dimanche 28 février 2016

Rails 4 - Group by date rage on month intervals

I'm trying to group my Events table my months and in range so i can present it in a chart (i'm using the chartKick gem). The Events have a start_date and a end_date so if a event starts in February and ends in February it will count as a February event, but if the Event starts in February and end in March it will count as a March Event. The format i desire is:

{"JAN"=>2, "FEB"=>3, "MAR"=>5, "APR"=>10, "MAY"=>5, "JUNE"=>0, "JULY"=>12, "AUG"=>4, "SEPT"=>17, "OCT"=>8, "NOV"=>0, "DEC"=>3}

Right now i'm using something very simple that doesn't do what i want:

<%= pie_chart Event.group(["DATE(created_at)"]).count %>

Can anyone help me getting the right query?

thanks

Aucun commentaire:

Enregistrer un commentaire