Created more types of stats to be showcased:
- Total Exams per Module; - Average Score per Module; - Total Exercises per Type; - Average Score per Exercise Type;
This commit is contained in:
@@ -2,23 +2,13 @@
|
||||
import Head from "next/head";
|
||||
import UserResultChart from "@/components/UserResultChart";
|
||||
import Navbar from "@/components/Navbar";
|
||||
import Icon from "@mdi/react";
|
||||
import {mdiPlus} from "@mdi/js";
|
||||
import Link from "next/link";
|
||||
import clsx from "clsx";
|
||||
import {infoButtonStyle} from "@/constants/buttonStyles";
|
||||
import ProfileCard from "@/components/ProfileCard";
|
||||
|
||||
// TODO: Remove this import
|
||||
import JSON_RESULTS from "@/demo/user_results.json";
|
||||
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {Stat, User} from "@/interfaces/user";
|
||||
import {User} from "@/interfaces/user";
|
||||
import {useEffect, useState} from "react";
|
||||
import useStats from "@/hooks/useStats";
|
||||
import {Module} from "@/interfaces";
|
||||
import {UserResults} from "@/interfaces/results";
|
||||
import {formatModuleTotalStats} from "@/utils/stats";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
const user = req.session.user;
|
||||
@@ -46,42 +36,6 @@ export default function Home({user}: {user: User}) {
|
||||
useEffect(() => setShowEndExam(window.innerWidth <= 960), []);
|
||||
useEffect(() => console.log(stats), [stats]);
|
||||
|
||||
const formatStatsToChart = (data: Stat[]): UserResults => {
|
||||
const result: UserResults = {
|
||||
reading: {
|
||||
exams: [],
|
||||
score: 0,
|
||||
total: 0,
|
||||
},
|
||||
listening: {
|
||||
exams: [],
|
||||
score: 0,
|
||||
total: 0,
|
||||
},
|
||||
writing: {
|
||||
exams: [],
|
||||
score: 0,
|
||||
total: 0,
|
||||
},
|
||||
speaking: {
|
||||
exams: [],
|
||||
score: 0,
|
||||
total: 0,
|
||||
},
|
||||
};
|
||||
|
||||
data.forEach((stat) => {
|
||||
if (result[stat.module].exams)
|
||||
result[stat.module] = {
|
||||
exams: [...result[stat.module].exams.filter((x) => x !== stat.exam), stat.exam],
|
||||
total: result[stat.module].score + (result[stat.module].exams.includes(stat.exam) ? 0 : 1),
|
||||
score: result[stat.module].total + 1,
|
||||
};
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -102,7 +56,7 @@ export default function Home({user}: {user: User}) {
|
||||
</section>
|
||||
{!isLoading && stats && (
|
||||
<section className="w-full lg:w-1/3 h-full flex items-center justify-center">
|
||||
<UserResultChart results={formatStatsToChart(stats)} resultKey="total" label="Total exams" className="w-2/3" />
|
||||
<UserResultChart data={formatModuleTotalStats(stats)} title="Total exams" className="w-2/3" />
|
||||
</section>
|
||||
)}
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user