add cause to testruns

trigger run and assess on request_for_comment
This commit is contained in:
Ralf Teusner
2017-09-13 13:28:31 +02:00
committed by Maximilian Grundke
parent 6dc34d3ebe
commit 194984a620
8 changed files with 53 additions and 18 deletions

View File

@ -59,8 +59,6 @@ CodeOceanEditorCodePilot = {
} }
}; };
//Request for comments does currently not work on staging platform (no relative root_url used here).
//To fix this rely on ruby routes
CodeOceanEditorRequestForComments = { CodeOceanEditorRequestForComments = {
requestComments: function () { requestComments: function () {
var user_id = $('#editor').data('user-id'); var user_id = $('#editor').data('user-id');
@ -83,6 +81,8 @@ CodeOceanEditorRequestForComments = {
}).done(function () { }).done(function () {
this.hideSpinner(); this.hideSpinner();
$.flash.success({text: $('#askForCommentsButton').data('message-success')}); $.flash.success({text: $('#askForCommentsButton').data('message-success')});
// trigger a run
this.runSubmission.call(this, submission);
}.bind(this)).error(this.ajaxError.bind(this)); }.bind(this)).error(this.ajaxError.bind(this));
}; };

View File

@ -142,19 +142,21 @@ CodeOceanEditorSubmissions = {
* Execution-Logic * Execution-Logic
*/ */
runCode: function(event) { runCode: function(event) {
event.preventDefault(); event.preventDefault();
if ($('#run').is(':visible')) { if ($('#run').is(':visible')) {
this.createSubmission('#run', null, function(response) { this.createSubmission('#run', null, this.runSubmission.bind(this));
//Run part starts here }
$('#stop').data('url', response.stop_url); },
this.running = true;
this.showSpinner($('#run')); runSubmission: function (submission) {
$('#score_div').addClass('hidden'); //Run part starts here
this.toggleButtonStates(); $('#stop').data('url', submission.stop_url);
var url = response.run_url.replace(this.FILENAME_URL_PLACEHOLDER, this.active_file.filename.replace(/#$/,'')); // remove # if it is the last character, this is not part of the filename and just an anchor this.running = true;
this.initializeSocketForRunning(url); this.showSpinner($('#run'));
}.bind(this)); $('#score_div').addClass('hidden');
} this.toggleButtonStates();
var url = submission.run_url.replace(this.FILENAME_URL_PLACEHOLDER, this.active_file.filename.replace(/#$/,'')); // remove # if it is the last character, this is not part of the filename and just an anchor
this.initializeSocketForRunning(url);
}, },
saveCode: function(event) { saveCode: function(event) {

View File

@ -42,6 +42,14 @@ div.positive-result {
box-shadow: 0px 0px 11px 1px rgba(44,222,0,1); box-shadow: 0px 0px 11px 1px rgba(44,222,0,1);
} }
div.unknown-result {
border-radius: 50%;
background-color: #ffca00;
-webkit-box-shadow: 0px 0px 11px 1px rgb(255, 202, 0);
-moz-box-shadow: 0px 0px 11px 1px rgb(255, 202, 0);
box-shadow: 0px 0px 11px 1px rgb(255, 202, 0);
}
div.negative-result { div.negative-result {
border-radius: 50%; border-radius: 50%;
background-color: #ff2600; background-color: #ff2600;

View File

@ -9,7 +9,7 @@ module SubmissionScoring
assessment = assessor.assess(output) assessment = assessor.assess(output)
passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score] > 0)) passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score] > 0))
testrun_output = passed ? nil : output[:stderr] testrun_output = passed ? nil : output[:stderr]
Testrun.new(submission: submission, file: file, passed: passed, output: testrun_output).save Testrun.new(submission: submission, cause: 'assess', file: file, passed: passed, output: testrun_output).save
output.merge!(assessment) output.merge!(assessment)
output.merge!(filename: file.name_with_extension, message: feedback_message(file, output[:score]), weight: file.weight) output.merge!(filename: file.name_with_extension, message: feedback_message(file, output[:score]), weight: file.weight)
end end

View File

@ -1,4 +1,5 @@
class RequestForCommentsController < ApplicationController class RequestForCommentsController < ApplicationController
include SubmissionScoring
before_action :set_request_for_comment, only: [:show, :edit, :update, :destroy, :mark_as_solved, :set_thank_you_note] before_action :set_request_for_comment, only: [:show, :edit, :update, :destroy, :mark_as_solved, :set_thank_you_note]
skip_after_action :verify_authorized skip_after_action :verify_authorized
@ -107,6 +108,10 @@ class RequestForCommentsController < ApplicationController
@request_for_comment = RequestForComment.new(request_for_comment_params) @request_for_comment = RequestForComment.new(request_for_comment_params)
respond_to do |format| respond_to do |format|
if @request_for_comment.save if @request_for_comment.save
# create thread here and execute tests. A run is triggered from the frontend and does not need to be handled here.
Thread.new do
score_submission(@request_for_comment.submission)
end
format.json { render :show, status: :created, location: @request_for_comment } format.json { render :show, status: :created, location: @request_for_comment }
else else
format.html { render :new } format.html { render :new }

View File

@ -262,7 +262,7 @@ class SubmissionsController < ApplicationController
def save_run_output def save_run_output
if !@message_buffer.blank? if !@message_buffer.blank?
@message_buffer = @message_buffer[(0..max_message_buffer_size-1)] # trim the string to max_message_buffer_size chars @message_buffer = @message_buffer[(0..max_message_buffer_size-1)] # trim the string to max_message_buffer_size chars
Testrun.create(file: @file, submission: @submission, output: @message_buffer) Testrun.create(file: @file, cause: 'run', submission: @submission, output: @message_buffer)
end end
end end

View File

@ -54,8 +54,10 @@ h1 = "#{@exercise} (external user #{@external_user})"
-submission_or_intervention.testruns.each do |run| -submission_or_intervention.testruns.each do |run|
- if run.passed - if run.passed
.unit-test-result.positive-result title=run.output .unit-test-result.positive-result title=run.output
- else - elsif run.failed
.unit-test-result.negative-result title=run.output .unit-test-result.negative-result title=run.output
- else
.unit-test-result.unknown-result title=run.output
td = Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0 td = Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0
-working_times_until.push((Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0)) -working_times_until.push((Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0))
- elsif submission_or_intervention.is_a? UserExerciseIntervention - elsif submission_or_intervention.is_a? UserExerciseIntervention

View File

@ -0,0 +1,18 @@
class AddCauseToTestruns < ActiveRecord::Migration
def up
add_column :testruns, :cause, :string
Testrun.reset_column_information
Testrun.all.each{ |testrun|
if(testrun.submission.nil?)
say_with_time "#{testrun.id} has no submission" do end
else
testrun.cause = testrun.submission.cause
testrun.save
end
}
end
def down
remove_column :testruns, :cause
end
end