Add a graph showing the user satisfaction

This commit is contained in:
gregoirenovel 2018-08-24 17:57:04 +02:00
parent c6a839cd64
commit b158a92493
2 changed files with 41 additions and 0 deletions

View file

@ -12,6 +12,7 @@ class StatsController < ApplicationController
@procedures_count = procedures.count
@dossiers_count = dossiers.count
@satisfaction_usagers = satisfaction_usagers
@dossiers_states = dossiers_states
@procedures_cumulative = cumulative_hash(procedures, :published_at)
@ -86,6 +87,37 @@ class StatsController < ApplicationController
}
end
def satisfaction_usagers
legend = {
"0" => "Mécontents",
"1" => "Neutres",
"2" => "Satisfaits"
}
totals = Feedback.where(created_at: 5.weeks.ago..Time.now).group_by_week(:created_at).count
(0..2).map do |mark|
data = Feedback
.where(created_at: 5.weeks.ago..Time.now, mark: mark)
.group_by_week(:created_at)
.count
.map do |week, count|
total = totals[week]
if total > 0
[week, (count.to_f / total).round(2)]
else
0
end
end.to_h
{
name: legend[mark.to_s],
data: data
}
end
end
def cloned_from_library_procedures_ratio
[3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |date|
min_date = date.beginning_of_week

View file

@ -15,6 +15,15 @@
%span.big-number-card-number
= number_with_delimiter(@dossiers_count)
.stat-card.stat-card-half.pull-left
%span.stat-card-title
Satisfaction usager
.chart-container
.chart
= line_chart @satisfaction_usagers,
colors: ["#F28900", "rgba(161, 0, 5, 0.9)", "#15AD70"]
.stat-card.stat-card-half.pull-left
%span.stat-card-title
Répartition des dossiers