WING-NUS / SSID

Student Submission Integrity Diagnosis
18 stars 23 forks source link

Feature/sort #319

Closed mengyewgau closed 1 year ago

mengyewgau commented 1 year ago

Added a button on remarks to sort it by descending order and ascending order

Description

Sorting by descending order (Suspected, Confirmed, Blank) implemented. The priority on sort is always on maximum similarity descending, which indicates how similar both submissions are.

Related Issue

This PR aims to fix #305, providing the update. The filter function suggested was not implemented, as I felt it might not be very useful in enhancing the user experience, and has no fundamental difference to the sort function

Motivation and Context

The objective is for reviewers to have a priority ranking on which suspected cases they can review first, based on which is the most similar!

How Has This Been Tested?

Screenshots (if appropriate):

Screenshot from 2023-09-11 01-02-46

Types of changes

Checklist:

coveralls commented 1 year ago

Coverage Status

coverage: 4.121% (-0.003%) from 4.124% when pulling eec135ff1da1562a2bc99f17a389ccb8da24f2b3 on mengyewgau:feature/sort into 0e0658c862423013acde6d67b1cacfefcc1ea569 on WING-NUS:master.

huyuxin0429 commented 1 year ago

Due to urgent user request, this functionality will be added to the base repo asap. User wants both max similarity and average similarity to be the top sorted results first

knmnyn commented 1 year ago

Thanks for doing this on an urgent basis!

sibinhho99 commented 1 year ago

Due to urgent user request, this functionality will be added to the base repo asap. User wants both max similarity and average similarity to be the top sorted results first

This PR concerns with adding sorting the Remarks/ Status (e.g. "Suspected of Plagiarism" etc.). There's no change on the current sorting mechanism used, the logic of which can be found in

https://github.com/WING-NUS/SSID/blob/0e0658c862423013acde6d67b1cacfefcc1ea569/app/models/assignment.rb#L87

https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-order

More specifically, the corresponding SQL query would sort the entries first by assignment ID, and if the assignment ID is tied, by descending similarity (which is max_similarity). It is not specified here whether if max similarities tie, average similarity is sorted (though I'd say it's extremely unlikely two assignments have exact same max similarities) and how it currently behaves.

The statement "max similarity and average similarity to be the top sorted results first" needs to be clarified or made more precise. Explicitly adding average similarity to the order clause is trivial. It's probably too complicated to include some fuzzy recommendations based on two attributes? In that case I feel the current sorting by only max_similarity suffices.

sibinhho99 commented 1 year ago

Due to urgent user request, this functionality will be added to the base repo asap. User wants both max similarity and average similarity to be the top sorted results first

This PR concerns with adding sorting the Remarks/ Status (e.g. "Suspected of Plagiarism" etc.). There's no change on the current sorting mechanism used, the logic of which can be found in

https://github.com/WING-NUS/SSID/blob/0e0658c862423013acde6d67b1cacfefcc1ea569/app/models/assignment.rb#L87

https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-order

More specifically, the corresponding SQL query would sort the entries first by assignment ID, and if the assignment ID is tied, by descending similarity (which is max_similarity). It is not specified here if max similarities tie, average similarity is sorted (though I'd say it's extremely unlikely two assignments have exact same max similarities) and how it currently behaves.

The statement "max similarity and average similarity to be the top sorted results first" needs to be clarified or made more precise. Explicitly adding average similarity to the order clause is trivial. It's probably too complicated to include some fuzzy recommendations based on two attributes? In that case I feel the current sorting by only max_similarity suffices.

Screenshot of current default ordering:

image
huyuxin0429 commented 1 year ago

The user requested for the the columns to be sorted with the maximum values of max similarity and average similarity appearing at the top. I interpreted this as performing a multilevel sort, first by avg similarity, then max similarity. I intend to add those functionality to this PR as it is the most relevant, and merge it into main once completed.

I dont really see much of an reason to sort by submission id, as that does not really give us any useful information.

I have done a raw SQL query directly on the database, here is the query:

SELECT U1.name as "Student 1", U2.name as "Student 2", Greatest(SS.similarity_1_to_2, SS.similarity_2_to_1) as "Max Similarity", ((SS.similarity_1_to_2 + SS.similarity_2_to_1)/2) as "Avg Similarity"
FROM ssid_production.submission_similarities as SS
inner join ssid_production.assignments on SS.assignment_id = ssid_production.assignments.id
inner join ssid_production.submissions AS S1 on SS.submission1_id = S1.id
inner join ssid_production.submissions AS S2 on SS.submission2_id = S2.id
inner join ssid_production.courses on ssid_production.assignments.course_id = ssid_production.courses.id
inner join ssid_production.users AS U1 on U1.id = S1.student_id
inner join ssid_production.users AS U2 on U2.id = S2.student_id
WHERE ssid_production.assignments.title = 'Assignment 2'
AND ssid_production.courses.code = 'CS1010E'
order by ((SS.similarity_1_to_2 + SS.similarity_2_to_1)/2) DESC, Greatest(SS.similarity_1_to_2, SS.similarity_2_to_1) DESC

I'll translate this to the relevant rails query, probably in accordance to https://guides.rubyonrails.org/active_record_querying.html.