Solved some problems with the excel of master statistical
This commit is contained in:
@@ -1,18 +1,8 @@
|
|||||||
/* eslint-disable @next/next/no-img-element */
|
/* eslint-disable @next/next/no-img-element */
|
||||||
import Modal from "@/components/Modal";
|
import Modal from "@/components/Modal";
|
||||||
import useFilterRecordsByUser from "@/hooks/useFilterRecordsByUser";
|
import useFilterRecordsByUser from "@/hooks/useFilterRecordsByUser";
|
||||||
import useUsers, {
|
import useUsers, {userHashStudent, userHashTeacher, userHashCorporate} from "@/hooks/useUsers";
|
||||||
userHashStudent,
|
import {CorporateUser, Group, MasterCorporateUser, Stat, User} from "@/interfaces/user";
|
||||||
userHashTeacher,
|
|
||||||
userHashCorporate,
|
|
||||||
} from "@/hooks/useUsers";
|
|
||||||
import {
|
|
||||||
CorporateUser,
|
|
||||||
Group,
|
|
||||||
MasterCorporateUser,
|
|
||||||
Stat,
|
|
||||||
User,
|
|
||||||
} from "@/interfaces/user";
|
|
||||||
import UserList from "@/pages/(admin)/Lists/UserList";
|
import UserList from "@/pages/(admin)/Lists/UserList";
|
||||||
import {dateSorter} from "@/utils";
|
import {dateSorter} from "@/utils";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
@@ -40,11 +30,7 @@ import {
|
|||||||
} from "react-icons/bs";
|
} from "react-icons/bs";
|
||||||
import UserCard from "@/components/UserCard";
|
import UserCard from "@/components/UserCard";
|
||||||
import useGroups from "@/hooks/useGroups";
|
import useGroups from "@/hooks/useGroups";
|
||||||
import {
|
import {averageLevelCalculator, calculateAverageLevel, calculateBandScore} from "@/utils/score";
|
||||||
averageLevelCalculator,
|
|
||||||
calculateAverageLevel,
|
|
||||||
calculateBandScore,
|
|
||||||
} from "@/utils/score";
|
|
||||||
import {MODULE_ARRAY} from "@/utils/moduleUtils";
|
import {MODULE_ARRAY} from "@/utils/moduleUtils";
|
||||||
import {Module} from "@/interfaces";
|
import {Module} from "@/interfaces";
|
||||||
import {groupByExam} from "@/utils/stats";
|
import {groupByExam} from "@/utils/stats";
|
||||||
@@ -64,12 +50,7 @@ import { createColumnHelper } from "@tanstack/react-table";
|
|||||||
import Checkbox from "@/components/Low/Checkbox";
|
import Checkbox from "@/components/Low/Checkbox";
|
||||||
import List from "@/components/List";
|
import List from "@/components/List";
|
||||||
import {getUserCompanyName} from "@/resources/user";
|
import {getUserCompanyName} from "@/resources/user";
|
||||||
import {
|
import {futureAssignmentFilter, pastAssignmentFilter, archivedAssignmentFilter, activeAssignmentFilter} from "@/utils/assignments";
|
||||||
futureAssignmentFilter,
|
|
||||||
pastAssignmentFilter,
|
|
||||||
archivedAssignmentFilter,
|
|
||||||
activeAssignmentFilter,
|
|
||||||
} from "@/utils/assignments";
|
|
||||||
import useUserBalance from "@/hooks/useUserBalance";
|
import useUserBalance from "@/hooks/useUserBalance";
|
||||||
import AssignmentsPage from "../views/AssignmentsPage";
|
import AssignmentsPage from "../views/AssignmentsPage";
|
||||||
import StudentPerformancePage from "./StudentPerformancePage";
|
import StudentPerformancePage from "./StudentPerformancePage";
|
||||||
@@ -98,36 +79,18 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
|
|
||||||
const {data: stats} = useFilterRecordsByUser<Stat[]>();
|
const {data: stats} = useFilterRecordsByUser<Stat[]>();
|
||||||
const {groups} = useGroups({admin: user.id});
|
const {groups} = useGroups({admin: user.id});
|
||||||
const {
|
const {assignments, isLoading: isAssignmentsLoading, reload: reloadAssignments} = useAssignments({corporate: user.id});
|
||||||
assignments,
|
|
||||||
isLoading: isAssignmentsLoading,
|
|
||||||
reload: reloadAssignments,
|
|
||||||
} = useAssignments({ corporate: user.id });
|
|
||||||
const {balance} = useUserBalance();
|
const {balance} = useUserBalance();
|
||||||
|
|
||||||
const {
|
useEffect(() => console.log(assignments), [assignments]);
|
||||||
users: students,
|
|
||||||
total: totalStudents,
|
const {users: students, total: totalStudents, reload: reloadStudents, isLoading: isStudentsLoading} = useUsers(studentHash);
|
||||||
reload: reloadStudents,
|
const {users: teachers, total: totalTeachers, reload: reloadTeachers, isLoading: isTeachersLoading} = useUsers(teacherHash);
|
||||||
isLoading: isStudentsLoading,
|
|
||||||
} = useUsers(studentHash);
|
|
||||||
const {
|
|
||||||
users: teachers,
|
|
||||||
total: totalTeachers,
|
|
||||||
reload: reloadTeachers,
|
|
||||||
isLoading: isTeachersLoading,
|
|
||||||
} = useUsers(teacherHash);
|
|
||||||
|
|
||||||
const appendUserFilters = useFilterStore((state) => state.appendUserFilter);
|
const appendUserFilters = useFilterStore((state) => state.appendUserFilter);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const assignmentsGroups = useMemo(
|
const assignmentsGroups = useMemo(() => groups.filter((x) => x.admin === user.id || x.participants.includes(user.id)), [groups, user.id]);
|
||||||
() =>
|
|
||||||
groups.filter(
|
|
||||||
(x) => x.admin === user.id || x.participants.includes(user.id)
|
|
||||||
),
|
|
||||||
[groups, user.id]
|
|
||||||
);
|
|
||||||
|
|
||||||
const assignmentsUsers = useMemo(
|
const assignmentsUsers = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -137,28 +100,22 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
.filter((g) => g.admin === selectedUser.id)
|
.filter((g) => g.admin === selectedUser.id)
|
||||||
.flatMap((g) => g.participants)
|
.flatMap((g) => g.participants)
|
||||||
.includes(x.id) || false
|
.includes(x.id) || false
|
||||||
: groups.flatMap((g) => g.participants).includes(x.id)
|
: groups.flatMap((g) => g.participants).includes(x.id),
|
||||||
),
|
),
|
||||||
[groups, teachers, students, selectedUser]
|
[groups, teachers, students, selectedUser],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setShowModal(!!selectedUser && router.asPath === "/#");
|
setShowModal(!!selectedUser && router.asPath === "/#");
|
||||||
}, [selectedUser, router.asPath]);
|
}, [selectedUser, router.asPath]);
|
||||||
|
|
||||||
const getStatsByStudent = (user: User) =>
|
const getStatsByStudent = (user: User) => stats.filter((s) => s.user === user.id);
|
||||||
stats.filter((s) => s.user === user.id);
|
|
||||||
|
|
||||||
const UserDisplay = (displayUser: User) => (
|
const UserDisplay = (displayUser: User) => (
|
||||||
<div
|
<div
|
||||||
onClick={() => setSelectedUser(displayUser)}
|
onClick={() => setSelectedUser(displayUser)}
|
||||||
className="flex w-full p-4 gap-4 items-center hover:bg-mti-purple-ultralight cursor-pointer transition ease-in-out duration-300"
|
className="flex w-full p-4 gap-4 items-center hover:bg-mti-purple-ultralight cursor-pointer transition ease-in-out duration-300">
|
||||||
>
|
<img src={displayUser.profilePicture} alt={displayUser.name} className="rounded-full w-10 h-10" />
|
||||||
<img
|
|
||||||
src={displayUser.profilePicture}
|
|
||||||
alt={displayUser.name}
|
|
||||||
className="rounded-full w-10 h-10"
|
|
||||||
/>
|
|
||||||
<div className="flex flex-col gap-1 items-start">
|
<div className="flex flex-col gap-1 items-start">
|
||||||
<span>{displayUser.name}</span>
|
<span>{displayUser.name}</span>
|
||||||
<span className="text-sm opacity-75">{displayUser.email}</span>
|
<span className="text-sm opacity-75">{displayUser.email}</span>
|
||||||
@@ -170,55 +127,41 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
// while still being able to use the corporate user
|
// while still being able to use the corporate user
|
||||||
const groupedByNameCorporateIds = useMemo(
|
const groupedByNameCorporateIds = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
[user.corporateInformation?.companyInformation?.name || user.name]: [
|
[user.corporateInformation?.companyInformation?.name || user.name]: [user.id],
|
||||||
user.id,
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
[user]
|
[user],
|
||||||
);
|
|
||||||
const teachersAndStudents = useMemo(
|
|
||||||
() => [...students, ...teachers],
|
|
||||||
[students, teachers]
|
|
||||||
);
|
);
|
||||||
|
const teachersAndStudents = useMemo(() => [...students, ...teachers], [students, teachers]);
|
||||||
const MasterStatisticalPage = () => {
|
const MasterStatisticalPage = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<div
|
<div
|
||||||
onClick={() => router.push("/")}
|
onClick={() => router.push("/")}
|
||||||
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300"
|
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300">
|
||||||
>
|
|
||||||
<BsArrowLeft className="text-xl" />
|
<BsArrowLeft className="text-xl" />
|
||||||
<span>Back</span>
|
<span>Back</span>
|
||||||
</div>
|
</div>
|
||||||
<h2 className="text-2xl font-semibold">Master Statistical</h2>
|
<h2 className="text-2xl font-semibold">Master Statistical</h2>
|
||||||
</div>
|
</div>
|
||||||
<MasterStatistical
|
<MasterStatistical users={teachersAndStudents} corporateUsers={groupedByNameCorporateIds} displaySelection={false} />
|
||||||
users={teachersAndStudents}
|
|
||||||
corporateUsers={groupedByNameCorporateIds}
|
|
||||||
displaySelection={false}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const GroupsList = () => {
|
const GroupsList = () => {
|
||||||
const filter = (x: Group) =>
|
const filter = (x: Group) => x.admin === user.id || x.participants.includes(user.id);
|
||||||
x.admin === user.id || x.participants.includes(user.id);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<div
|
<div
|
||||||
onClick={() => router.push("/")}
|
onClick={() => router.push("/")}
|
||||||
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300"
|
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300">
|
||||||
>
|
|
||||||
<BsArrowLeft className="text-xl" />
|
<BsArrowLeft className="text-xl" />
|
||||||
<span>Back</span>
|
<span>Back</span>
|
||||||
</div>
|
</div>
|
||||||
<h2 className="text-2xl font-semibold">
|
<h2 className="text-2xl font-semibold">Groups ({groups.filter(filter).length})</h2>
|
||||||
Groups ({groups.filter(filter).length})
|
|
||||||
</h2>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<GroupList user={user} />
|
<GroupList user={user} />
|
||||||
@@ -236,12 +179,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
.filter((f) => !!f.focus);
|
.filter((f) => !!f.focus);
|
||||||
const bandScores = formattedStats.map((s) => ({
|
const bandScores = formattedStats.map((s) => ({
|
||||||
module: s.module,
|
module: s.module,
|
||||||
level: calculateBandScore(
|
level: calculateBandScore(s.score.correct, s.score.total, s.module, s.focus!),
|
||||||
s.score.correct,
|
|
||||||
s.score.total,
|
|
||||||
s.module,
|
|
||||||
s.focus!
|
|
||||||
),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const levels: {[key in Module]: number} = {
|
const levels: {[key in Module]: number} = {
|
||||||
@@ -265,8 +203,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<div
|
<div
|
||||||
onClick={() => router.push("/")}
|
onClick={() => router.push("/")}
|
||||||
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300"
|
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300">
|
||||||
>
|
|
||||||
<BsArrowLeft className="text-xl" />
|
<BsArrowLeft className="text-xl" />
|
||||||
<span>Back</span>
|
<span>Back</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -285,8 +222,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<div
|
<div
|
||||||
onClick={() => router.push("/")}
|
onClick={() => router.push("/")}
|
||||||
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300"
|
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300">
|
||||||
>
|
|
||||||
<BsArrowLeft className="text-xl" />
|
<BsArrowLeft className="text-xl" />
|
||||||
<span>Back</span>
|
<span>Back</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -297,8 +233,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (router.asPath === "/#groups") return <GroupsList />;
|
if (router.asPath === "/#groups") return <GroupsList />;
|
||||||
if (router.asPath === "/#studentsPerformance")
|
if (router.asPath === "/#studentsPerformance") return <StudentPerformancePage user={user} />;
|
||||||
return <StudentPerformancePage user={user} />;
|
|
||||||
|
|
||||||
if (router.asPath === "/#assignments")
|
if (router.asPath === "/#assignments")
|
||||||
return (
|
return (
|
||||||
@@ -324,14 +259,11 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
loggedInUser={user}
|
loggedInUser={user}
|
||||||
onClose={(shouldReload) => {
|
onClose={(shouldReload) => {
|
||||||
setSelectedUser(undefined);
|
setSelectedUser(undefined);
|
||||||
if (shouldReload && selectedUser!.type === "student")
|
if (shouldReload && selectedUser!.type === "student") reloadStudents();
|
||||||
reloadStudents();
|
if (shouldReload && selectedUser!.type === "teacher") reloadTeachers();
|
||||||
if (shouldReload && selectedUser!.type === "teacher")
|
|
||||||
reloadTeachers();
|
|
||||||
}}
|
}}
|
||||||
onViewStudents={
|
onViewStudents={
|
||||||
selectedUser.type === "corporate" ||
|
selectedUser.type === "corporate" || selectedUser.type === "teacher"
|
||||||
selectedUser.type === "teacher"
|
|
||||||
? () => {
|
? () => {
|
||||||
appendUserFilters({
|
appendUserFilters({
|
||||||
id: "view-students",
|
id: "view-students",
|
||||||
@@ -341,11 +273,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
id: "belongs-to-admin",
|
id: "belongs-to-admin",
|
||||||
filter: (x: User) =>
|
filter: (x: User) =>
|
||||||
groups
|
groups
|
||||||
.filter(
|
.filter((g) => g.admin === selectedUser.id || g.participants.includes(selectedUser.id))
|
||||||
(g) =>
|
|
||||||
g.admin === selectedUser.id ||
|
|
||||||
g.participants.includes(selectedUser.id)
|
|
||||||
)
|
|
||||||
.flatMap((g) => g.participants)
|
.flatMap((g) => g.participants)
|
||||||
.includes(x.id),
|
.includes(x.id),
|
||||||
});
|
});
|
||||||
@@ -355,8 +283,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
onViewTeachers={
|
onViewTeachers={
|
||||||
selectedUser.type === "corporate" ||
|
selectedUser.type === "corporate" || selectedUser.type === "student"
|
||||||
selectedUser.type === "student"
|
|
||||||
? () => {
|
? () => {
|
||||||
appendUserFilters({
|
appendUserFilters({
|
||||||
id: "view-teachers",
|
id: "view-teachers",
|
||||||
@@ -366,11 +293,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
id: "belongs-to-admin",
|
id: "belongs-to-admin",
|
||||||
filter: (x: User) =>
|
filter: (x: User) =>
|
||||||
groups
|
groups
|
||||||
.filter(
|
.filter((g) => g.admin === selectedUser.id || g.participants.includes(selectedUser.id))
|
||||||
(g) =>
|
|
||||||
g.admin === selectedUser.id ||
|
|
||||||
g.participants.includes(selectedUser.id)
|
|
||||||
)
|
|
||||||
.flatMap((g) => g.participants)
|
.flatMap((g) => g.participants)
|
||||||
.includes(x.id),
|
.includes(x.id),
|
||||||
});
|
});
|
||||||
@@ -389,11 +312,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
<>
|
<>
|
||||||
{!!linkedCorporate && (
|
{!!linkedCorporate && (
|
||||||
<div className="absolute top-4 right-4 bg-neutral-200 px-2 rounded-lg py-1">
|
<div className="absolute top-4 right-4 bg-neutral-200 px-2 rounded-lg py-1">
|
||||||
Linked to:{" "}
|
Linked to: <b>{linkedCorporate?.corporateInformation?.companyInformation.name || linkedCorporate.name}</b>
|
||||||
<b>
|
|
||||||
{linkedCorporate?.corporateInformation?.companyInformation.name ||
|
|
||||||
linkedCorporate.name}
|
|
||||||
</b>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<section className="grid grid-cols-5 -md:grid-cols-2 gap-4 text-center">
|
<section className="grid grid-cols-5 -md:grid-cols-2 gap-4 text-center">
|
||||||
@@ -416,47 +335,27 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
<IconCard
|
<IconCard
|
||||||
Icon={BsClipboard2Data}
|
Icon={BsClipboard2Data}
|
||||||
label="Exams Performed"
|
label="Exams Performed"
|
||||||
value={
|
value={stats.filter((s) => groups.flatMap((g) => g.participants).includes(s.user)).length}
|
||||||
stats.filter((s) =>
|
|
||||||
groups.flatMap((g) => g.participants).includes(s.user)
|
|
||||||
).length
|
|
||||||
}
|
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
<IconCard
|
<IconCard
|
||||||
Icon={BsPaperclip}
|
Icon={BsPaperclip}
|
||||||
isLoading={isStudentsLoading}
|
isLoading={isStudentsLoading}
|
||||||
label="Average Level"
|
label="Average Level"
|
||||||
value={averageLevelCalculator(
|
value={averageLevelCalculator(stats.filter((s) => groups.flatMap((g) => g.participants).includes(s.user))).toFixed(1)}
|
||||||
stats.filter((s) =>
|
|
||||||
groups.flatMap((g) => g.participants).includes(s.user)
|
|
||||||
)
|
|
||||||
).toFixed(1)}
|
|
||||||
color="purple"
|
|
||||||
/>
|
|
||||||
<IconCard
|
|
||||||
onClick={() => router.push("/#groups")}
|
|
||||||
Icon={BsPeople}
|
|
||||||
label="Groups"
|
|
||||||
value={groups.length}
|
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
|
<IconCard onClick={() => router.push("/#groups")} Icon={BsPeople} label="Groups" value={groups.length} color="purple" />
|
||||||
<IconCard
|
<IconCard
|
||||||
Icon={BsPersonCheck}
|
Icon={BsPersonCheck}
|
||||||
label="User Balance"
|
label="User Balance"
|
||||||
value={`${balance}/${
|
value={`${balance}/${user.corporateInformation?.companyInformation?.userAmount || 0}`}
|
||||||
user.corporateInformation?.companyInformation?.userAmount || 0
|
|
||||||
}`}
|
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
<IconCard
|
<IconCard
|
||||||
Icon={BsClock}
|
Icon={BsClock}
|
||||||
label="Expiration Date"
|
label="Expiration Date"
|
||||||
value={
|
value={user.subscriptionExpirationDate ? moment(user.subscriptionExpirationDate).format("DD/MM/yyyy") : "Unlimited"}
|
||||||
user.subscriptionExpirationDate
|
|
||||||
? moment(user.subscriptionExpirationDate).format("DD/MM/yyyy")
|
|
||||||
: "Unlimited"
|
|
||||||
}
|
|
||||||
color="rose"
|
color="rose"
|
||||||
/>
|
/>
|
||||||
<IconCard
|
<IconCard
|
||||||
@@ -467,24 +366,16 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
color="purple"
|
color="purple"
|
||||||
onClick={() => router.push("/#studentsPerformance")}
|
onClick={() => router.push("/#studentsPerformance")}
|
||||||
/>
|
/>
|
||||||
<IconCard
|
<IconCard Icon={BsDatabase} label="Master Statistical" color="purple" onClick={() => router.push("/#statistical")} />
|
||||||
Icon={BsDatabase}
|
|
||||||
label="Master Statistical"
|
|
||||||
color="purple"
|
|
||||||
onClick={() => router.push("/#statistical")}
|
|
||||||
/>
|
|
||||||
<button
|
<button
|
||||||
disabled={isAssignmentsLoading}
|
disabled={isAssignmentsLoading}
|
||||||
onClick={() => router.push("/#assignments")}
|
onClick={() => router.push("/#assignments")}
|
||||||
className="bg-white col-span-2 rounded-xl shadow p-4 flex flex-col gap-4 items-center w-96 h-52 justify-center cursor-pointer hover:shadow-xl transition ease-in-out duration-300"
|
className="bg-white col-span-2 rounded-xl shadow p-4 flex flex-col gap-4 items-center w-96 h-52 justify-center cursor-pointer hover:shadow-xl transition ease-in-out duration-300">
|
||||||
>
|
|
||||||
<BsEnvelopePaper className="text-6xl text-mti-purple-light" />
|
<BsEnvelopePaper className="text-6xl text-mti-purple-light" />
|
||||||
<span className="flex flex-col gap-1 items-center text-xl">
|
<span className="flex flex-col gap-1 items-center text-xl">
|
||||||
<span className="text-lg">Assignments</span>
|
<span className="text-lg">Assignments</span>
|
||||||
<span className="font-semibold text-mti-purple-light">
|
<span className="font-semibold text-mti-purple-light">
|
||||||
{isAssignmentsLoading
|
{isAssignmentsLoading ? "Loading..." : assignments.filter((a) => !a.archived).length}
|
||||||
? "Loading..."
|
|
||||||
: assignments.filter((a) => !a.archived).length}
|
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -515,11 +406,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
<span className="p-4">Highest level students</span>
|
<span className="p-4">Highest level students</span>
|
||||||
<div className="flex flex-col items-start h-96 overflow-scroll scrollbar-hide">
|
<div className="flex flex-col items-start h-96 overflow-scroll scrollbar-hide">
|
||||||
{students
|
{students
|
||||||
.sort(
|
.sort((a, b) => calculateAverageLevel(b.levels) - calculateAverageLevel(a.levels))
|
||||||
(a, b) =>
|
|
||||||
calculateAverageLevel(b.levels) -
|
|
||||||
calculateAverageLevel(a.levels)
|
|
||||||
)
|
|
||||||
.map((x) => (
|
.map((x) => (
|
||||||
<UserDisplay key={x.id} {...x} />
|
<UserDisplay key={x.id} {...x} />
|
||||||
))}
|
))}
|
||||||
@@ -531,8 +418,7 @@ export default function CorporateDashboard({ user, linkedCorporate }: Props) {
|
|||||||
{students
|
{students
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
Object.keys(groupByExam(getStatsByStudent(b))).length -
|
Object.keys(groupByExam(getStatsByStudent(b))).length - Object.keys(groupByExam(getStatsByStudent(a))).length,
|
||||||
Object.keys(groupByExam(getStatsByStudent(a))).length
|
|
||||||
)
|
)
|
||||||
.map((x) => (
|
.map((x) => (
|
||||||
<UserDisplay key={x.id} {...x} />
|
<UserDisplay key={x.id} {...x} />
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ const MasterStatistical = (props: Props) => {
|
|||||||
assignments.reduce((accmA: TableData[], a: AssignmentWithCorporateId) => {
|
assignments.reduce((accmA: TableData[], a: AssignmentWithCorporateId) => {
|
||||||
const userResults = a.assignees.map((assignee) => {
|
const userResults = a.assignees.map((assignee) => {
|
||||||
const userData = users.find((u) => u.id === assignee);
|
const userData = users.find((u) => u.id === assignee);
|
||||||
const userStats = !!userData ? a.results.find((r) => r.user === assignee)?.stats || [] : [];
|
const userStats = a.results.find((r) => r.user === assignee)?.stats || [];
|
||||||
const corporate = getUserName(users.find((u) => u.id === a.assigner));
|
const corporate = getUserName(users.find((u) => u.id === a.assigner));
|
||||||
const commonData = {
|
const commonData = {
|
||||||
user: userData,
|
user: userData,
|
||||||
@@ -109,8 +109,6 @@ const MasterStatistical = (props: Props) => {
|
|||||||
[assignments, users],
|
[assignments, users],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => console.log(assignments), [assignments]);
|
|
||||||
|
|
||||||
const getCorporateScores = (corporateId: string): UserCount => {
|
const getCorporateScores = (corporateId: string): UserCount => {
|
||||||
const corporateAssignmentsUsers = assignments.filter((a) => a.corporateId === corporateId).reduce((acc, a) => acc + a.assignees.length, 0);
|
const corporateAssignmentsUsers = assignments.filter((a) => a.corporateId === corporateId).reduce((acc, a) => acc + a.assignees.length, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export default function AssignmentsPage({assignments, corporateAssignments, user
|
|||||||
<AssignmentCreator
|
<AssignmentCreator
|
||||||
assignment={selectedAssignment}
|
assignment={selectedAssignment}
|
||||||
groups={groups}
|
groups={groups}
|
||||||
users={users}
|
users={[...users, user]}
|
||||||
user={user}
|
user={user}
|
||||||
isCreating={isCreatingAssignment}
|
isCreating={isCreatingAssignment}
|
||||||
cancelCreation={() => {
|
cancelCreation={() => {
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ export default function useUsers(props?: {type?: string; page?: number; size?: n
|
|||||||
if (props[key as keyof typeof props] !== undefined) params.append(key, props[key as keyof typeof props]!.toString());
|
if (props[key as keyof typeof props] !== undefined) params.append(key, props[key as keyof typeof props]!.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(params.toString());
|
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
axios
|
axios
|
||||||
.get<{users: User[]; total: number}>(`/api/users/list?${params.toString()}`, {headers: {page: "register"}})
|
.get<{users: User[]; total: number}>(`/api/users/list?${params.toString()}`, {headers: {page: "register"}})
|
||||||
|
|||||||
@@ -14,12 +14,18 @@ import {getGradingSystem} from "@/utils/grading.be";
|
|||||||
import {StudentUser, User} from "@/interfaces/user";
|
import {StudentUser, User} from "@/interfaces/user";
|
||||||
import {calculateBandScore, getGradingLabel} from "@/utils/score";
|
import {calculateBandScore, getGradingLabel} from "@/utils/score";
|
||||||
import {Module} from "@/interfaces";
|
import {Module} from "@/interfaces";
|
||||||
|
import {uniq} from "lodash";
|
||||||
|
import {getUserName} from "@/utils/users";
|
||||||
|
import {LevelExam} from "@/interfaces/exam";
|
||||||
|
import {getSpecificExams} from "@/utils/exams.be";
|
||||||
|
|
||||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||||
|
|
||||||
interface TableData {
|
interface TableData {
|
||||||
user: string;
|
user: string;
|
||||||
studentID: string;
|
studentID: string;
|
||||||
|
passportID: string;
|
||||||
|
exams: string;
|
||||||
email: string;
|
email: string;
|
||||||
correct: number;
|
correct: number;
|
||||||
corporate: string;
|
corporate: string;
|
||||||
@@ -41,7 +47,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
if (req.method === "POST") return await post(req, res);
|
if (req.method === "POST") return await post(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchFilters = [["email"], ["user"], ["userId"]];
|
const searchFilters = [["email"], ["user"], ["userId"], ["assignment"], ["exams"]];
|
||||||
|
|
||||||
async function post(req: NextApiRequest, res: NextApiResponse) {
|
async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||||
// verify if it's a logged user that is trying to export
|
// verify if it's a logged user that is trying to export
|
||||||
@@ -66,10 +72,11 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const endDateParsed = endDate ? new Date(endDate) : undefined;
|
const endDateParsed = endDate ? new Date(endDate) : undefined;
|
||||||
const assignments = await getAssignmentsForCorporates(req.session.user.type, ids, startDateParsed, endDateParsed);
|
const assignments = await getAssignmentsForCorporates(req.session.user.type, ids, startDateParsed, endDateParsed);
|
||||||
|
|
||||||
const assignmentUsers = [...new Set(assignments.flatMap((a) => a.assignees))];
|
const assignmentUsers = uniq([...assignments.flatMap((x) => x.assignees), ...assignments.flatMap((x) => x.assigner)]);
|
||||||
const assigners = [...new Set(assignments.map((a) => a.assigner))];
|
const assigners = [...new Set(assignments.map((a) => a.assigner))];
|
||||||
const users = await getSpecificUsers(assignmentUsers);
|
const users = await getSpecificUsers(assignmentUsers);
|
||||||
const assignerUsers = await getSpecificUsers(assigners);
|
const assignerUsers = await getSpecificUsers(assigners);
|
||||||
|
const exams = await getSpecificExams(uniq(assignments.flatMap((x) => x.exams.map((x) => x.id))));
|
||||||
|
|
||||||
const assignerUsersGradingSystems = await Promise.all(
|
const assignerUsersGradingSystems = await Promise.all(
|
||||||
assignerUsers.map(async (user: User) => {
|
assignerUsers.map(async (user: User) => {
|
||||||
@@ -91,7 +98,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
if (gradingSystem) {
|
if (gradingSystem) {
|
||||||
const bandScore = calculateBandScore(correct, total, "level", user?.focus || "academic");
|
const bandScore = calculateBandScore(correct, total, "level", user?.focus || "academic");
|
||||||
return {
|
return {
|
||||||
label: getGradingLabel(bandScore, gradingSystem?.steps || []),
|
label: getGradingLabel(bandScore, gradingSystem.steps || []),
|
||||||
score: bandScore,
|
score: bandScore,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -113,10 +120,12 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const commonData = {
|
const commonData = {
|
||||||
user: userData?.name || "",
|
user: userData?.name || "",
|
||||||
email: userData?.email || "",
|
email: userData?.email || "",
|
||||||
studentID: (userData as StudentUser).studentID || "",
|
studentID: (userData as StudentUser)?.studentID || "",
|
||||||
|
passportID: (userData as StudentUser)?.demographicInformation?.passport_id || "",
|
||||||
userId: assignee,
|
userId: assignee,
|
||||||
|
exams: a.exams.map((x) => x.id).join(", "),
|
||||||
corporateId: a.corporateId,
|
corporateId: a.corporateId,
|
||||||
corporate: corporateUser?.name || "",
|
corporate: !corporateUser ? "" : getUserName(corporateUser),
|
||||||
assignment: a.name,
|
assignment: a.name,
|
||||||
level,
|
level,
|
||||||
score,
|
score,
|
||||||
@@ -130,14 +139,22 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const partsData = userStats.every((e) => e.module === "level")
|
let data: {total: number; correct: number}[] = [];
|
||||||
? userStats.reduce((acc, e, index) => {
|
if (a.exams.every((x) => x.module === "level")) {
|
||||||
return {
|
const exam = exams.find((x) => x.id === a.exams.find((x) => x.assignee === assignee)?.id) as LevelExam;
|
||||||
...acc,
|
data = exam.parts.map((x) => {
|
||||||
[`part${index}`]: `${e.score.correct}/${e.score.total}`,
|
const exerciseIDs = x.exercises.map((x) => x.id);
|
||||||
};
|
const stats = userStats.filter((x) => exerciseIDs.includes(x.exercise));
|
||||||
}, {})
|
|
||||||
: {};
|
const total = stats.reduce((acc, curr) => acc + curr.score.total, 0);
|
||||||
|
const correct = stats.reduce((acc, curr) => acc + curr.score.correct, 0);
|
||||||
|
|
||||||
|
return {total, correct};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const partsData =
|
||||||
|
data.length > 0 ? data.reduce((acc, e, index) => ({...acc, [`part${index}`]: `${e.correct}/${e.total}`}), {}) : {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...commonData,
|
...commonData,
|
||||||
@@ -169,6 +186,10 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
label: "Student ID",
|
label: "Student ID",
|
||||||
value: (entry: TableData) => entry.studentID,
|
value: (entry: TableData) => entry.studentID,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Passport ID",
|
||||||
|
value: (entry: TableData) => entry.passportID,
|
||||||
|
},
|
||||||
...(displaySelection
|
...(displaySelection
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
@@ -186,7 +207,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
value: (entry: TableData) => (entry.submitted ? "Yes" : "No"),
|
value: (entry: TableData) => (entry.submitted ? "Yes" : "No"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Correct",
|
label: "Score",
|
||||||
value: (entry: TableData) => entry.correct,
|
value: (entry: TableData) => entry.correct,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -206,7 +227,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
})),
|
})),
|
||||||
];
|
];
|
||||||
|
|
||||||
const filteredSearch = searchText ? search(searchText, searchFilters, tableResults) : tableResults;
|
const filteredSearch = !!searchText ? search(searchText, searchFilters, tableResults) : tableResults;
|
||||||
|
|
||||||
worksheet.addRow(headers.map((h) => h.label));
|
worksheet.addRow(headers.map((h) => h.label));
|
||||||
(filteredSearch as TableData[]).forEach((entry) => {
|
(filteredSearch as TableData[]).forEach((entry) => {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {withIronSessionApiRoute} from "iron-session/next";
|
|||||||
import {sessionOptions} from "@/lib/session";
|
import {sessionOptions} from "@/lib/session";
|
||||||
import {getLinkedUsers} from "@/utils/users.be";
|
import {getLinkedUsers} from "@/utils/users.be";
|
||||||
import {Type} from "@/interfaces/user";
|
import {Type} from "@/interfaces/user";
|
||||||
|
import {uniqBy} from "lodash";
|
||||||
|
|
||||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||||
|
|
||||||
@@ -31,5 +32,5 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
direction,
|
direction,
|
||||||
);
|
);
|
||||||
|
|
||||||
res.status(200).json({users, total});
|
res.status(200).json({users: uniqBy([...users, req.session.user], "id"), total});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,28 @@ import {Module} from "@/interfaces";
|
|||||||
import {getCorporateUser} from "@/resources/user";
|
import {getCorporateUser} from "@/resources/user";
|
||||||
import {getUserCorporate} from "./groups.be";
|
import {getUserCorporate} from "./groups.be";
|
||||||
import {Db, ObjectId} from "mongodb";
|
import {Db, ObjectId} from "mongodb";
|
||||||
|
import client from "@/lib/mongodb";
|
||||||
|
import {MODULE_ARRAY} from "./moduleUtils";
|
||||||
|
|
||||||
|
const db = client.db(process.env.MONGODB_DB);
|
||||||
|
|
||||||
|
export async function getSpecificExams(ids: string[]) {
|
||||||
|
if (ids.length === 0) return [];
|
||||||
|
|
||||||
|
const exams: Exam[] = (
|
||||||
|
await Promise.all(
|
||||||
|
MODULE_ARRAY.flatMap(
|
||||||
|
async (module) =>
|
||||||
|
await db
|
||||||
|
.collection(module)
|
||||||
|
.find<Exam>({id: {$in: ids}})
|
||||||
|
.toArray(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
).flat();
|
||||||
|
|
||||||
|
return exams;
|
||||||
|
}
|
||||||
|
|
||||||
export const getExams = async (
|
export const getExams = async (
|
||||||
db: Db,
|
db: Db,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*fields example = [
|
/*fields example = [
|
||||||
['id'],
|
['id'],
|
||||||
['companyInformation', 'companyInformation', 'name']
|
['companyInformation', 'companyInformation', 'name']
|
||||||
@@ -18,6 +17,7 @@ export const search = (text: string, fields: string[][], rows: any[]) => {
|
|||||||
return fields.some((fieldsKeys) => {
|
return fields.some((fieldsKeys) => {
|
||||||
const value = getFieldValue(fieldsKeys, row);
|
const value = getFieldValue(fieldsKeys, row);
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
|
console.log(value, searchText, value.toLowerCase().includes(searchText));
|
||||||
return value.toLowerCase().includes(searchText);
|
return value.toLowerCase().includes(searchText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,4 +26,4 @@ export const search = (text: string, fields: string[][], rows: any[]) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user