Implement basic statistics

This commit is contained in:
Maximilian Grundke
2018-03-13 18:38:54 +01:00
parent da0859d483
commit 68d3fd174e
6 changed files with 116 additions and 3 deletions

View File

@ -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;
}
}
}

View File

@ -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

View File

@ -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

View File

@ -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 '')

View File

@ -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"

View File

@ -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"