Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programming exercises: Fix an issue where the result export does not work with structured grading criteria #10174

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ type Points = number;
export class ResultWithPointsPerGradingCriterion {
result: Result;
totalPoints: Points;
pointsPerCriterion: Map<GradingCriterionId, Points>;
// type union is needed here, because deserialized java maps are actually represented as plain JSON key-value pairs
pointsPerCriterion: { [key: string]: number } | Map<GradingCriterionId, Points>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ class ExerciseScoresRowBuilder {
private setGradingCriteriaPoints() {
let unnamedCriterionIndex = 1;
this.gradingCriteria.forEach((criterion) => {
const points = this.resultWithPoints.pointsPerCriterion.get(criterion.id!) || 0;
const pointsPerCriterion = this.resultWithPoints.pointsPerCriterion;
const points = pointsPerCriterion instanceof Map ? pointsPerCriterion.get(criterion.id!) || 0 : +(pointsPerCriterion[criterion.id!] || 0);
if (criterion.title) {
this.set(criterion.title, points);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ export class ResultService implements IResultService {
this.convertResultDatesFromServer(resultWithPoints.result);
const pointsMap = new Map<number, number>();
if (resultWithPoints.pointsPerCriterion) {
resultWithPoints.pointsPerCriterion.forEach((value, key) => {
pointsMap.set(Number(key), value);
Object.entries(resultWithPoints.pointsPerCriterion).forEach(([key, value]) => {
pointsMap.set(+key, value);
});
}
resultWithPoints.pointsPerCriterion = pointsMap;
Expand Down
2 changes: 1 addition & 1 deletion src/test/javascript/spec/service/result.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('ResultService', () => {
const resultWithPoints2 = new ResultWithPointsPerGradingCriterion();
resultWithPoints2.result = result2;
resultWithPoints2.totalPoints = 50;
resultWithPoints2.pointsPerCriterion = new Map(Object.entries({ '1': 20, '2': 30 }).map(([key, value]) => [Number(key), value]));
resultWithPoints2.pointsPerCriterion = { '1': 20, '2': 30 };

const results = [resultWithPoints1, resultWithPoints2];

Expand Down
Loading