diff --git a/src/App.jsx b/src/App.jsx index 1a7a3d17..7735c01a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -16,7 +16,7 @@ import Canardman from "./components/Canardman/Canardman"; import AppLoading from "./components/generic/Loading/AppLoading"; import EdpUnblock from "./components/EdpUnblock/EdpUnblock" import { useCreateNotification } from "./components/generic/PopUps/Notification"; -import { getGradeValue, calcAverage, findCategory, calcCategoryAverage, calcGeneralAverage, formatSkills } from "./utils/gradesTools"; +import { getGradeValue, calcAverage, findCategory, calcCategoryAverage, calcGeneralAverage, formatSkills, safeParseFloat } from "./utils/gradesTools"; import { areOccurenciesEqual, createUserLists, encrypt, decrypt, getBrowser } from "./utils/utils"; import { getCurrentSchoolYear } from "./utils/date"; import { getProxiedURL } from "./utils/requests"; @@ -695,9 +695,9 @@ export default function App() { newSubject.elementType = "subject"; newSubject.id = matiere.id.toString(); newSubject.name = matiere.discipline.replace(". ", ".").replace(".", ". "); - newSubject.classAverage = !isNaN(parseFloat(matiere.moyenneClasse?.replace(",", "."))) ? parseFloat(matiere.moyenneClasse?.replace(",", ".")) : "N/A"; - newSubject.minAverage = !isNaN(parseFloat(matiere.moyenneMin?.replace(",", "."))) ? parseFloat(matiere.moyenneMin?.replace(",", ".")) : "N/A"; - newSubject.maxAverage = !isNaN(parseFloat(matiere.moyenneMax?.replace(",", "."))) ? parseFloat(matiere.moyenneMax?.replace(",", ".")) : "N/A"; + newSubject.classAverage = safeParseFloat(matiere.moyenneClasse); + newSubject.minAverage = safeParseFloat(matiere.moyenneMin); + newSubject.maxAverage = safeParseFloat(matiere.moyenneMax); newSubject.coef = matiere.coef; newSubject.size = matiere.effectif; newSubject.rank = matiere.rang; @@ -781,12 +781,12 @@ export default function App() { newGrade.type = grade.typeDevoir; newGrade.date = new Date(grade.date); newGrade.entryDate = new Date(grade.dateSaisie); - newGrade.coef = parseFloat(grade.coef); - newGrade.scale = isNaN(parseFloat(grade.noteSur)) ? "N/A" : parseFloat(grade.noteSur); + newGrade.coef = safeParseFloat(grade.coef); + newGrade.scale = safeParseFloat(grade.noteSur); newGrade.value = getGradeValue(grade.valeur); - newGrade.classMin = isNaN(parseFloat(grade.minClasse?.replace(",", "."))) ? "N/A" : parseFloat(grade.minClasse?.replace(",", ".")); - newGrade.classMax = isNaN(parseFloat(grade.maxClasse?.replace(",", "."))) ? "N/A" : parseFloat(grade.maxClasse?.replace(",", ".")); - newGrade.classAverage = isNaN(parseFloat(grade.moyenneClasse?.replace(",", "."))) ? "N/A" : parseFloat(grade.moyenneClasse?.replace(",", ".")); + newGrade.classMin = safeParseFloat(grade.minClasse); + newGrade.classMax = safeParseFloat(grade.maxClasse); + newGrade.classAverage = safeParseFloat(grade.moyenneClasse); newGrade.subjectName = grade.libelleMatiere; newGrade.isSignificant = !grade.nonSignificatif; newGrade.examSubjectSRC = grade.uncSujet; diff --git a/src/utils/gradesTools.jsx b/src/utils/gradesTools.jsx index 4df49dbc..775433e3 100644 --- a/src/utils/gradesTools.jsx +++ b/src/utils/gradesTools.jsx @@ -16,6 +16,10 @@ export function getGradeValue(gradeValue) { return isNaN(output) ? "N/A" : output; } +export function safeParseFloat(value) { + return isNaN(parseFloat(value?.replace(",", "."))) ? "N/A" : parseFloat(value?.replace(",", ".")) +} + export function calcAverage(list) { let average = 0; let coef = 0;