Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions client/src/pivots/AbsenceTrackingList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MAX_PAGE_SIZE } from '@shared/config/settings';
import {
DEFAULT_THRESHOLD_PERCENT,
NEAR_THRESHOLD_ABSENCES,
formatNumber,
formatPercent,
getDetailDateRange,
getLessonHeaders,
Expand Down Expand Up @@ -162,7 +163,7 @@ const SummaryTiles = ({ students, noReportsCount, thresholdPercent, status, onSt
{
label: 'אחוז חיסור כללי',
value: lessons ? formatPercent(unapproved / lessons) : '–',
hint: `${unapproved} חיסורים לא מאושרים · ${approved} מאושרים`,
hint: `${formatNumber(unapproved)} חיסורים לא מאושרים · ${formatNumber(approved)} מאושרים`,
},
];
return (
Expand Down Expand Up @@ -199,8 +200,8 @@ const SummaryTiles = ({ students, noReportsCount, thresholdPercent, status, onSt
};

const leftText = ({ key, left }) => {
if (key === 'over') return left === 0 ? 'הגיעה לסף' : `${-left} מעל הסף`;
return left === 1 ? 'עוד חיסור אחד לסף' : `עוד ${left} חיסורים לסף`;
if (key === 'over') return left === 0 ? 'הגיעה לסף' : `${formatNumber(-left)} מעל הסף`;
return left === 1 ? 'עוד חיסור אחד לסף' : `עוד ${formatNumber(left)} חיסורים לסף`;
};

const ThresholdMeter = ({ student, thresholdRatio }) => {
Expand Down Expand Up @@ -246,7 +247,7 @@ const SubjectChips = ({ subjects }) => {
key={subject.key}
sx={{ ...chipSx, ...(index === 0 && subject.abs >= 3 && { borderColor: 'transparent', ...STATUS_STYLES.over.pill, fontWeight: 600 }) }}
>
{subject.name} {subject.abs}
{subject.name} {formatNumber(subject.abs)}
</Box>
))}
{subjects.length > 4 && (
Expand Down Expand Up @@ -311,8 +312,8 @@ const StudentDetail = ({ student, lessonHeaders }) => {
{subjects.map((subject) => (
<tr key={subject.key}>
<Box component="td" sx={cell}>{subject.name}</Box>
<Box component="td" sx={cell}>{subject.lessons}</Box>
<Box component="td" sx={cell}>{subject.abs}</Box>
<Box component="td" sx={cell}>{formatNumber(subject.lessons)}</Box>
<Box component="td" sx={cell}>{formatNumber(subject.abs)}</Box>
<Box component="td" sx={cell}>{formatPercent(subject.ratio)}</Box>
</tr>
))}
Expand All @@ -326,7 +327,7 @@ const StudentDetail = ({ student, lessonHeaders }) => {
<Box component="ul" sx={{ m: 0, p: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 0.25 }}>
{absences.slice(0, 10).map((absence) => (
<Typography component="li" variant="body2" key={absence.id}>
{formatDate(absence.date)} · {absence.subject}{absence.count > 1 ? ` (${absence.count})` : ''}
{formatDate(absence.date)} · {absence.subject}{absence.count > 1 ? ` (${formatNumber(absence.count)})` : ''}
</Typography>
))}
</Box>
Expand Down Expand Up @@ -373,7 +374,7 @@ const StudentRow = ({ student, thresholdRatio, lessonHeaders, open, onToggle })
<Box sx={{ minWidth: 0 }}>
<Typography variant="body2" sx={{ fontWeight: 600, overflowWrap: 'anywhere' }}>{student.name}</Typography>
<Typography variant="caption" color="text.secondary">
{student.unapproved} לא מאושרים מתוך {student.lessons} שיעורים{student.approved ? ` · ${student.approved} מאושרים` : ''}
{formatNumber(student.unapproved)} לא מאושרים מתוך {formatNumber(student.lessons)} שיעורים{student.approved ? ` · ${formatNumber(student.approved)} מאושרים` : ''}
</Typography>
</Box>
<ThresholdMeter student={student} thresholdRatio={thresholdRatio} />
Expand Down
3 changes: 3 additions & 0 deletions client/src/utils/absenceTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ export function getDetailDateRange(extra = {}, reportMonth) {
}

export const formatPercent = (ratio) => `${(ratio * 100).toFixed(1)}%`;

// Absence counts can be fractional; show at most one decimal and hide float noise (9.600000000000001).
export const formatNumber = (value) => String(Math.round((Number(value) || 0) * 10) / 10);
10 changes: 10 additions & 0 deletions client/src/utils/absenceTracking.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
formatNumber,
getDetailDateRange,
getLessonHeaders,
getStudentStats,
Expand Down Expand Up @@ -123,3 +124,12 @@ describe('getDetailDateRange', () => {
expect(getDetailDateRange({}, undefined)).toEqual({ from: undefined, to: undefined });
});
});

describe('formatNumber', () => {
it('rounds to one decimal and hides float noise', () => {
expect(formatNumber(9.600000000000001)).toBe('9.6');
expect(formatNumber(8.899999999999999)).toBe('8.9');
expect(formatNumber(20)).toBe('20');
expect(formatNumber(2.25)).toBe('2.3');
});
});
Loading