Offer aggregated RfC counts via API

This commit is contained in:
Maximilian Grundke
2018-04-24 14:08:07 +02:00
parent 4936d5d372
commit 4177e40edc
2 changed files with 45 additions and 1 deletions

View File

@ -29,11 +29,20 @@ class StatisticsController < ApplicationController
def rfc_activity
respond_to do |format|
format.json { render(json: rfc_activity_live_data) }
format.json { render(json: rfc_activity_data) }
end
end
def rfc_activity_history
respond_to do |format|
format.html { render 'rfc_activity_history' }
format.json do
range = params[:range] || 'year'
from = DateTime.strptime(params[:from], '%Y') rescue DateTime.new(0)
to = DateTime.strptime(params[:to], '%Y') rescue DateTime.now
render(json: ranged_rfc_data(range, from, to))
end
end
end
def authorize!

View File

@ -152,4 +152,39 @@ module StatisticsHelper
]
end
def ranged_rfc_data(range='year', from=DateTime.new(0), to=DateTime.now)
[
{
key: 'rfcs',
name: t('activerecord.models.request_for_comment.other'),
data: RequestForComment.in_range(from, to)
.select("date_trunc('#{range}', created_at) AS \"range\", count(id)")
.group('range').order('range')
},
{
key: 'rfcs_solved',
name: t('statistics.entries.request_for_comments.percent_solved'),
data: RequestForComment.in_range(from, to)
.where(solved: true)
.select("date_trunc('#{range}', created_at) AS \"range\", count(id)")
.group('range').order('range')
},
{
key: 'rfcs_soft_solved',
name: t('statistics.entries.request_for_comments.percent_soft_solved'),
data: RequestForComment.in_range(from, to).unsolved
.where(full_score_reached: true)
.select("date_trunc('#{range}', created_at) AS \"range\", count(id)")
.group('range').order('range')
},
{
key: 'rfcs_unsolved',
name: t('statistics.entries.request_for_comments.percent_unsolved'),
data: RequestForComment.in_range(from, to).unsolved
.select("date_trunc('#{range}', created_at) AS \"range\", count(id)")
.group('range').order('range')
}
]
end
end