apluslms / a-plus

A+ frontend portal - A+ LMS documentation:
https://apluslms.github.io/
Other
64 stars 72 forks source link

Diff view between student submission and another file #1364

Closed Mikael-Lenander closed 3 weeks ago

Mikael-Lenander commented 1 month ago

Description

What?

Shows the difference of a student submission and another submission of the same student or model solution in the inspect page in git style. Green lines indicate the lines that the student has "added" compared to the other submission and red lines indicate the lines that the student has "removed". The original line numbers of both files are displayed on the left in GitLab style. When the submission is copied or downloaded with buttons "Copy to clipboard" or "Download", the diff lines are included if the compare mode is on.

image image

Why?

Makes it easier for TAs to find bugs and catch plagiarism in students' submissions.

How?

Adds a query param "compare_to" to SubmittedFileView that returns the diff of the submitted file and another file. Possible options for the param are id of another submission or the string "model" (to compare to the model submission). The diff of the files are shown so that marker ' ' (two spaces) is prepended to the common lines and the marker '+ ' or '- ' is prepended to lines that are unique to the files. See https://docs.python.org/3/library/difflib.html for more details. The lines are rendered with different background colors depending on these markers. Some model answers have different versions for different languages, so the language of the submission is considered when fetching the model answer.

CAUTIONS: If the exercise submission includes multiple files, the files have to be paired when they are compared. When a student submits a solution, each submitted file is given a param_name file{i}, where i is an index starting from 1. The code that pairs the model submission files with the student's submitted files assumes that the model submission files in the LearningObject.model_answers attribute are listed in the same order as the file indices in the submitted files. I tested that this pairing scheme works, but it is not very reliable, as it is solely based on the file order. We could use file names to pair the files more reliably, but this does not work if the student gives different names to the files that the model solution files have.

Fixes #1129

Testing

Remember to add or update unit tests for new features and changes.

What type of test did you run?

Submitted assignments to 5+ exercises in O1 and A+ manual local instances. Compared the submissions to the model solution and previous submissions. Line numbers and colors are displayed correctly. Compare button is not shown in the submission table if there is only one submission. "Compare to model answer" button is not shown if the exercise has no model answer. An error message is shown if the compare_to param is changed to an invalid value. Buttons "Download" and "Copy to clipboard" work as expected. Submissions are compared to the model solution with the correct language version, even if the assistant uses a different language than the submitter. Submissions with arbitrary file names are paired with correct model solution files. Added playwright tests.

Did you test the changes in

Think of what is affected by these changes and could become broken

Translation

Programming style

Have you updated the README or other relevant documentation?

Is it Done?

Clean up your git commit history before submitting the pull request!

Mikael-Lenander commented 1 month ago

New feature request to this pr: compare to previous submission. So still in progress.

Mikael-Lenander commented 1 month ago

Ready to be reviewed!

Mikael-Lenander commented 1 month ago

The lint tests should not fail. The only issues are in some sample submissions I use in end-to-end tests.