From 889de1f8d4cbe8c2607b53134a12995df8aca531 Mon Sep 17 00:00:00 2001 From: yoopie Date: Tue, 20 Aug 2024 10:45:39 +0800 Subject: [PATCH] fix hound comments --- .../statistics/live_feedback_concern.rb | 48 +++++++++++-------- .../submission/submissions_controller.rb | 2 +- app/models/course/assessment/live_feedback.rb | 1 + .../assessment/live_feedback_comment.rb | 2 +- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/controllers/concerns/course/statistics/live_feedback_concern.rb b/app/controllers/concerns/course/statistics/live_feedback_concern.rb index f0c520056e..e391522e85 100644 --- a/app/controllers/concerns/course/statistics/live_feedback_concern.rb +++ b/app/controllers/concerns/course/statistics/live_feedback_concern.rb @@ -15,31 +15,41 @@ def fetch_hash_for_live_feedback_assessment(submissions, assessment_live_feedbac def populate_hash(submissions, student_hash, assessment_live_feedbacks) submissions.each do |submission| - submitter_course_user = submission.creator.course_users.select do |u| - u.course_id == @assessment.course_id - end.first + submitter_course_user = find_submitter_course_user(submission) next unless submitter_course_user&.student? - # Initialize the feedback count array with zeros for each user - feedback_count = Array.new(@question_order_hash.size, 0) + feedback_count = initialize_feedback_count - user_assessment_live_feedback = assessment_live_feedbacks.select do |live_feedback| - live_feedback.creator == submitter_course_user - end + user_assessment_live_feedback = find_user_assessment_live_feedback(submitter_course_user, + assessment_live_feedbacks) - user_assessment_live_feedback.each do |feedback| - index = @question_order_hash[feedback.question_id] - # For each feedback, get all the code and all the corresponding comments - # If there is at least 1 comment within ALL the code, increment the feedback count - feedback.code.each do |code| - unless code.comments.empty? - feedback_count[index] += 1 - break - end - end - end + update_feedback_count(feedback_count, user_assessment_live_feedback) student_hash[submitter_course_user] = [submission, feedback_count] end end + + def find_submitter_course_user(submission) + submission.creator.course_users.find { |u| u.course_id == @assessment.course_id } + end + + def initialize_feedback_count + Array.new(@question_order_hash.size, 0) + end + + def find_user_assessment_live_feedback(submitter_course_user, assessment_live_feedbacks) + assessment_live_feedbacks.select { |live_feedback| live_feedback.creator == submitter_course_user } + end + + def update_feedback_count(feedback_count, user_assessment_live_feedback) + user_assessment_live_feedback.each do |feedback| + index = @question_order_hash[feedback.question_id] + feedback.code.each do |code| + unless code.comments.empty? + feedback_count[index] += 1 + break + end + end + end + end end diff --git a/app/controllers/course/assessment/submission/submissions_controller.rb b/app/controllers/course/assessment/submission/submissions_controller.rb index 5054fee270..9a85bd71c3 100644 --- a/app/controllers/course/assessment/submission/submissions_controller.rb +++ b/app/controllers/course/assessment/submission/submissions_controller.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -class Course::Assessment::Submission::SubmissionsController < +class Course::Assessment::Submission::SubmissionsController < \ Course::Assessment::Submission::Controller include Course::Assessment::Submission::SubmissionsControllerServiceConcern include Signals::EmissionConcern diff --git a/app/models/course/assessment/live_feedback.rb b/app/models/course/assessment/live_feedback.rb index b170e4a3ce..e3be1eba20 100644 --- a/app/models/course/assessment/live_feedback.rb +++ b/app/models/course/assessment/live_feedback.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Course::Assessment::LiveFeedback < ApplicationRecord belongs_to :assessment, class_name: 'Course::Assessment', foreign_key: 'assessment_id' belongs_to :question, class_name: 'Course::Assessment::Question', foreign_key: 'question_id' diff --git a/app/models/course/assessment/live_feedback_comment.rb b/app/models/course/assessment/live_feedback_comment.rb index a52befc56d..88ec081d16 100644 --- a/app/models/course/assessment/live_feedback_comment.rb +++ b/app/models/course/assessment/live_feedback_comment.rb @@ -1,4 +1,4 @@ -# app/models/course/assessment/live_feedback_comment.rb +# frozen_string_literal: true class Course::Assessment::LiveFeedbackComment < ApplicationRecord belongs_to :code, class_name: 'Course::Assessment::LiveFeedbackCode', foreign_key: 'code_id'