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 React from "react";
import { import {
Document,
Page,
View, View,
Text, Text,
StyleSheet,
Image, Image,
} from "@react-pdf/renderer"; } from "@react-pdf/renderer";
import { styles } from "../styles"; import { styles } from "../styles";
import { ModuleScore } from "@/interfaces/module.scores"; import { ModuleScore } from "@/interfaces/module.scores";
export const RadialResult = ({ module, score, total }: ModuleScore) => ( export const RadialResult = ({ module, score, total, png }: ModuleScore) => (
<View <View
key="module" key="module"
style={{ style={[
display: "flex", styles.textFont,
flexDirection: "column", {
alignItems: "center", display: "flex",
gap: 8, flexDirection: "column",
}} alignItems: "center",
gap: 4,
position: "relative",
},
]}
> >
<Text <Text style={[styles.textColor, styles.textBold, { fontSize: 10 }]}>
style={[
styles.textFont,
styles.textColor,
styles.textBold,
{ fontSize: 10 },
]}
>
{module} {module}
</Text> </Text>
<Text>{score}</Text> <Image src={png} style={{ height: "64px", width: "64px" }}></Image>
<Text>Out of {total}</Text> <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>
); );

View File

@@ -5,4 +5,5 @@ export interface ModuleScore {
total: number; total: number;
module: Module | 'Overall'; module: Module | 'Overall';
feedback?: string, 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) { async function post(req: NextApiRequest, res: NextApiResponse) {
if (req.session.user) { if (req.session.user) {
const { id } = req.query as { id: string }; 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 user = docUser.data() as User;
const stats = docsSnap.docs.map((d) => d.data()); 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); const fixedModuleStr = module[0].toUpperCase() + module.substring(1);
if (accm.find((e: ModuleScore) => e.module === fixedModuleStr)) { if (accm.find((e: ModuleScore) => e.module === fixedModuleStr)) {
return accm.map((e: ModuleScore) => { return accm.map((e: ModuleScore) => {
@@ -179,7 +188,13 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
feedback: getFeedback(module), 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[]; const [stat] = stats as Stat[];
@@ -196,6 +211,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
module: "Overall", module: "Overall",
score: overallScore, score: overallScore,
total: overallTotal, total: overallTotal,
png: getRadialProgressPNG('laranja', overallScore, overallTotal),
} as ModuleScore; } as ModuleScore;
const testDetails = [overallDetail, ...results]; const testDetails = [overallDetail, ...results];
const renderDetails = () => { const renderDetails = () => {