Parallelize calculation of working_times
This commit is contained in:
@ -1,15 +1,17 @@
|
|||||||
module ActionCableHelper
|
module ActionCableHelper
|
||||||
def trigger_rfc_action_cable
|
def trigger_rfc_action_cable
|
||||||
|
Thread.new do
|
||||||
# Context: RfC
|
# Context: RfC
|
||||||
if submission.study_group_id.present?
|
if submission.study_group_id.present?
|
||||||
ActionCable.server.broadcast(
|
ActionCable.server.broadcast(
|
||||||
"la_exercises_#{exercise_id}_channel_study_group_#{submission.study_group_id}",
|
"la_exercises_#{exercise_id}_channel_study_group_#{submission.study_group_id}",
|
||||||
type: :rfc,
|
type: :rfc,
|
||||||
id: id,
|
id: id,
|
||||||
html: (ApplicationController.render(partial: 'request_for_comments/list_entry',
|
html: (ApplicationController.render(partial: 'request_for_comments/list_entry',
|
||||||
locals: {request_for_comment: self})))
|
locals: {request_for_comment: self})))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def trigger_rfc_action_cable_from_comment
|
def trigger_rfc_action_cable_from_comment
|
||||||
# Context: Comment
|
# Context: Comment
|
||||||
@ -17,12 +19,14 @@ module ActionCableHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def trigger_working_times_action_cable
|
def trigger_working_times_action_cable
|
||||||
# Context: Submission
|
Thread.new do
|
||||||
if study_group_id.present?
|
# Context: Submission
|
||||||
ActionCable.server.broadcast(
|
if study_group_id.present?
|
||||||
"la_exercises_#{exercise_id}_channel_study_group_#{study_group_id}",
|
ActionCable.server.broadcast(
|
||||||
type: :working_times,
|
"la_exercises_#{exercise_id}_channel_study_group_#{study_group_id}",
|
||||||
working_time_data: exercise.get_working_times_for_study_group(study_group_id, user))
|
type: :working_times,
|
||||||
|
working_time_data: exercise.get_working_times_for_study_group(study_group_id, user))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -198,7 +198,7 @@ class Exercise < ApplicationRecord
|
|||||||
def get_working_times_for_study_group(study_group_id, user = nil)
|
def get_working_times_for_study_group(study_group_id, user = nil)
|
||||||
user_progress = []
|
user_progress = []
|
||||||
additional_user_data = []
|
additional_user_data = []
|
||||||
max_bucket = 4
|
max_bucket = 100
|
||||||
maximum_score = self.maximum_score
|
maximum_score = self.maximum_score
|
||||||
|
|
||||||
if user.blank?
|
if user.blank?
|
||||||
@ -209,7 +209,7 @@ class Exercise < ApplicationRecord
|
|||||||
|
|
||||||
results = self.class.connection.execute(study_group_working_time_query(id, study_group_id, additional_filter)).each do |tuple|
|
results = self.class.connection.execute(study_group_working_time_query(id, study_group_id, additional_filter)).each do |tuple|
|
||||||
if tuple['score'] <= maximum_score
|
if tuple['score'] <= maximum_score
|
||||||
bucket = tuple['score'] / maximum_score * max_bucket
|
bucket = (tuple['score'] / maximum_score * max_bucket).round
|
||||||
else
|
else
|
||||||
bucket = max_bucket # maximum_score / maximum_score will always be 1
|
bucket = max_bucket # maximum_score / maximum_score will always be 1
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user