Skip to content

Instantly share code, notes, and snippets.

@enthal
Created May 31, 2012 22:31
Show Gist options
  • Save enthal/2846798 to your computer and use it in GitHub Desktop.
Save enthal/2846798 to your computer and use it in GitHub Desktop.
def mr
# total_sponsor_amount = sum{|d| d.amount * dollars_per_locale_currency_unit(d.locale)}
reduce = {
usd_per_could_sponsor: ->(d){d.usd / d.could_count},
usd_per_did_sponsor: ->(d){d.usd / d.did_count},
}
map = {
usd: where(->(d){d.type == :did_member_sponsor}, sum{|d| d.amount * dollars_per_locale_currency_unit(d.locale)}),
could_count: count{|d| d.type == :could_member_sponsor},
did_count: count{|d| d.type == :did_member_sponsor}
}
# :usd_per_did_sponsor, {sum{|d| d.amount * dollars_per_locale_currency_unit(d.locale)} / count{|d| d.type == :did_member_sponsor}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment