Skip to content
Closed
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
11 changes: 6 additions & 5 deletions frontend/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,20 @@ function updateStatistics(subjects) {
return;
}

const scores = subjects.map(subject => subject.scoreValue);
const highest = Math.max(...scores);
let highest = -Infinity;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The initialization of highest to -Infinity changes the behavior compared to the previous Math.max(...scores) implementation when dealing with NaN values. If all scores are NaN, Math.max would return NaN, whereas this loop will leave highest as -Infinity. This could result in the UI displaying "-Infinity" instead of "NaN" or a fallback value. Consider handling NaN explicitly or ensuring the display logic (outside this diff) handles -Infinity gracefully.


// 計算加權平均
// 計算加權平均與最高分 (Combined loop for performance optimization)
let totalWeightedScore = 0;
let totalWeight = 0;

subjects.forEach(subject => {
for (const subject of subjects) {
Comment on lines +135 to +139

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateStatistics behavior changed (highest score + weighted average calculation) but there are no tests covering it, even though this file already has a test suite. Adding a small jsdom-based test that feeds a few prepared subjects (including an invalid/empty score case) and asserts avgScore/highestScore DOM output would help prevent regressions.

Copilot uses AI. Check for mistakes.
const score = subject.scoreValue;
if (score > highest) highest = score;

Comment on lines +139 to +142

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highest is initialized to -Infinity and only updated when score > highest. If any/all subject.scoreValue values are NaN (possible via getNumericScore fallback), the comparison is always false and the UI will render -Infinity as the highest score. Consider skipping non-finite scores (e.g., Number.isFinite(score)) and falling back to '--' when no valid score is found.

Copilot uses AI. Check for mistakes.
const weight = getSubjectWeight(subject.SubjectName);
totalWeightedScore += score * weight;
totalWeight += weight;
});
}

const weightedAvg = totalWeight > 0 ? totalWeightedScore / totalWeight : 0;

Expand Down
Loading
Loading