Skip to content

Commit

Permalink
Account for hooks in viewFeedback instead of feedback output (#2003)
Browse files Browse the repository at this point in the history
* preliminary working version

* resolve merge conflicts

* use submission.scores instead of feedback array

* don't show non autograded scores in autograded scores tab

* rabbit ai suggestions

* more rabbit.ai nits

* make finishedAutograding not an instance variable
  • Loading branch information
michellexliu authored Dec 1, 2023
1 parent 08e9710 commit 84f92d4
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions app/controllers/assessments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -660,16 +660,17 @@ def history
def viewFeedback
# User requested to view feedback on a score
@score = @submission.scores.find_by(problem_id: params[:feedback])
autograded_scores = @submission.scores.includes(:problem).where(grader_id: 0)
# Checks whether at least one problem has finished being auto-graded
@finishedAutograding = @submission.scores.where.not(feedback: nil).where(grader_id: 0)
finishedAutograding = @submission.scores.where.not(feedback: nil).where(grader_id: 0)
@job_id = @submission["jobid"]
@submission_id = params[:submission_id]

# Autograding is not in-progress and no score is available
if @score.nil?
if !@finishedAutograding.empty?
if !finishedAutograding.empty?
redirect_to(action: "viewFeedback",
feedback: @finishedAutograding.first.problem_id,
feedback: finishedAutograding.first.problem_id,
submission_id: params[:submission_id]) && return
end

Expand All @@ -683,7 +684,10 @@ def viewFeedback
return if @score.nil?

@jsonFeedback = parseFeedback(@score.feedback)
@scoreHash = parseScore(@score.feedback)

raw_score_hash = scoreHashFromScores(autograded_scores) if @score.grader_id <= 0
@scoreHash = parseScore(raw_score_hash) unless raw_score_hash.nil?

if Archive.archive? @submission.handin_file_path
@files = Archive.get_files @submission.handin_file_path
end
Expand Down Expand Up @@ -723,28 +727,17 @@ def getPartialFeedback
# TODO: Take into account any modifications by :parseAutoresult and :modifySubmissionScores
# We should probably read the final scores directly
# See: assessment_autograde_core.rb's saveAutograde
def parseScore(feedback)
return if feedback.nil?

lines = feedback.rstrip.lines
feedback = lines[lines.length - 1]
def parseScore(score_hash)
total = 0
return if score_hash.nil?

return unless valid_json_hash?(feedback)

score_hash = JSON.parse(feedback)
score_hash = score_hash["scores"]
if @jsonFeedback&.key?("_scores_order") == false
@jsonFeedback["_scores_order"] = score_hash.keys
end
@total = 0
score_hash.keys.each do |k|
@total += score_hash[k].to_f
rescue NoMethodError
flash.now[:error] ||= ""
flash.now[:error] += "The score for #{k} could not be parsed.<br>"
flash.now[:html_safe] = true
total += score_hash[k].to_f if score_hash[k]
end
score_hash["_total"] = @total
score_hash["_total"] = total
score_hash
end

Expand Down Expand Up @@ -1165,4 +1158,10 @@ def destroy_no_redirect

@assessment.destroy # awwww!!!!
end

def scoreHashFromScores(scores)
scores.map { |s|
[s.problem.name, s.score]
}.to_h
end
end

0 comments on commit 84f92d4

Please sign in to comment.