From 841a885711e91721872118ac203620381ea5a9a1 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Tue, 13 Mar 2018 14:52:40 +0100 Subject: [PATCH] Send hints when scoring --- app/assets/javascripts/editor/execution.js.erb | 1 + app/controllers/concerns/submission_scoring.rb | 2 +- app/controllers/submissions_controller.rb | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/editor/execution.js.erb b/app/assets/javascripts/editor/execution.js.erb index 0d2015e4..5d50e69d 100644 --- a/app/assets/javascripts/editor/execution.js.erb +++ b/app/assets/javascripts/editor/execution.js.erb @@ -30,6 +30,7 @@ CodeOceanEditorWebsocket = { initializeSocketForScoring: function(url) { this.initializeSocket(url); this.websocket.on('default',this.handleScoringResponse.bind(this)); + this.websocket.on('hint', this.showHint.bind(this)); this.websocket.on('exit', this.handleExitCommand.bind(this)); }, diff --git a/app/controllers/concerns/submission_scoring.rb b/app/controllers/concerns/submission_scoring.rb index 5b3c0ce7..06bba11c 100644 --- a/app/controllers/concerns/submission_scoring.rb +++ b/app/controllers/concerns/submission_scoring.rb @@ -13,7 +13,7 @@ module SubmissionScoring submission.exercise.execution_environment.error_templates.each do |template| pattern = Regexp.new(template.signature).freeze if pattern.match(testrun_output) - StructuredError.create_from_template(template, testrun_output) + StructuredError.create_from_template(template, testrun_output, submission) end end end diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 4f1bb49f..9032bda9 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -197,9 +197,8 @@ class SubmissionsController < ApplicationController def kill_socket(tubesock) # search for errors and save them as StructuredError (for scoring runs see submission_scoring.rb) - extract_errors.each do | error | - tubesock.send_data JSON.dump({cmd: 'hint', hint: error.hint, description: error.error_template.description}) - end + errors = extract_errors + send_hints(tubesock, errors) # save the output of this "run" as a "testrun" (scoring runs are saved in submission_scoring.rb) save_run_output @@ -307,11 +306,21 @@ class SubmissionsController < ApplicationController # to ensure responsiveness, we therefore open a thread here. Thread.new { tubesock.send_data JSON.dump(score_submission(@submission)) + + send_hints(tubesock, StructuredError.where(submission: @submission)) + tubesock.send_data JSON.dump({'cmd' => 'exit'}) } end end + def send_hints(tubesock, errors) + errors = errors.to_a.uniq { |e| e.hint} + errors.each do | error | + tubesock.send_data JSON.dump({cmd: 'hint', hint: error.hint, description: error.error_template.description}) + end + end + def set_docker_client @docker_client = DockerClient.new(execution_environment: @submission.execution_environment) end