Created
October 1, 2014 05:47
-
-
Save shadabahmed/c2da1892f43da6a10e9e to your computer and use it in GitHub Desktop.
Aggrobot Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
{ | |
"region1": {month1: {avg_target: xxx, avg_actual: xxx} | |
month2: ......... | |
} | |
=end | |
month_grouping = Aggrobot.block do | |
hash do | |
group_by :month | |
select avg_target: avg(:target), avg_actual: avg(:actual) | |
group_labels {|x| Date.new(2014, x).strftime("%b")} | |
iterate | |
end | |
end | |
Aggrobot.start(PrimarySales) do | |
hash do | |
group_by :region_code | |
override name: :label | |
recurse month_grouping | |
end | |
end | |
month_labels = month_labels_for(3) | |
z = Aggrobot.block do | |
{ | |
months: list do | |
group_by :month, buckets: month_labels.keys, keep_empty: true | |
override name: :label | |
group_labels month_labels | |
select actual: round(sum(:actual)), target: round(sum(:target)) | |
default_values actual: 0, target: 0 | |
iterate | |
end | |
} | |
end | |
Aggrobot.start(PrimarySales, z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment