Skip to content

Instantly share code, notes, and snippets.

@enthal
Created May 31, 2012 22:31
Show Gist options
  • Select an option

  • Save enthal/2846798 to your computer and use it in GitHub Desktop.

Select an option

Save enthal/2846798 to your computer and use it in GitHub Desktop.

Revisions

  1. enthal created this gist May 31, 2012.
    16 changes: 16 additions & 0 deletions mem_spons_mr.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@


    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