Skip to content

Instantly share code, notes, and snippets.

@jonstorer
Created December 20, 2012 15:51
Show Gist options
  • Save jonstorer/4346119 to your computer and use it in GitHub Desktop.
Save jonstorer/4346119 to your computer and use it in GitHub Desktop.
How much cash our members could cash out
class CountUpCash
COST_OF_TWENTY_FIVE_DOLLAR_GIFT_CARDS = 50000
COST_OF_TEN_DOLLAR_GIFT_CARDS = 20000
DEFAULT_QUERY = { :points.gte => 20000, :banned.in => [ false, nil ] }
attr_accessor :query, :total_number_of_twenty_five_dollar_gift_cards, :total_number_of_ten_dollar_gift_cards
def initialize(query = {})
@query = DEFAULT_QUERY.merge(query)
@total_number_of_twenty_five_dollar_gift_cards = 0
@total_number_of_ten_dollar_gift_cards = 0
end
def run!
mongoid_logger = Mongoid.logger
moped_logger = Moped.logger
Mongoid.logger = nil
Moped.logger = nil
# progress_bar = ProgressBar.new('Progress', Member.where(@query).count)
Member.where(query).each do | member |
points = member.redeemable_points
all_tens = ( 10 * points ) / COST_OF_TEN_DOLLAR_GIFT_CARDS
notfdgc = points / COST_OF_TWENTY_FIVE_DOLLAR_GIFT_CARDS
votfdgc = notfdgc * 25
notdgc = ( points - ( notfdgc * COST_OF_TWENTY_FIVE_DOLLAR_GIFT_CARDS ) ) / COST_OF_TEN_DOLLAR_GIFT_CARDS
votdgc = notdgc * 10
combo = votfdgc + votdgc
if all_tens > combo
number_of_twenty_five_dollar_gift_cards = 0
number_of_ten_dollar_gift_cards = points / COST_OF_TEN_DOLLAR_GIFT_CARDS
else
number_of_twenty_five_dollar_gift_cards = points / COST_OF_TWENTY_FIVE_DOLLAR_GIFT_CARDS
number_of_ten_dollar_gift_cards = ( points - number_of_twenty_five_dollar_gift_cards * COST_OF_TWENTY_FIVE_DOLLAR_GIFT_CARDS ) / COST_OF_TEN_DOLLAR_GIFT_CARDS
end
self.total_number_of_twenty_five_dollar_gift_cards += number_of_twenty_five_dollar_gift_cards
self.total_number_of_ten_dollar_gift_cards += number_of_ten_dollar_gift_cards
# progress_bar.inc
end
# progress_bar.finish
Mongoid.logger = mongoid_logger
Moped.logger = moped_logger
print "#{@total_number_of_twenty_five_dollar_gift_cards},"
print "#{@total_number_of_ten_dollar_gift_cards},"
puts "$#{@total_number_of_twenty_five_dollar_gift_cards * 25 + @total_number_of_ten_dollar_gift_cards * 10}"
end
end
puts "Days ago Range, Num $25 GCs, Num $10 GCs, $ Liable"
(1..60).step(1) do | n |
print "#{n - 1} - #{ n },"
CountUpCash.new({
:last_visited_at.lte => (n - 1).days.ago.utc.to_i,
:last_visited_at.gt => n.day.ago.utc.to_i
}).run!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment