Skip to content

Instantly share code, notes, and snippets.

@shadabahmed
Created October 1, 2014 05:47
Show Gist options
  • Save shadabahmed/c2da1892f43da6a10e9e to your computer and use it in GitHub Desktop.
Save shadabahmed/c2da1892f43da6a10e9e to your computer and use it in GitHub Desktop.
Aggrobot Example
=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