Implement ranged user queries

This commit is contained in:
Maximilian Grundke
2018-04-25 13:58:40 +02:00
parent 9da3d98654
commit a0d46d223c
3 changed files with 25 additions and 0 deletions

View File

@ -187,4 +187,25 @@ module StatisticsHelper
]
end
def ranged_user_data(interval='year', from=DateTime.new(0), to=DateTime.now)
[
{
key: 'active',
name: t('statistics.entries.users.active'),
data: ExternalUser.joins(:submissions)
.where(submissions: {created_at: from..to})
.select("date_trunc('#{interval}', submissions.created_at) AS \"key\", count(distinct external_users.id) AS \"value\"")
.group('key').order('key')
},
{
key: 'submissions',
name: t('statistics.entries.exercises.submissions'),
data: Submission.where(created_at: from..to)
.select("date_trunc('#{interval}', created_at) AS \"key\", count(id) AS \"value\"")
.group('key').order('key'),
axis: 'right'
}
]
end
end