From 413ec9f95600e1547ef38fed64a455e6acf2beea Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 8 May 2020 11:35:11 +0200 Subject: [PATCH] Show up to three submissions for teachers and add overview to table --- app/controllers/exercises_controller.rb | 8 +++++--- app/models/submission.rb | 2 +- .../exercises/external_users/statistics.html.slim | 2 +- app/views/exercises/statistics.html.slim | 12 ++++++++++-- app/views/external_users/statistics.html.slim | 12 ++++++++++-- config/locales/de.yml | 4 +++- config/locales/en.yml | 4 +++- 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index b2242a01..3ffc2221 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -418,9 +418,11 @@ class ExercisesController < ApplicationController @working_times_until.push((format_time_difference(@deltas[0..index].inject(:+)) if index > 0)) end else - latest_submissions = Submission.where(user: @external_user, exercise_id: @exercise.id).in_study_group_of(current_user).final.latest - relevant_submissions = latest_submissions.before_deadline.or(latest_submissions.within_grace_period).or(latest_submissions.after_late_deadline) - @submissions = relevant_submissions.sort_by(&:created_at) + final_submissions = Submission.where(user: @external_user, exercise_id: @exercise.id).in_study_group_of(current_user).final + @submissions = [] + @submissions.push final_submissions.before_deadline.latest + @submissions.push final_submissions.within_grace_period.latest + @submissions.push final_submissions.after_late_deadline.latest @all_events = @submissions end render 'exercises/external_users/statistics' diff --git a/app/models/submission.rb b/app/models/submission.rb index dc0f2eae..c96e947e 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -27,7 +27,7 @@ class Submission < ApplicationRecord scope :within_grace_period, -> { joins(:exercise).where('(submissions.updated_at > exercises.submission_deadline) AND (submissions.updated_at <= exercises.late_submission_deadline OR exercises.late_submission_deadline IS NULL)') } scope :after_late_deadline, -> { joins(:exercise).where('submissions.updated_at > exercises.late_submission_deadline') } - scope :latest, -> { order(updated_at: :desc).limit(1) } + scope :latest, -> { order(updated_at: :desc).first } scope :in_study_group_of, ->(user) { where(study_group_id: user.study_groups) unless user.admin? } diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index 61ac33b0..d09c2fef 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -43,7 +43,7 @@ h1 = "#{@exercise} (external user #{link_to_if(policy(@external_user).show?, @ex th.header = t('.time_difference') if policy(@exercise).detailed_statistics? tbody - @all_events.each_with_index do |this, index| - - highlight = (index > 0 and @deltas[index] == 0 and this.created_at.to_s != @all_events[index - 1].created_at.to_s) + - highlight = (index > 0 and @deltas.present? and @deltas[index] == 0 and this.created_at.to_s != @all_events[index - 1].created_at.to_s) - row_classes = '' - row_classes += ' highlight' if highlight - row_classes += ' before_deadline' if this.is_a?(Submission) && this.before_deadline? diff --git a/app/views/exercises/statistics.html.slim b/app/views/exercises/statistics.html.slim index 2f80ee7e..4422d4f1 100644 --- a/app/views/exercises/statistics.html.slim +++ b/app/views/exercises/statistics.html.slim @@ -42,14 +42,15 @@ h1 = @exercise - submissions = Submission.where(user: @exercise.send(symbol).distinct, exercise: @exercise).in_study_group_of(current_user) - if !policy(@exercise).detailed_statistics? - submissions = submissions.final - - any_viewable_submission = submissions.first - - if any_viewable_submission + - latest_submission = submissions.latest + - if latest_submission .table-responsive table.table.table-striped.sortable thead tr th.header = t('.user') th.header = t('.score') + th.header = t('.deadline') th.header = t('.runs') if policy(@exercise).detailed_statistics? th.header = t('.worktime') if policy(@exercise).detailed_statistics? tbody @@ -60,5 +61,12 @@ h1 = @exercise tr td = link_to_if symbol==:external_users && policy(user).statistics?, label, {controller: "exercises", action: "statistics", external_user_id: user.id, id: @exercise.id} td = us['maximum_score'] or 0 + td.align-middle + - if latest_submission.before_deadline? + .unit-test-result.positive-result.before_deadline + - elsif latest_submission.within_grace_period? + .unit-test-result.unknown-result.within_grace_period + - elsif latest_submission.after_late_deadline? + .unit-test-result.negative-result.after_late_deadline td = us['runs'] if policy(@exercise).detailed_statistics? td = @exercise.average_working_time_for(user.id) or 0 if policy(@exercise).detailed_statistics? diff --git a/app/views/external_users/statistics.html.slim b/app/views/external_users/statistics.html.slim index a7e78887..00dcab63 100644 --- a/app/views/external_users/statistics.html.slim +++ b/app/views/external_users/statistics.html.slim @@ -4,15 +4,16 @@ h1 = t('.title') - exercises = Exercise.where(id: submissions.joins(:exercise).group(:exercise_id).select(:exercise_id).distinct) - if !policy(exercises.first).detailed_statistics? - submissions = submissions.final -- any_viewable_submission = submissions.first +- latest_viewable_submission = submissions.latest -- if any_viewable_submission && policy(any_viewable_submission).show_study_group? +- if latest_viewable_submission && policy(latest_viewable_submission).show_study_group? .table-responsive table.table.table-striped.sortable thead tr th.header = t('.exercise') th.header = t('.score') + th.header = t('.deadline') th.header = t('.runs') if policy(exercises.first).detailed_statistics? th.header = t('.worktime') if policy(exercises.first).detailed_statistics? tbody @@ -24,6 +25,13 @@ h1 = t('.title') tr td = link_to exercise, controller: "exercises", action: "statistics", external_user_id: @user.id, id: exercise.id td = stats["maximum_score"] or 0 + td.align-middle + - if latest_viewable_submission.before_deadline? + .unit-test-result.positive-result.before_deadline + - elsif latest_viewable_submission.within_grace_period? + .unit-test-result.unknown-result.within_grace_period + - elsif latest_viewable_submission.after_late_deadline? + .unit-test-result.negative-result.after_late_deadline td = stats["runs"] or 0 if policy(exercises.first).detailed_statistics? td = stats["working_time"] or 0 if policy(exercises.first).detailed_statistics? - else diff --git a/config/locales/de.yml b/config/locales/de.yml index 5d5ab495..9aefa613 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -414,6 +414,7 @@ de: users: '%{count} verschiedene Nutzer' user: Nutzer score: Maximale Punktzahl + deadline: Abgabefrist runs: Versuche worktime: Arbeitszeit average_worktime: Durchschnittliche Arbeitszeit @@ -434,7 +435,7 @@ de: external_users: statistics: no_data_available: Keine Daten verfügbar oder fehlende Berechtigungen. - time: Zeit + time: Zeit (UTC) cause: Grund score: Punktzahl tests: Unit Tests @@ -453,6 +454,7 @@ de: title: Statistiken für Externe Benutzer exercise: Übung score: Maximale Punktzahl + deadline: Abgabefrist runs: Abgaben worktime: Arbeitszeit show: diff --git a/config/locales/en.yml b/config/locales/en.yml index dd8edc97..ca7fd39e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -414,6 +414,7 @@ en: users: '%{count} distinct users' user: User score: Maximum Score + deadline: Deadline runs: Runs worktime: Working Time average_worktime: Average Working Time @@ -434,7 +435,7 @@ en: external_users: statistics: no_data_available: No data available or insufficient permissions - time: Time + time: Time (UTC) cause: Cause score: Score tests: Unit Test Results @@ -453,6 +454,7 @@ en: title: External User Statistics exercise: Exercise score: Maximum Score + deadline: Deadline runs: Submissions worktime: Working Time show: