From 3d5ced89c680b80737723637efa8b3a72a5a5afd Mon Sep 17 00:00:00 2001 From: Riku Rauhala Date: Tue, 22 Oct 2024 19:49:00 +0300 Subject: [PATCH] [Class statistics] Fix pass rate --- .../PopulationCourseStats/PassFailEnrollments/index.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/frontend/src/components/PopulationCourseStats/PassFailEnrollments/index.jsx b/services/frontend/src/components/PopulationCourseStats/PassFailEnrollments/index.jsx index 6fef994ed3..3b711a8396 100644 --- a/services/frontend/src/components/PopulationCourseStats/PassFailEnrollments/index.jsx +++ b/services/frontend/src/components/PopulationCourseStats/PassFailEnrollments/index.jsx @@ -8,6 +8,13 @@ import { CourseFilterToggle } from '../CourseFilterToggle' import { UsePopulationCourseContext } from '../PopulationCourseContext' import './passFailEnrollments.css' +const calculatePassRate = (total, passed) => { + if (total === 0) { + return 0 + } + return (100 * passed) / total +} + export const PassFailEnrollments = ({ flat, onlyIamRights }) => { const { modules, courseStatistics, onGoToCourseStatisticsClick, toggleGroupExpansion, expandedGroups } = UsePopulationCourseContext() @@ -96,7 +103,7 @@ export const PassFailEnrollments = ({ flat, onlyIamRights }) => { title: 'Pass rate', cellStyle: { textAlign: 'right' }, filterType: 'range', - getRowVal: row => row.stats?.percentageWithEnrollments ?? 0, + getRowVal: row => calculatePassRate(row.stats?.totalStudents, row.stats?.passed), formatValue: value => value && new Intl.NumberFormat('fi-FI', {