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

Plagiarism checks: Change separation operator for plagiarism csv file #9847

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -37,23 +37,31 @@ export class PlagiarismCasesInstructorViewComponent implements OnInit {
plagiarismCasesForInstructor$.subscribe({
next: (res: HttpResponse<PlagiarismCase[]>) => {
this.plagiarismCases = res.body!;
this.groupedPlagiarismCases = this.plagiarismCases.reduce((acc: { [exerciseId: number]: PlagiarismCase[] }, plagiarismCase) => {
const caseExerciseId = plagiarismCase.exercise?.id;
if (caseExerciseId === undefined) {
return acc;
}

// Group initialization
if (!acc[caseExerciseId]) {
acc[caseExerciseId] = [];
this.exercisesWithPlagiarismCases.push(plagiarismCase.exercise!);
}

// Grouping
acc[caseExerciseId].push(plagiarismCase);
this.groupedPlagiarismCases = this.plagiarismCases.reduce(
(
acc: {
[exerciseId: number]: PlagiarismCase[];
},
plagiarismCase,
) => {
const caseExerciseId = plagiarismCase.exercise?.id;
if (caseExerciseId === undefined) {
return acc;
}

// Group initialization
if (!acc[caseExerciseId]) {
acc[caseExerciseId] = [];
this.exercisesWithPlagiarismCases.push(plagiarismCase.exercise!);
}

// Grouping
acc[caseExerciseId].push(plagiarismCase);

return acc;
}, {});
return acc;
},
{},
);
},
});
}
Expand Down Expand Up @@ -131,19 +139,39 @@ export class PlagiarismCasesInstructorViewComponent implements OnInit {
}

/**
* export the plagiarism cases in CSV format
* set placeholder for undefined values and sanitize the operators away
* @param value
* @private
*/
private sanitizeCSVField(value: any): string {
if (value === null || value === undefined) {
return '-';
AjayvirS marked this conversation as resolved.
Show resolved Hide resolved
}
return String(value).replace(/;/g, '";"');
AjayvirS marked this conversation as resolved.
Show resolved Hide resolved
}
AjayvirS marked this conversation as resolved.
Show resolved Hide resolved

/**
* export the cases in CSV format
*/
exportPlagiarismCases(): void {
const blobParts: string[] = ['Student Login,Exercise,Verdict, Verdict Date\n'];
const headers = ['Student Login', 'Matr. Nr.', 'Exercise', 'Verdict', 'Verdict Date', 'Verdict By'].map((header) => this.sanitizeCSVField(header));
AjayvirS marked this conversation as resolved.
Show resolved Hide resolved
AjayvirS marked this conversation as resolved.
Show resolved Hide resolved
const blobParts: string[] = [headers.join(';') + '\n'];
AjayvirS marked this conversation as resolved.
Show resolved Hide resolved
this.plagiarismCases.forEach((plagiarismCase) => {
AjayvirS marked this conversation as resolved.
Show resolved Hide resolved
const exerciseTitleCSVSanitized = plagiarismCase.exercise?.title?.replace(',', '","');
const fields = [
this.sanitizeCSVField(plagiarismCase.student?.login),
this.sanitizeCSVField(plagiarismCase.student?.visibleRegistrationNumber),
this.sanitizeCSVField(plagiarismCase.exercise?.title),
];
if (plagiarismCase.verdict) {
blobParts.push(
`${plagiarismCase.student?.login},${exerciseTitleCSVSanitized},${plagiarismCase.verdict},${plagiarismCase.verdictDate},${plagiarismCase.verdictBy!.name}\n`,
fields.push(
this.sanitizeCSVField(plagiarismCase.verdict),
this.sanitizeCSVField(plagiarismCase.verdictDate),
this.sanitizeCSVField(plagiarismCase.verdictBy?.name),
);
} else {
blobParts.push(`${plagiarismCase.student?.login},${exerciseTitleCSVSanitized}, No verdict yet, -, -\n`);
fields.push('No verdict yet', '-', '-');
}
blobParts.push(fields.join(';') + '\n');
});
downloadFile(new Blob(blobParts, { type: 'text/csv' }), 'plagiarism-cases.csv');
AjayvirS marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ describe('Plagiarism Cases Instructor View Component', () => {
const downloadSpy = jest.spyOn(DownloadUtil, 'downloadFile');
component.plagiarismCases = [plagiarismCase1, plagiarismCase4];
const expectedBlob = [
'Student Login,Exercise,Verdict, Verdict Date\n',
`Student 1, Test Exercise 1, PLAGIARISM, ${date}, Test Instructor 1\n`,
'Student 2, Test Exercise 2, No verdict yet, -, -\n',
'Student Login; Matr. Nr.; Exercise;Verdict; Verdict Date\n',
`Student 1; -; Test Exercise 1; PLAGIARISM; ${date}; Test Instructor 1\n`,
'Student 2; -; Test Exercise 2; No verdict yet; -; -\n',
];
component.exportPlagiarismCases();
expect(downloadSpy).toHaveBeenCalledOnce();
Expand Down
Loading