Skip to content

Commit

Permalink
Display funding platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Aug 22, 2024
1 parent aa11054 commit c95d46c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/models/allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def export_to_csv
end

def group_projects_by_funding_platform
# TODO
project_allocations.where('amount_cents >= 1').order('amount_cents desc').includes(:project)
.group_by { |pa| pa.project.preferred_funding_platform }
.transform_values { |pas| pas.sum(&:amount_cents) }
.sort_by { |platform, amount| -amount }
end
end
13 changes: 12 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def sync_issues
end

def funding_links
(package_funding_links + repo_funding_links + owner_funding_links + readme_funding_links).uniq
@funding_links ||= (package_funding_links + repo_funding_links + owner_funding_links + readme_funding_links).uniq
end

def package_funding_links
Expand Down Expand Up @@ -658,12 +658,23 @@ def funding_domains
'communitybridge.org', 'tidelift.com', 'buymeacoffee.com', 'paypal.com', 'paypal.me','givebutter.com', 'polar.sh']
end

def unique_funding_domains
funding_links.map{|u| URI.parse(u).host.gsub(/^www\./, '').gsub('paypal.me', 'paypal.com') rescue nil }.compact.uniq
end

def preferred_funding_platform
# pick the first funding platform from unique_funding_domains, preferring opencollective.com, otherwise prefer github.com if it's there
unique_funding_domains.find{|d| d == 'opencollective.com' } || unique_funding_domains.find{|d| d == 'github.com' } || unique_funding_domains.first || 'Unknown'
end

def readme_funding_links
urls = readme_urls.select{|u| funding_domains.any?{|d| u.include?(d) } || u.include?('github.com/sponsors') }.reject{|u| ['.svg', '.png'].include? File.extname(URI.parse(u).path) }
# remove anchors
urls = urls.map{|u| u.gsub(/#.*$/, '') }.uniq
# remove sponsor/9/website from open collective urls
urls = urls.map{|u| u.gsub(/\/sponsor\/\d+\/website$/, '') }.uniq
# remove backer/9/website from open collective urls
urls = urls.map{|u| u.gsub(/\/backer\/\d+\/website$/, '') }.uniq
end


Expand Down
21 changes: 21 additions & 0 deletions app/views/allocations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
Projects: <%= @project_allocations.count %>
</p>

<table class="table w-auto">
<thead>
<tr>
<th>Platform</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<% @allocation.group_projects_by_funding_platform.each do |platform, total_cents| %>
<tr>
<td><%= platform %></td>
<td><%= number_to_currency(total_cents/100.0) %></td>
</tr>
<% end %>
</tbody>
</table>

<table class="table">
<thead>
<tr>
Expand All @@ -16,6 +33,7 @@
<th>Dependent Repos</th>
<th>Dependent Pkgs</th>
<th>Stars</th>
<th>Platform</th>
</tr>
</tr>
</thead>
Expand All @@ -29,6 +47,9 @@
<td><%= number_with_delimiter project_allocation.project.dependent_repos_count %></td>
<td><%= number_with_delimiter project_allocation.project.dependent_packages_count %></td>
<td><%= number_with_delimiter project_allocation.project.stars %></td>
<td title='<%= project_allocation.project.funding_links.join(', ') %>'>
<%= project_allocation.project.preferred_funding_platform %>
</td>
</tr>
<% end %>
</tbody>
Expand Down

0 comments on commit c95d46c

Please sign in to comment.