changed way working times are returned. builtin protection if exercise is new
This commit is contained in:
@ -167,8 +167,8 @@ class ExercisesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def working_times
|
def working_times
|
||||||
working_time_accumulated = Time.parse(@exercise.average_working_time_for_only(current_user.id) || "00:00:00").seconds_since_midnight
|
working_time_accumulated = @exercise.accumulated_working_time_for_only(current_user.id)
|
||||||
working_time_avg = Time.parse(@exercise.average_working_time || "00:00:00").seconds_since_midnight
|
working_time_avg = @exercise.get_quantiles([0.75]).first
|
||||||
render(json: {working_time_avg: working_time_avg, working_time_accumulated: working_time_accumulated})
|
render(json: {working_time_avg: working_time_avg, working_time_accumulated: working_time_accumulated})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -96,7 +96,12 @@ class Exercise < ActiveRecord::Base
|
|||||||
GROUP BY user_id
|
GROUP BY user_id
|
||||||
) AS foo
|
) AS foo
|
||||||
""")
|
""")
|
||||||
quantiles.each_with_index.map{|q,i| Time.parse(result[i]["unnest"]).seconds_since_midnight}
|
if result.count > 0
|
||||||
|
quantiles.each_with_index.map{|q,i| Time.parse(result[i]["unnest"]).seconds_since_midnight}
|
||||||
|
else
|
||||||
|
quantiles.map{|q| 0}
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def retrieve_working_time_statistics
|
def retrieve_working_time_statistics
|
||||||
@ -121,8 +126,8 @@ class Exercise < ActiveRecord::Base
|
|||||||
@working_time_statistics[user_id]["working_time"]
|
@working_time_statistics[user_id]["working_time"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def average_working_time_for_only(user_id)
|
def accumulated_working_time_for_only(user_id)
|
||||||
self.class.connection.execute("""
|
Time.parse(self.class.connection.execute("""
|
||||||
SELECT sum(working_time_new) AS working_time
|
SELECT sum(working_time_new) AS working_time
|
||||||
FROM
|
FROM
|
||||||
(SELECT CASE WHEN working_time >= '0:30:00' THEN '0' ELSE working_time END AS working_time_new
|
(SELECT CASE WHEN working_time >= '0:30:00' THEN '0' ELSE working_time END AS working_time_new
|
||||||
@ -132,7 +137,7 @@ class Exercise < ActiveRecord::Base
|
|||||||
ORDER BY created_at)) AS working_time
|
ORDER BY created_at)) AS working_time
|
||||||
FROM submissions
|
FROM submissions
|
||||||
WHERE exercise_id=#{id} and user_id=#{user_id} and user_type='ExternalUser') AS foo) AS bar
|
WHERE exercise_id=#{id} and user_id=#{user_id} and user_type='ExternalUser') AS foo) AS bar
|
||||||
""").first["working_time"]
|
""").first["working_time"] || "00:00:00").seconds_since_midnight
|
||||||
end
|
end
|
||||||
|
|
||||||
def duplicate(attributes = {})
|
def duplicate(attributes = {})
|
||||||
|
@ -144,7 +144,7 @@ class ProxyExercise < ActiveRecord::Base
|
|||||||
return 0.0
|
return 0.0
|
||||||
end
|
end
|
||||||
points_ratio_index = ((scoring_matrix.size - 1) * points_ratio).to_i
|
points_ratio_index = ((scoring_matrix.size - 1) * points_ratio).to_i
|
||||||
working_time_user = Time.parse(ex.average_working_time_for_only(user.id) || "00:00:00").seconds_since_midnight
|
working_time_user = ex.accumulated_working_time_for_only(user.id)
|
||||||
quantiles_working_time = ex.get_quantiles(scoring_matrix_quantiles)
|
quantiles_working_time = ex.get_quantiles(scoring_matrix_quantiles)
|
||||||
quantile_index = quantiles_working_time.size
|
quantile_index = quantiles_working_time.size
|
||||||
quantiles_working_time.each_with_index do |quantile_time, i|
|
quantiles_working_time.each_with_index do |quantile_time, i|
|
||||||
|
Reference in New Issue
Block a user