Skip to content

Commit

Permalink
Increase other sponsor all_time by last_payment every month (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Mar 19, 2024
1 parent e4083a9 commit 5150646
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scripts/merge.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,31 @@ end
all_sponsors_map = Hash(UInt64, Sponsor).new
overrides = Array(Sponsor).new

update_other_sponsor_totals = ENV["UPDATE_OTHER_SPONSOR_TOTALS"]? == "1" || Time.utc.day == 1 # only do this on the first day of the month

SPONSOR_DATA = begin
csv = CSV.new(File.read("#{__DIR__}/../_data/sponsors.csv"), headers: true)
hash = Hash(UInt64, Int32).new
csv.each do |row|
hash[Sponsor.id(row["name"], row["url"])] = row["all_time"].lchop("$").lchop("").gsub(",", nil).to_i
end
hash
end

%w(opencollective.json bountysource.json others.json).each do |filename|
File.open("#{__DIR__}/../_data/#{filename}") do |file|
sponsors = Array(Sponsor).from_json(file)
sponsors, overrides = sponsors.partition(&.overrides.nil?) if filename == "others.json"

if filename == "others.json"
sponsors, overrides = sponsors.partition(&.overrides.nil?)
if update_other_sponsor_totals
sponsors.map! do |sponsor|
sponsor.all_time = SPONSOR_DATA[sponsor.id] + sponsor.last_payment
sponsor
end
end
end

sponsors.each do |sponsor|
prev_sponsor = all_sponsors_map[sponsor.id]?
all_sponsors_map[sponsor.id] = prev_sponsor ? sponsor.merge(prev_sponsor) : sponsor
Expand Down
4 changes: 4 additions & 0 deletions scripts/sponsors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ record Sponsor, name : String, url : String?, logo : String?, last_payment : Flo
property time_last_payment : Time?

def id : UInt64
self.class.id(name, url)
end

def self.id(name : String, url : String?)
name.hash ^ (url || "").hash
end

Expand Down

0 comments on commit 5150646

Please sign in to comment.