-
Notifications
You must be signed in to change notification settings - Fork 349
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
Feature/jplag implementation #447
base: development
Are you sure you want to change the base?
Changes from 9 commits
dd70500
469b1ac
28c50d9
611bbac
6fa26f0
c83919c
4d0abe3
eb8c0e8
bf1f7d6
1caabe4
b95fa31
2a23759
f9b0ae0
dab43cb
a45eb6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,17 +14,26 @@ def last_plagarism_scan | |
end | ||
|
||
# Pass tasks on to plagarism detection software and setup links between students | ||
def check_moss_similarity(force: false) | ||
def check_similarity(force: false) | ||
# Get each task... | ||
return unless active | ||
|
||
# need pwd to restore after cding into submission folder (so the files do not have full path) | ||
pwd = FileUtils.pwd | ||
|
||
# making temp directory for unit - jplag | ||
root_work_dir = Rails.root.join("tmp", "jplag", "#{code}-#{id}") | ||
unit_code = "#{code}-#{id}" | ||
FileUtils.mkdir_p(root_work_dir) | ||
|
||
begin | ||
logger.info "Checking plagiarsm for unit #{code} - #{name} (id=#{id})" | ||
|
||
task_definitions.each do |td| | ||
# making temp directory for each task - jplag | ||
tasks_dir = root_work_dir.join(td.id.to_s) | ||
FileUtils.mkdir_p(tasks_dir) | ||
|
||
next if td.moss_language.nil? || td.upload_requirements.nil? || td.upload_requirements.select { |upreq| upreq['type'] == 'code' && upreq['tii_check'] }.empty? | ||
|
||
type_data = td.moss_language.split | ||
|
@@ -35,6 +44,9 @@ def check_moss_similarity(force: false) | |
tasks = tasks_for_definition(td) | ||
tasks_with_files = tasks.select(&:has_pdf) | ||
|
||
# JPLAG | ||
run_jplag_on_done_files(td, tasks_dir, tasks_with_files, unit_code) | ||
|
||
JackSCarroll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Skip if not due yet | ||
next if td.due_date > Time.zone.now | ||
|
||
|
@@ -48,6 +60,7 @@ def check_moss_similarity(force: false) | |
|
||
# There are new tasks, check these | ||
|
||
|
||
logger.debug 'Contacting MOSS for new checks' | ||
|
||
# Create the MossRuby object | ||
|
@@ -222,4 +235,60 @@ def add_done_files_for_plagiarism_check_of(task_definition, tmp_path, to_check, | |
|
||
self | ||
end | ||
|
||
# JPLAG Function - extracts "done" files for each task and packages them into a directory for JPLAG to run on | ||
def run_jplag_on_done_files(task_definition, tasks_dir, tasks_with_files, unit_code) | ||
type_data = task_definition.moss_language.split | ||
return if type_data.nil? || (type_data.length != 2) || (type_data[0] != 'moss') | ||
similarity_pct = task_definition.plagiarism_warn_pct | ||
return if similarity_pct.nil? | ||
|
||
# Check if the directory exists and create it if it doesn't | ||
results_dir = "/jplag/results/#{unit_code}" | ||
`sudo docker exec jplag sh -c 'if [ ! -d "#{results_dir}" ]; then mkdir -p "#{results_dir}"; fi'` | ||
|
||
# Remove existing result file if it exists | ||
result_file = "#{results_dir}/#{task_definition.id}-result.zip" | ||
`sudo docker exec jplag sh -c 'if [ -f "#{result_file}" ]; then rm "#{result_file}"; fi'` | ||
|
||
# get each code file for each task | ||
task_definition.upload_requirements.each_with_index do |upreq, idx| | ||
# only check code files marked for similarity checks | ||
next unless upreq['type'] == 'code' && upreq['tii_check'] | ||
|
||
pattern = task_definition.glob_for_upload_requirement(idx) | ||
|
||
tasks_with_files.each do |t| | ||
t.extract_file_from_done(tasks_dir, pattern, ->(_task, to_path, name) { File.join(to_path.to_s, t.student.username.to_s, name.to_s) }) | ||
end | ||
|
||
logger.info "Starting JPLAG container to run on #{tasks_dir}" | ||
root_dir = Rails.root.to_s | ||
tasks_dir_split = tasks_dir.to_s.split(root_dir)[1] | ||
|
||
# Set the file language based on the type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can be removing MOSS with this - so the languages can be updated to those we want from JPlag. This would be part of the front end change as well. |
||
# Currently only supporting C/C++/C#/Python | ||
# MOSS and JPLAG use different names for some languages, need to be converted | ||
# If new MOSS languages options are added to task-defintion-upload, this will need to be updated | ||
file_lang = case type_data[1] | ||
when 'cc' | ||
'cpp' | ||
when 'python' | ||
'python3' | ||
else | ||
type_data[1] | ||
end | ||
|
||
# Run JPLAG on the extracted files | ||
`sudo docker exec jplag java -jar /jplag/myJplag.jar #{tasks_dir_split} -l #{file_lang} --similarity-threshold=#{similarity_pct} -M RUN -r #{results_dir}/#{task_definition.id}-result` | ||
end | ||
|
||
# Delete the extracted code files from tmp | ||
tmp_dir = Rails.root.join("tmp", "jplag") | ||
logger.info "Deleting files in: #{tmp_dir}" | ||
logger.info "Files to delete: #{Dir.glob("#{tmp_dir}/*")}" | ||
FileUtils.rm_rf(Dir.glob("#{tmp_dir}/*")) | ||
|
||
self | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are the similarity matches created? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to parse the report and link related tasks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a function to create the similarity matches. Here's the commit. |
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this still be moss_language?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using the upload requirement language from the task definition ui
task-definition-upload.component.html
.Feel like it makes sense to use existing language definition considering the task creator has already decided if plagiarism checks are necessary from MOSS.
So if no requirement for MOSS, no requirement for JPLAG.
Let me know if you don't think is this appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this we should remove the old moss code, so these could be renamed...