jipe_app/app/views/admin/petitions/stats.html.haml
2017-08-14 10:53:30 +02:00

167 lines
3.8 KiB
Plaintext

.qi_header
%h1
Pétitions
%span
stats pour la pétition :
=@petition.lang("fr").title
.qi_row
.qi_pannel.qi_plain.padding
.header
%h2 Evolution du nombre de signatures
%table.table
%tr
%th
Provenance
%th
Nombre de signataires
%th
Nombre de signataires avec adresse postale
%th
Nombre de signataires avec numéro de téléphone
-@petition.signators.group(:provenance_id).each do |prov|
%tr
%td
-if prov.provenance_id?
=prov.provenance_id
-else
Non spécifié
%td
=@petition.signators.where(:provenance_id => prov.provenance_id).count
%td
=@petition.signators.where(:provenance_id => prov.provenance_id).where("(address is not null and address != '')").count
%td
=@petition.signators.where(:provenance_id => prov.provenance_id).where("(phone is not null and phone != '')").count
-start_date = Time.parse("2016/04/20")
= @petition.signators.order("created_at ASC").first.created_at
-start_date = @petition.signators.order("created_at ASC").first.created_at
-stop_date = Time.now.end_of_day
%p
Nombre de jours :
=nbr_jours = (stop_date.to_date - start_date.to_date).to_i
%p
Echelle de temps :
-if nbr_jours > 400
1 mois
-step = "1month"
-elsif nbr_jours > 100
2 semaine
-step = "2week"
-elsif nbr_jours > 90
1 semaine
-step = "1week"
-elsif nbr_jours > 60
2 jour
-step = "2day"
-elsif nbr_jours > 10
1 jour
-step = "1day"
-elsif nbr_jours > 0
1 heure
-step = "1hour"
<div>
<canvas id="ca_stats" height="200" width="600"></canvas>
</div>
-labels = []
-datas_ht = []
-if step == "1hour"
-date = start_date - 1.hour
-elsif step == "1day"
-date = start_date.yesterday.end_of_day
-elsif step == "2day"
-date = start_date.yesterday.end_of_day
-elsif step == "1week"
-date = start_date.prev_week.end_of_week
-elsif step == "2week"
-date = start_date.prev_week.end_of_week
-elsif step == "1month"
-date = start_date.prev_month.end_of_month
-i = 0
-while date <= stop_date and i < 2000
-i = i + 1
-labels << l(date, :format => "%a %d %b")
-ht = @petition.signators.where("created_at >= ? and created_at <= ?",start_date,date).count
-datas_ht << ht
-#date = date.tomorrow.end_of_day
-#date = date.end_of_week.end_of_day
-#date = date.end_of_month.end_of_day
-#date = date.end_of_month.end_of_day
-if step == "1hour"
-date = date + 1.hour
-elsif step == "1day"
-date = date.tomorrow.end_of_day
-elsif step == "2day"
-date = date.tomorrow.tomorrow.end_of_day
-elsif step == "1week"
-date = date.next_week.end_of_week.end_of_day
-elsif step == "2week"
-date = date.next_week.next_week.end_of_week.end_of_day
-elsif step == "1month"
-date = date.next_month.end_of_month.end_of_day
<script>
var lineChartData2 = {
=raw"labels : #{labels.to_json},"
datasets : [
{
label: "Nbr signatures",
fillColor : "rgba(22,156,67,0.1)",
strokeColor : "rgba(22,156,67,1)",
pointColor : "rgba(22,156,67,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(220,220,220,1)",
=raw"data : #{datas_ht.to_json}"
}
]
}
var ctx2 = document.getElementById("ca_stats").getContext("2d");
new Chart(ctx2).Line(lineChartData2, {
responsive: true,
bezierCurve : false
});
</script>