Implement basic statistics
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
74
app/helpers/statistics_helper.rb
Normal file
74
app/helpers/statistics_helper.rb
Normal 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
|
@@ -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 '')
|
||||
|
Reference in New Issue
Block a user