Skip to content

Commit

Permalink
Fix off by one fault
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikRemo committed Nov 12, 2024
1 parent d73a07f commit b1856f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default function ExpertLinks(props: ExpertLinksProps) {
<div className="bg-blue-500 h-2 rounded" style={{ width: `${progressPercentage}%` }} />
</div>
<span className="text-sm text-gray-700">
{completed === 0 ? 'Not started' : `${completed} / ${total} completed`}
{completed === 0 ? 'Not started' : completed === total ? 'Finished 🏁' : `${completed} / ${total} completed`}
</span>
</>
)}
Expand Down
15 changes: 6 additions & 9 deletions playground/src/helpers/get_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,19 @@ export function getProgressStatsFromFileSync(
return undefined;
}

const totalSubmissions = config.exercises.reduce((acc, exercise) => acc + (exercise.submissions?.length || 0), 0);

let progressStats: { [expertId: string]: number } = {};
for (const expertId of expertIds) {
let progress = getProgressFromFileSync(dataMode, expertEvaluationId, expertId);
if (progress) {
let expertProgress = 0;
for (let i = 0; i < progress.current_exercise_index; i++) {
expertProgress += config.exercises[i]?.submissions?.length || 0;
}
expertProgress += progress.current_submission_index;

progressStats[expertId] = expertProgress;
if (progress && progress.is_finished_evaluating) {
progressStats[expertId] = totalSubmissions;
} else if (progress && progress.has_started_evaluating) {
progressStats[expertId] = config.exercises.slice(0, progress.current_exercise_index).reduce((sum, exercise) => sum + exercise.submissions!.length, 0) + progress.current_submission_index;
}
}

const totalSubmissions = config.exercises.reduce((acc, exercise) => acc + (exercise.submissions?.length || 0), 0);

return {
totalSubmissions: totalSubmissions,
...progressStats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ export default function SideBySideExpertView() {
};

useEffect(() => {
if (currentSubmissionIndex > 0) {
saveProgress();
}
}, [currentSubmissionIndex, isFinishedEvaluating]);
saveProgress();
}, [currentSubmissionIndex, currentExerciseIndex, isFinishedEvaluating]);

const handlePrevious = () => {
// If we are not at the first submission, just decrement the submission index
Expand Down

0 comments on commit b1856f2

Please sign in to comment.