Skip to content

Commit

Permalink
Compute assignment grade based on details
Browse files Browse the repository at this point in the history
  • Loading branch information
ledoyen committed May 6, 2024
1 parent 35222d4 commit 4b88239
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/lib/api-mock/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export const getAssignment = async (
type: a.type ?? 'should be defined',
name: a.name ?? 'should be defined',
description: a.description ?? 'should be defined',
grade: mock.gradeAssignment(a).normalized_grade,
start: a.start ?? new Date(0),
stop: a.stop ?? new Date(0),
repo_linked: a.linked,
Expand Down
1 change: 0 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export type Assignment = {
type: string;
name: string;
description: string;
grade: number;
start: Date;
stop: Date;
repo_linked: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@
import Icon from '@iconify/svelte';
import { jsDateToHumanDate, jsDateToHumanTime } from '$lib/utils';
import api from '$lib/api';
import type { Assignment } from '$lib/types';
export let data;
const computeGrade = (a: Assignment): number => {
if (a.latest_run !== undefined) {
let grade = 0;
let max_grade = 0;
for (const detail of a.latest_run.details) {
grade += detail.grade;
if (detail.max_grade !== undefined) {
max_grade += detail.max_grade;
}
}
return Number(((grade * 20) / max_grade).toFixed(2));
} else {
return 0;
}
};
</script>

{#await api.getAssignment(data.moduleId, data.assignmentId)}
Expand Down Expand Up @@ -54,7 +71,7 @@
<div class="mr-1 icon">
<Icon icon="ph:medal-duotone" inline style="font-size: 24px;" />
</div>
<div>Grade: {assignment.grade} / 20</div>
<div>Grade: {computeGrade(assignment)} / 20</div>
</div>
<div class="row disabled center-v">
<div class="mr-1 icon">
Expand Down

0 comments on commit 4b88239

Please sign in to comment.