Added more control over the stats appearing in the stats page
This commit is contained in:
@@ -6,15 +6,15 @@ import {withIronSessionSsr} from "iron-session/next";
|
|||||||
import {sessionOptions} from "@/lib/session";
|
import {sessionOptions} from "@/lib/session";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import useStats from "@/hooks/useStats";
|
import useStats from "@/hooks/useStats";
|
||||||
import {averageScore, totalExamsByModule, groupBySession, groupByModule} from "@/utils/stats";
|
import {averageScore, totalExamsByModule, groupBySession, groupByModule, timestampToMoment, groupByDate} from "@/utils/stats";
|
||||||
import useUser from "@/hooks/useUser";
|
import useUser from "@/hooks/useUser";
|
||||||
import {ToastContainer} from "react-toastify";
|
import {ToastContainer} from "react-toastify";
|
||||||
import {capitalize} from "lodash";
|
import {capitalize, Dictionary} from "lodash";
|
||||||
import {Module} from "@/interfaces";
|
import {Module} from "@/interfaces";
|
||||||
import ProgressBar from "@/components/Low/ProgressBar";
|
import ProgressBar from "@/components/Low/ProgressBar";
|
||||||
import Layout from "@/components/High/Layout";
|
import Layout from "@/components/High/Layout";
|
||||||
import {calculateAverageLevel, calculateBandScore} from "@/utils/score";
|
import {calculateAverageLevel, calculateBandScore} from "@/utils/score";
|
||||||
import {MODULE_ARRAY} from "@/utils/moduleUtils";
|
import {MODULE_ARRAY, sortByModule} from "@/utils/moduleUtils";
|
||||||
import {Chart} from "react-chartjs-2";
|
import {Chart} from "react-chartjs-2";
|
||||||
import useUsers from "@/hooks/useUsers";
|
import useUsers from "@/hooks/useUsers";
|
||||||
import Select from "react-select";
|
import Select from "react-select";
|
||||||
@@ -24,6 +24,7 @@ import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
|||||||
import ProfileSummary from "@/components/ProfileSummary";
|
import ProfileSummary from "@/components/ProfileSummary";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import {Stat} from "@/interfaces/user";
|
import {Stat} from "@/interfaces/user";
|
||||||
|
import {Divider} from "primereact/divider";
|
||||||
|
|
||||||
ChartJS.register(LinearScale, CategoryScale, PointElement, LineElement, LineController, Legend, Tooltip);
|
ChartJS.register(LinearScale, CategoryScale, PointElement, LineElement, LineController, Legend, Tooltip);
|
||||||
|
|
||||||
@@ -64,6 +65,11 @@ export default function Stats() {
|
|||||||
const [startDate, setStartDate] = useState<Date | null>(moment("01/01/2023").toDate());
|
const [startDate, setStartDate] = useState<Date | null>(moment("01/01/2023").toDate());
|
||||||
const [endDate, setEndDate] = useState<Date | null>(new Date());
|
const [endDate, setEndDate] = useState<Date | null>(new Date());
|
||||||
const [displayStats, setDisplayStats] = useState<Stat[]>([]);
|
const [displayStats, setDisplayStats] = useState<Stat[]>([]);
|
||||||
|
const [initialStatDate, setInitialStatDate] = useState<Date>();
|
||||||
|
|
||||||
|
const [monthlyOverallScoreDate, setMonthlyOverallScoreDate] = useState<Date | null>(new Date());
|
||||||
|
const [monthlyModuleScoreDate, setMonthlyModuleScoreDate] = useState<Date | null>(new Date());
|
||||||
|
const [monthlyOverallGraphScoreDate, setMonthlyOverallGraphScoreDate] = useState<Date | null>(new Date());
|
||||||
|
|
||||||
const {user} = useUser({redirectTo: "/login"});
|
const {user} = useUser({redirectTo: "/login"});
|
||||||
const {users} = useUsers();
|
const {users} = useUsers();
|
||||||
@@ -76,11 +82,8 @@ export default function Stats() {
|
|||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const startDateFilter = (s: Stat) => moment.unix(s.date / 1000).isAfter(moment(startDate));
|
const startDateFilter = (s: Stat) => timestampToMoment(s).isAfter(moment(startDate));
|
||||||
const endDateFilter = (s: Stat) => {
|
const endDateFilter = (s: Stat) => moment(endDate).isAfter(timestampToMoment(s));
|
||||||
console.log(moment.unix(s.date / 1000), moment(endDate).isAfter(moment.unix(s.date)));
|
|
||||||
return moment(endDate).isAfter(moment.unix(s.date / 1000));
|
|
||||||
};
|
|
||||||
|
|
||||||
const filters = [];
|
const filters = [];
|
||||||
if (startDate) filters.push(startDateFilter);
|
if (startDate) filters.push(startDateFilter);
|
||||||
@@ -89,20 +92,39 @@ export default function Stats() {
|
|||||||
setDisplayStats(filters.reduce((d, f) => d.filter(f), stats));
|
setDisplayStats(filters.reduce((d, f) => d.filter(f), stats));
|
||||||
}, [endDate, startDate, stats]);
|
}, [endDate, startDate, stats]);
|
||||||
|
|
||||||
const calculateTotalScorePerSession = () => {
|
useEffect(() => {
|
||||||
const groupedBySession = groupBySession(stats);
|
setInitialStatDate(
|
||||||
|
stats
|
||||||
|
.filter((s) => s.date)
|
||||||
|
.sort((a, b) => timestampToMoment(a).diff(timestampToMoment(b)))
|
||||||
|
.map(timestampToMoment)
|
||||||
|
.shift()
|
||||||
|
?.toDate(),
|
||||||
|
);
|
||||||
|
}, [stats]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setStartDate(initialStatDate || moment("01/01/2023").toDate());
|
||||||
|
}, [initialStatDate]);
|
||||||
|
|
||||||
|
const calculateModuleScore = (stats: Stat[]) => {
|
||||||
|
const moduleStats = groupByModule(stats);
|
||||||
|
return Object.keys(moduleStats).map((y) => {
|
||||||
|
const correct = moduleStats[y].reduce((accumulator, current) => accumulator + current.score.correct, 0);
|
||||||
|
const total = moduleStats[y].reduce((accumulator, current) => accumulator + current.score.total, 0);
|
||||||
|
|
||||||
|
return {
|
||||||
|
module: y as Module,
|
||||||
|
score: calculateBandScore(correct, total, y as Module, user?.focus || "academic"),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const calculateTotalScorePerKey = (stats: Stat[], keyFunction: (stats: Stat[]) => Dictionary<Stat[]>) => {
|
||||||
|
const groupedBySession = keyFunction(stats);
|
||||||
const sessionAverage = Object.keys(groupedBySession).map((x: string) => {
|
const sessionAverage = Object.keys(groupedBySession).map((x: string) => {
|
||||||
const session = groupedBySession[x];
|
const session = groupedBySession[x];
|
||||||
const moduleStats = groupByModule(session);
|
const moduleScores = calculateModuleScore(session);
|
||||||
const moduleScores = Object.keys(moduleStats).map((y) => {
|
|
||||||
const correct = moduleStats[y].reduce((accumulator, current) => accumulator + current.score.correct, 0);
|
|
||||||
const total = moduleStats[y].reduce((accumulator, current) => accumulator + current.score.total, 0);
|
|
||||||
|
|
||||||
return {
|
|
||||||
module: y,
|
|
||||||
score: calculateBandScore(correct, total, y as Module, user?.focus || "academic"),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return moduleScores.reduce((acc, curr) => acc + curr.score, 0) / 4;
|
return moduleScores.reduce((acc, curr) => acc + curr.score, 0) / 4;
|
||||||
});
|
});
|
||||||
@@ -110,7 +132,12 @@ export default function Stats() {
|
|||||||
return sessionAverage;
|
return sessionAverage;
|
||||||
};
|
};
|
||||||
|
|
||||||
const calculateAverageTimePerModule = () => {
|
const calculateTotalScore = (stats: Stat[]) => {
|
||||||
|
const moduleScores = calculateModuleScore(stats);
|
||||||
|
return moduleScores.reduce((acc, curr) => acc + curr.score, 0) / 4;
|
||||||
|
};
|
||||||
|
|
||||||
|
const calculateAverageTimePerModule = (stats: Stat[]) => {
|
||||||
const groupedBySession = groupBySession(stats.filter((x) => !!x.timeSpent));
|
const groupedBySession = groupBySession(stats.filter((x) => !!x.timeSpent));
|
||||||
const sessionAverage = Object.keys(groupedBySession).map((x: string) => {
|
const sessionAverage = Object.keys(groupedBySession).map((x: string) => {
|
||||||
const session = groupedBySession[x];
|
const session = groupedBySession[x];
|
||||||
@@ -122,7 +149,7 @@ export default function Stats() {
|
|||||||
return sessionAverage;
|
return sessionAverage;
|
||||||
};
|
};
|
||||||
|
|
||||||
const calculateModularScorePerSession = (module: Module) => {
|
const calculateModularScorePerSession = (stats: Stat[], module: Module) => {
|
||||||
const groupedBySession = groupBySession(stats);
|
const groupedBySession = groupBySession(stats);
|
||||||
const sessionAverage = Object.keys(groupedBySession).map((x: string) => {
|
const sessionAverage = Object.keys(groupedBySession).map((x: string) => {
|
||||||
const session = groupedBySession[x];
|
const session = groupedBySession[x];
|
||||||
@@ -208,81 +235,78 @@ export default function Stats() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
<DatePicker
|
|
||||||
dateFormat="dd/MM/yyyy"
|
|
||||||
className="border border-mti-gray-dim/40 px-4 py-1.5 rounded-lg text-center w-[256px]"
|
|
||||||
startDate={startDate}
|
|
||||||
endDate={endDate}
|
|
||||||
selectsRange
|
|
||||||
showMonthDropdown
|
|
||||||
filterDate={(date) => moment(date).isSameOrBefore(moment(new Date()))}
|
|
||||||
onChange={([initialDate, finalDate]) => {
|
|
||||||
setStartDate(initialDate ?? moment("01/01/2023").toDate());
|
|
||||||
setEndDate(finalDate);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{displayStats.length > 0 && (
|
{stats.length > 0 && (
|
||||||
<div className="flex -md:flex-col -md:items-center gap-4 flex-wrap">
|
<div className="flex -md:flex-col -md:items-center gap-4 flex-wrap">
|
||||||
{/* Exams per module */}
|
{/* Overall Level per Month */}
|
||||||
<div className="flex flex-col gap-10 border w-full h-fit md:h-96 md:max-w-xs border-mti-gray-platinum p-4 pb-12 rounded-xl">
|
<div className="flex flex-col items-center gap-4 border w-full h-[420px] overflow-y-scroll scrollbar-hide md:max-w-sm border-mti-gray-platinum p-4 pb-12 rounded-xl">
|
||||||
<span className="text-sm font-bold">Exams per Module</span>
|
<div className="flex flex-col gap-2 w-full">
|
||||||
<div className="flex flex-col gap-4">
|
<span className="text-sm font-bold">Overall Level per Month</span>
|
||||||
{MODULE_ARRAY.map((module) => (
|
<DatePicker
|
||||||
<div className="flex flex-col gap-2" key={module}>
|
dateFormat="MMMM yyyy"
|
||||||
<div className="flex justify-between items-end">
|
className="border border-mti-gray-dim/40 px-2 py-1.5 rounded-lg text-center w-[200px]"
|
||||||
<span className="text-xs">
|
minDate={initialStatDate}
|
||||||
<span className="font-medium">{totalExamsByModule(displayStats, module)}</span> of{" "}
|
maxDate={new Date()}
|
||||||
<span className="font-medium">{Object.keys(groupBySession(displayStats)).length}</span>
|
selected={monthlyOverallScoreDate}
|
||||||
|
showMonthYearPicker
|
||||||
|
onChange={setMonthlyOverallScoreDate}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="w-full grid grid-cols-3 gap-4 items-center">
|
||||||
|
{[...Array(31).keys()].map((day) => {
|
||||||
|
const date = moment(
|
||||||
|
`${(day + 1).toString().padStart(2, "0")}/${
|
||||||
|
moment(monthlyOverallScoreDate).get("month") + 1
|
||||||
|
}/${moment(monthlyOverallScoreDate).get("year")}`,
|
||||||
|
"DD/MM/yyyy",
|
||||||
|
);
|
||||||
|
|
||||||
|
return date.isValid() ? (
|
||||||
|
<div
|
||||||
|
key={day}
|
||||||
|
className="flex flex-col gap-1 items-start border border-mti-gray-smoke rounded-lg overflow-hidden">
|
||||||
|
<span className="bg-mti-purple-ultralight w-full px-2 py-1 font-semibold">
|
||||||
|
Day {(day + 1).toString().padStart(2, "0")}
|
||||||
|
</span>
|
||||||
|
<span className="px-2">
|
||||||
|
Level{" "}
|
||||||
|
{calculateTotalScore(stats.filter((s) => timestampToMoment(s).isBefore(date))).toFixed(1)}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs">{capitalize(module)}</span>
|
|
||||||
</div>
|
</div>
|
||||||
<ProgressBar
|
) : null;
|
||||||
color={module}
|
})}
|
||||||
percentage={
|
|
||||||
(totalExamsByModule(displayStats, module) * 100) /
|
|
||||||
Object.keys(groupBySession(displayStats)).length
|
|
||||||
}
|
|
||||||
label=""
|
|
||||||
className="h-3"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Module Score */}
|
{/* Overall Level per Month Graph */}
|
||||||
<div className="flex flex-col gap-10 border w-full h-fit md:h-96 md:max-w-xs border-mti-gray-platinum p-4 pb-12 rounded-xl">
|
<div className="w-full md:max-w-2xl border border-mti-gray-platinum p-4 pb-12 rounded-xl h-fit md:h-[420px]">
|
||||||
<span className="text-sm font-bold">Module Score Bands</span>
|
<div className="flex flex-col gap-2 w-full">
|
||||||
<div className="flex flex-col gap-4">
|
<span className="text-sm font-bold">Overall Level per Month</span>
|
||||||
{MODULE_ARRAY.map((module) => (
|
<DatePicker
|
||||||
<div className="flex flex-col gap-2" key={module}>
|
dateFormat="MMMM yyyy"
|
||||||
<div className="flex justify-between items-end">
|
className="border border-mti-gray-dim/40 px-2 py-1.5 rounded-lg text-center w-[200px]"
|
||||||
<span className="text-xs">
|
minDate={initialStatDate}
|
||||||
<span className="font-medium">{user.levels[module]}</span> of{" "}
|
maxDate={new Date()}
|
||||||
<span className="font-medium">{user.desiredLevels[module]}</span>
|
selected={monthlyOverallScoreDate}
|
||||||
</span>
|
showMonthYearPicker
|
||||||
<span className="text-xs">{capitalize(module)}</span>
|
onChange={setMonthlyOverallScoreDate}
|
||||||
</div>
|
/>
|
||||||
<ProgressBar
|
|
||||||
color={module}
|
|
||||||
percentage={(user.levels[module] * 100) / user.desiredLevels[module]}
|
|
||||||
label=""
|
|
||||||
className="h-3"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Total Score Band per Session */}
|
|
||||||
<div className="w-full md:max-w-2xl border border-mti-gray-platinum p-4 pb-12 rounded-xl h-fit md:h-96">
|
|
||||||
<span className="text-sm font-bold">Total Score Band per Session</span>
|
|
||||||
<Chart
|
<Chart
|
||||||
type="line"
|
type="line"
|
||||||
data={{
|
data={{
|
||||||
labels: Object.keys(groupBySession(displayStats)).map((_, index) => index),
|
labels: [...Array(31).keys()]
|
||||||
|
.map((day) => {
|
||||||
|
const date = moment(
|
||||||
|
`${(day + 1).toString().padStart(2, "0")}/${
|
||||||
|
moment(monthlyOverallScoreDate).get("month") + 1
|
||||||
|
}/${moment(monthlyOverallScoreDate).get("year")}`,
|
||||||
|
"DD/MM/yyyy",
|
||||||
|
);
|
||||||
|
return date.isValid() ? (day + 1).toString().padStart(2, "0") : undefined;
|
||||||
|
})
|
||||||
|
.filter((x) => !!x),
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
type: "line",
|
type: "line",
|
||||||
@@ -292,55 +316,123 @@ export default function Stats() {
|
|||||||
backgroundColor: "#7872BF",
|
backgroundColor: "#7872BF",
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
spanGaps: true,
|
spanGaps: true,
|
||||||
data: calculateTotalScorePerSession(),
|
data: [...Array(31).keys()]
|
||||||
|
.map((day) => {
|
||||||
|
const date = moment(
|
||||||
|
`${(day + 1).toString().padStart(2, "0")}/${
|
||||||
|
moment(monthlyOverallScoreDate).get("month") + 1
|
||||||
|
}/${moment(monthlyOverallScoreDate).get("year")}`,
|
||||||
|
"DD/MM/yyyy",
|
||||||
|
);
|
||||||
|
|
||||||
|
return date.isValid()
|
||||||
|
? calculateTotalScore(
|
||||||
|
stats.filter((s) => timestampToMoment(s).isBefore(date)),
|
||||||
|
).toFixed(1)
|
||||||
|
: undefined;
|
||||||
|
})
|
||||||
|
.filter((x) => !!x),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Module Score Band per Session */}
|
{/* Module Level per Day */}
|
||||||
<div className="w-full md:max-w-2xl border border-mti-gray-platinum p-4 pb-12 rounded-xl h-fit md:h-96">
|
<div className="flex flex-col gap-8 border w-full h-fit md:h-[420px] md:max-w-xs border-mti-gray-platinum p-4 pb-12 rounded-xl">
|
||||||
<span className="text-sm font-bold">Module Score Band per Session</span>
|
<div className="flex flex-col gap-2 w-full">
|
||||||
<Chart
|
<span className="text-sm font-bold">Module Level per Day</span>
|
||||||
type="line"
|
<DatePicker
|
||||||
data={{
|
dateFormat="dd MMMM yyyy"
|
||||||
labels: Object.keys(groupBySession(displayStats)).map((_, index) => index),
|
className="border border-mti-gray-dim/40 px-2 py-1.5 rounded-lg text-center w-[200px]"
|
||||||
datasets: [
|
minDate={initialStatDate}
|
||||||
...MODULE_ARRAY.map((module, index) => ({
|
maxDate={new Date()}
|
||||||
type: "line" as const,
|
selected={monthlyModuleScoreDate}
|
||||||
label: capitalize(module),
|
onChange={setMonthlyModuleScoreDate}
|
||||||
borderColor: COLORS[index],
|
/>
|
||||||
backgroundColor: COLORS[index],
|
</div>
|
||||||
borderWidth: 2,
|
<div className="flex flex-col gap-4">
|
||||||
data: calculateModularScorePerSession(module),
|
{calculateModuleScore(stats.filter((s) => timestampToMoment(s).isBefore(moment(monthlyModuleScoreDate))))
|
||||||
})),
|
.sort(sortByModule)
|
||||||
],
|
.map(({module, score}) => (
|
||||||
}}
|
<div className="flex flex-col gap-2" key={module}>
|
||||||
/>
|
<div className="flex justify-between items-end">
|
||||||
|
<span className="text-xs">
|
||||||
|
<span className="font-medium">{score}</span> of <span className="font-medium">9</span>
|
||||||
|
</span>
|
||||||
|
<span className="text-xs">{capitalize(module)}</span>
|
||||||
|
</div>
|
||||||
|
<ProgressBar color={module as Module} percentage={(score * 100) / 9} label="" className="h-3" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Average Time per Module */}
|
<Divider />
|
||||||
<div className="w-full md:max-w-2xl border border-mti-gray-platinum p-4 pb-12 rounded-xl h-fit md:h-96">
|
|
||||||
<span className="text-sm font-bold">Average Time per Module (in Minutes)</span>
|
{displayStats.length > 0 && (
|
||||||
<Chart
|
<div className="w-full flex flex-col gap-4">
|
||||||
type="line"
|
<DatePicker
|
||||||
data={{
|
dateFormat="dd/MM/yyyy"
|
||||||
labels: Object.keys(groupBySession(displayStats.filter((s) => !!s.timeSpent))).map((_, index) => index),
|
className="border border-mti-gray-dim/40 px-4 py-2 rounded-lg text-center w-80"
|
||||||
datasets: [
|
startDate={startDate}
|
||||||
{
|
endDate={endDate}
|
||||||
type: "line",
|
selectsRange
|
||||||
label: "Average (in minutes)",
|
showMonthDropdown
|
||||||
fill: false,
|
filterDate={(date) => moment(date).isSameOrBefore(moment(new Date()))}
|
||||||
borderColor: "#6A5FB1",
|
onChange={([initialDate, finalDate]) => {
|
||||||
backgroundColor: "#7872BF",
|
setStartDate(initialDate ?? moment("01/01/2023").toDate());
|
||||||
borderWidth: 2,
|
setEndDate(finalDate);
|
||||||
spanGaps: true,
|
}}
|
||||||
data: calculateAverageTimePerModule(),
|
/>
|
||||||
},
|
<div className="flex -md:flex-col -md:items-center gap-4 flex-wrap">
|
||||||
],
|
{/* Module Score Band per Session */}
|
||||||
}}
|
<div className="w-full md:max-w-2xl border border-mti-gray-platinum p-4 pb-12 rounded-xl h-fit md:h-96">
|
||||||
/>
|
<span className="text-sm font-bold">Module Score Band per Session</span>
|
||||||
|
<Chart
|
||||||
|
type="line"
|
||||||
|
data={{
|
||||||
|
labels: Object.keys(groupBySession(displayStats)).map((_, index) => index),
|
||||||
|
datasets: [
|
||||||
|
...MODULE_ARRAY.map((module, index) => ({
|
||||||
|
type: "line" as const,
|
||||||
|
label: capitalize(module),
|
||||||
|
borderColor: COLORS[index],
|
||||||
|
backgroundColor: COLORS[index],
|
||||||
|
borderWidth: 2,
|
||||||
|
data: calculateModularScorePerSession(displayStats, module),
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Average Time per Module */}
|
||||||
|
<div className="w-full md:max-w-2xl border border-mti-gray-platinum p-4 pb-12 rounded-xl h-fit md:h-96">
|
||||||
|
<span className="text-sm font-bold">Average Time per Module (in Minutes)</span>
|
||||||
|
<Chart
|
||||||
|
type="line"
|
||||||
|
data={{
|
||||||
|
labels: Object.keys(groupBySession(displayStats.filter((s) => !!s.timeSpent))).map(
|
||||||
|
(_, index) => index,
|
||||||
|
),
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
type: "line",
|
||||||
|
label: "Average (in minutes)",
|
||||||
|
fill: false,
|
||||||
|
borderColor: "#6A5FB1",
|
||||||
|
backgroundColor: "#7872BF",
|
||||||
|
borderWidth: 2,
|
||||||
|
spanGaps: true,
|
||||||
|
data: calculateAverageTimePerModule(displayStats),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {Module} from "@/interfaces";
|
import {Module} from "@/interfaces";
|
||||||
import {Exercise} from "@/interfaces/exam";
|
import {Exercise} from "@/interfaces/exam";
|
||||||
|
|
||||||
export const MODULE_ARRAY: Module[] = ["reading", "listening", "writing", "speaking"];
|
export const MODULE_ARRAY: Module[] = ["reading", "listening", "writing", "speaking", "level"];
|
||||||
|
|
||||||
export const moduleLabels: {[key in Module]: string} = {
|
export const moduleLabels: {[key in Module]: string} = {
|
||||||
listening: "Listening",
|
listening: "Listening",
|
||||||
@@ -11,7 +11,7 @@ export const moduleLabels: {[key in Module]: string} = {
|
|||||||
level: "Level",
|
level: "Level",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sortByModule = (a: {module: Module}, b: {module: Module}) => {
|
export const sortByModule = (a: {module: Module; [key: string]: any}, b: {module: Module; [key: string]: any}) => {
|
||||||
return MODULE_ARRAY.findIndex((x) => a.module === x) - MODULE_ARRAY.findIndex((x) => b.module === x);
|
return MODULE_ARRAY.findIndex((x) => a.module === x) - MODULE_ARRAY.findIndex((x) => b.module === x);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ import {convertCamelCaseToReadable} from "@/utils/string";
|
|||||||
import {UserSolution} from "@/interfaces/exam";
|
import {UserSolution} from "@/interfaces/exam";
|
||||||
import {Module} from "@/interfaces";
|
import {Module} from "@/interfaces";
|
||||||
import {MODULES} from "@/constants/ielts";
|
import {MODULES} from "@/constants/ielts";
|
||||||
|
import moment from "moment";
|
||||||
|
|
||||||
|
export const timestampToMoment = (stat: Stat): moment.Moment => {
|
||||||
|
return moment.unix(stat.date > Math.pow(10, 11) ? stat.date / 1000 : stat.date);
|
||||||
|
};
|
||||||
|
|
||||||
export const totalExams = (stats: Stat[]): number => {
|
export const totalExams = (stats: Stat[]): number => {
|
||||||
const moduleStats = formatModuleTotalStats(stats);
|
const moduleStats = formatModuleTotalStats(stats);
|
||||||
|
|||||||
Reference in New Issue
Block a user