Added PNGs with partial radial progress

This commit is contained in:
Joao Ramos
2024-01-07 23:51:05 +00:00
parent 7a297a6f6c
commit 5e8e46ff09
25 changed files with 53 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -1,36 +1,50 @@
/* eslint-disable jsx-a11y/alt-text */
import React from "react";
import {
Document,
Page,
View,
Text,
StyleSheet,
Image,
} from "@react-pdf/renderer";
import { styles } from "../styles";
import { ModuleScore } from "@/interfaces/module.scores";
export const RadialResult = ({ module, score, total }: ModuleScore) => (
export const RadialResult = ({ module, score, total, png }: ModuleScore) => (
<View
key="module"
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: 8,
}}
style={[
styles.textFont,
{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: 4,
position: "relative",
},
]}
>
<Text
style={[
styles.textFont,
styles.textColor,
styles.textBold,
{ fontSize: 10 },
]}
>
<Text style={[styles.textColor, styles.textBold, { fontSize: 10 }]}>
{module}
</Text>
<Text>{score}</Text>
<Text>Out of {total}</Text>
<Image src={png} style={{ height: "64px", width: "64px" }}></Image>
<View
style={[
styles.textColor,
{
display: "flex",
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%",
alignItems: "center",
justifyContent: "center",
fontSize: 10,
gap: 8,
},
]}
>
<Text style={styles.textBold}>{score}</Text>
<Text style={{ fontSize: 8 }}>out of {total}</Text>
</View>
</View>
);

View File

@@ -5,4 +5,5 @@ export interface ModuleScore {
total: number;
module: Module | 'Overall';
feedback?: string,
png?: string,
}

View File

@@ -125,6 +125,15 @@ const generateQRCode = async (link: string) => {
}
};
type RADIAL_PROGRESS_COLOR = 'laranja' | 'azul';
const getRadialProgressPNG = (color: RADIAL_PROGRESS_COLOR, score: number, total: number) => {
const percent = (score / total) * 100;
const remainder = percent % 10;
const roundedPercent = percent - remainder;
return `public/radial_progress/${color}_${roundedPercent}.png`;
}
async function post(req: NextApiRequest, res: NextApiResponse) {
if (req.session.user) {
const { id } = req.query as { id: string };
@@ -154,7 +163,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
const user = docUser.data() as User;
const stats = docsSnap.docs.map((d) => d.data());
const results = stats.reduce((accm: ModuleScore[], { module, score }) => {
const results = (stats.reduce((accm: ModuleScore[], { module, score }) => {
const fixedModuleStr = module[0].toUpperCase() + module.substring(1);
if (accm.find((e: ModuleScore) => e.module === fixedModuleStr)) {
return accm.map((e: ModuleScore) => {
@@ -179,7 +188,13 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
feedback: getFeedback(module),
},
];
}, []) as ModuleScore[];
}, []) as ModuleScore[]).map((moduleScore) => {
const { score, total } = moduleScore;
return {
...moduleScore,
png: getRadialProgressPNG('azul', score, total),
}
});
const [stat] = stats as Stat[];
@@ -196,6 +211,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
module: "Overall",
score: overallScore,
total: overallTotal,
png: getRadialProgressPNG('laranja', overallScore, overallTotal),
} as ModuleScore;
const testDetails = [overallDetail, ...results];
const renderDetails = () => {