modify concern
This commit is contained in:
parent
6ed339e7aa
commit
3555c9696a
1 changed files with 18 additions and 0 deletions
|
@ -27,4 +27,22 @@ module ProcedureStatsConcern
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stats_termines_by_week
|
||||||
|
Rails.cache.fetch("#{cache_key_with_version}/stats_termines_by_week", expires_in: 12.hours) do
|
||||||
|
now = Time.zone.now
|
||||||
|
chart_data = dossiers.joins(:traitements)
|
||||||
|
.state_termine
|
||||||
|
.where(traitements: { processed_at: (now.beginning_of_week - 6.months)..now.end_of_week })
|
||||||
|
|
||||||
|
dossier_state_values = chart_data.pluck(:state).sort.uniq
|
||||||
|
|
||||||
|
# rubocop:disable Style/HashTransformValues
|
||||||
|
dossier_state_values
|
||||||
|
.map do |state|
|
||||||
|
{ name: state, data: chart_data.where(state: state).group_by_week { |dossier| dossier.traitements.first.processed_at }.map { |k, v| [k, v.count] }.to_h }
|
||||||
|
# rubocop:enable Style/HashTransformValues
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue