diff --git a/app/assets/stylesheets/statistics.css.scss b/app/assets/stylesheets/statistics.css.scss index c1c8d993..bf5e5c05 100644 --- a/app/assets/stylesheets/statistics.css.scss +++ b/app/assets/stylesheets/statistics.css.scss @@ -61,6 +61,10 @@ div.negative-result { ///////////////////////////////////////////////////////////////////////////////////////////// // StatisticsController: +#statistics-container { + margin-bottom: 40px; +} + .statistics-wrapper { display: grid; grid-template-columns: repeat(4, 1fr); @@ -81,7 +85,11 @@ div.negative-result { flex-grow: 1; font-size: 40px; vertical-align: middle; - line-height: 100px; + line-height: 50px; + } + + > .title { + height: 42px; } } } diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb index 66ffea02..a26d5670 100644 --- a/app/controllers/statistics_controller.rb +++ b/app/controllers/statistics_controller.rb @@ -1,4 +1,5 @@ class StatisticsController < ApplicationController + include StatisticsHelper def policy_class StatisticsPolicy @@ -6,6 +7,10 @@ class StatisticsController < ApplicationController def show authorize self + respond_to do |format| + format.html + format.json { render(json: statistics_data) } + end end end diff --git a/app/helpers/statistics_helper.rb b/app/helpers/statistics_helper.rb new file mode 100644 index 00000000..124ddf3d --- /dev/null +++ b/app/helpers/statistics_helper.rb @@ -0,0 +1,74 @@ +module StatisticsHelper + + def statistics_data + [ + { + key: 'users', + name: t('statistics.sections.users'), + entries: user_statistics + }, + { + key: 'exercises', + name: t('statistics.sections.exercises'), + entries: exercise_statistics + }, + { + key: 'request_for_comments', + name: t('statistics.sections.request_for_comments'), + entries: rfc_statistics + } + ] + end + + def user_statistics + [ + { + key: 'internal_users', + title: t('activerecord.models.internal_user.other'), + data: InternalUser.count + }, + { + key: 'external_users', + title: t('activerecord.models.external_user.other'), + data: ExternalUser.count + } + ] + end + + def exercise_statistics + [ + { + key: 'exercises', + title: t('activerecord.models.exercise.other'), + data: Exercise.count + }, + { + key: 'average_submissions', + title: t('statistics.entries.exercises.average_number_of_submissions'), + data: Submission.count / Exercise.count + } + ] + end + + def rfc_statistics + [ + { + key: 'rfcs', + title: t('activerecord.models.request_for_comment.other'), + data: RequestForComment.count + }, + { + key: 'percent_solved', + title: t('statistics.entries.request_for_comments.percent_solved'), + data: (100.0 / RequestForComment.count * RequestForComment.where(solved: true).count).round(2), + unit: '%' + }, + { + key: 'comments', + title: t('activerecord.models.comment.other'), + data: Comment.count + }, + ] + end + +end diff --git a/app/views/statistics/show.html.slim b/app/views/statistics/show.html.slim index c151cf29..e34f8933 100644 --- a/app/views/statistics/show.html.slim +++ b/app/views/statistics/show.html.slim @@ -1,3 +1,9 @@ -h1 = t('shared.statistics') -.statistics-wrapper +#statistics-container + - statistics_data.each do | section | + h2 = section[:name] + .statistics-wrapper + - section[:entries].each do | entry | + div + .title = entry[:title] + .data = entry[:data].to_s + (entry[:unit] or '') diff --git a/config/locales/de.yml b/config/locales/de.yml index 4db92696..9e8b180c 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -676,3 +676,13 @@ de: subscriptions: successfully_unsubscribed: "Ihr Abonnement für weitere Kommentare auf dieser Kommentaranfrage wurde erfolgreich beendet." subscription_not_existent: "Das Abonnement, von dem Sie sich abmelden wollen, existiert nicht." + statistics: + sections: + users: "Benutzer" + exercises: "Aufgaben" + request_for_comments: "Kommentaranfragen" + entries: + exercises: + average_number_of_submissions: "Durchschnittliche Zahl von Abgaben" + request_for_comments: + percent_solved: "Beantwortete Anfragen" diff --git a/config/locales/en.yml b/config/locales/en.yml index 1a7ef575..3dca3a02 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -676,3 +676,13 @@ en: subscriptions: successfully_unsubscribed: "You successfully unsubscribed from this Request for Comment" subscription_not_existent: "The subscription you want to unsubscribe from does not exist." + statistics: + sections: + users: "Users" + exercises: "Exercises" + request_for_comments: "Requests for Comment" + entries: + exercises: + average_number_of_submissions: "Average Number of Submissions" + request_for_comments: + percent_solved: "Solved Requests"