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

Diff view between student submission and another file #1364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mikael-Lenander
Copy link
Contributor

@Mikael-Lenander Mikael-Lenander commented May 19, 2024

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?

  • Accessibility test using the WAVE extension.
  • Django unit tests.
  • Selenium tests.
  • Other test. (Add a description below)
  • Manual testing.

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

  • Chrome
  • Firefox
  • This pull request cannot be tested in the browser.

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

Translation

Programming style

  • Did you follow our style guides?
  • Did you use Python type hinting in all functions that you added or edited? (type hints for function parameters and return values)

Have you updated the README or other relevant documentation?

  • documents inside the doc directory.
  • README.md.
  • Aplus Manual.
  • Other documentation (mention below which documentation).

Is it Done?

  • Reviewer has finished the code review
  • After the review, the developer has made changes accordingly
  • Customer/Teacher has accepted the implementation of the feature

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

@Mikael-Lenander
Copy link
Contributor Author

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

@Mikael-Lenander Mikael-Lenander changed the title Diff view between student submission and model answer Diff view between student submission and another file May 27, 2024
@Mikael-Lenander Mikael-Lenander force-pushed the easy-diff branch 2 times, most recently from 51e660b to 2af0a31 Compare May 28, 2024 13:07
@Mikael-Lenander
Copy link
Contributor Author

Ready to be reviewed!

@Mikael-Lenander
Copy link
Contributor Author

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

@ihalaij1 ihalaij1 self-assigned this Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

Enable easy diffs between student solution and example solution
2 participants