Incorporate feedback from PR review

This commit is contained in:
Sebastian Serth
2019-03-12 13:01:25 +01:00
parent 900bc896c9
commit d63469099b
3 changed files with 91 additions and 90 deletions

View File

@ -24,7 +24,8 @@ $.fn.scrollTo = function(selector) {
}, ANIMATION_DURATION);
};
$.fn.replaceWithPush = function(a) {
// Same as $.replaceWith, just returns the new element instead of the deleted one
$.fn.replaceWithAndReturnNewElement = function(a) {
const $a = $(a);
this.replaceWith($a);
return $a;

View File

@ -31,7 +31,7 @@ $(document).on('turbolinks:load', function() {
if ($row.length === 0) {
$row = $($('#posted_rfcs')[0].insertRow(0));
}
$row = $row.replaceWithPush(data.html);
$row = $row.replaceWithAndReturnNewElement(data.html);
$row.find('time').timeago();
$row.click(function () {
Turbolinks.visit($(this).data("href"));
@ -236,7 +236,7 @@ $(document).on('turbolinks:load', function() {
$('#no_chart_data').addClass("d-none");
transitionStacked();
// transitionGrouped();
// ToDo: Add button to switch using transitionGrouped();
buildDictionary(additional_user_data);
}

View File

@ -97,7 +97,7 @@ class Exercise < ApplicationRecord
submissions.user_type,
score,
created_at,
(created_at - lag(created_at) over (PARTITION BY submissions.user_id, exercise_id
(created_at - lag(created_at) over (PARTITION BY submissions.user_type, submissions.user_id, exercise_id
ORDER BY created_at)) AS working_time
FROM submissions
WHERE exercise_id = #{exercise_id} AND study_group_id = #{study_group_id} #{additional_filter}),
@ -106,7 +106,7 @@ class Exercise < ApplicationRecord
user_type,
score,
sum(CASE WHEN score IS NOT NULL THEN 1 ELSE 0 END)
over (ORDER BY user_type, user_id, created_at) AS change_in_score,
over (ORDER BY user_type, user_id, created_at ASC) AS change_in_score,
created_at,
CASE WHEN working_time >= #{StatisticsHelper::WORKING_TIME_DELTA_IN_SQL_INTERVAL} THEN '0' ELSE working_time END AS working_time_filtered
FROM working_time_between_submissions
@ -124,7 +124,7 @@ class Exercise < ApplicationRecord
SELECT *
FROM working_times_with_score_expanded
UNION ALL
-- Duplicate last row per score and make it unique by setting another created_at timestamp.
-- Duplicate last row per user and score and make it unique by setting another created_at timestamp.
-- In addition, the working time is set to zero in order to prevent getting a wrong time.
-- This duplication is needed, as we will shift the scores and working times by one and need to ensure not to loose any information.
SELECT DISTINCT ON (user_type, user_id, corrected_score) user_id,
@ -148,7 +148,7 @@ class Exercise < ApplicationRecord
user_type,
shifted_score AS score,
MIN(created_at) AS start_time,
SUM(working_time_filtered) AS working_time,
SUM(working_time_filtered) AS working_time_per_score,
SUM(SUM(working_time_filtered)) over (PARTITION BY user_type, user_id) AS total_working_time
FROM working_times_with_score_not_null_and_shifted
GROUP BY user_id, user_type, score
@ -159,7 +159,7 @@ class Exercise < ApplicationRecord
user_type,
score,
start_time,
working_time,
working_time_per_score,
total_working_time
FROM working_times_to_be_sorted)
SELECT index,
@ -168,7 +168,7 @@ class Exercise < ApplicationRecord
name,
score,
start_time,
working_time,
working_time_per_score,
total_working_time
FROM working_times_with_index
JOIN external_users ON user_type = 'ExternalUser' AND user_id = external_users.id
@ -179,11 +179,11 @@ class Exercise < ApplicationRecord
name,
score,
start_time,
working_time,
working_time_per_score,
total_working_time
FROM working_times_with_index
JOIN internal_users ON user_type = 'InternalUser' AND user_id = internal_users.id
ORDER BY index, score ASC LIMIT 200;
ORDER BY index, score ASC;
"""
end
@ -210,7 +210,7 @@ class Exercise < ApplicationRecord
additional_user_data[bucket] ||= []
additional_user_data[max_bucket + 1] ||= []
user_progress[bucket][tuple['index']] = tuple["working_time"]
user_progress[bucket][tuple['index']] = tuple["working_time_per_score"]
additional_user_data[bucket][tuple['index']] = {start_time: tuple["start_time"], score: tuple["score"]}
additional_user_data[max_bucket + 1][tuple['index']] = {id: tuple['user_id'], type: tuple['user_type'], name: tuple['name']}
end