Skip to content

Commit

Permalink
Add issue charts data to collectives index page
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 17, 2024
1 parent 34accb4 commit eef7fc2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
53 changes: 52 additions & 1 deletion app/controllers/collectives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def charts_data

period = (params[:period].presence || 'month').to_sym

start_date = params[:start_date].presence || Transaction.order(:created_at).first.try(:created_at)
start_date = params[:start_date].presence || 2.years.ago
end_date = params[:end_date].presence || Date.today

scope = scope.created_after(start_date) if start_date.present?
Expand Down Expand Up @@ -149,6 +149,57 @@ def issue_chart_data
render json: data
end

def issue_charts_data
scope = Issue.all

period = (params[:period].presence || 'month').to_sym

start_date = params[:start_date].presence || 2.year.ago
end_date = params[:end_date].presence || Date.today

scope = scope.created_after(start_date) if start_date.present?
scope = scope.created_before(end_date) if end_date.present?

if params[:exclude_bots] == 'true'
scope = scope.human
end

if params[:only_bots] == 'true'
scope = scope.bot
end

case params[:chart]
when 'issues_opened'
data = scope.issue.group_by_period(period, :created_at).count
when 'issues_closed'
data = scope.issue.closed.group_by_period(period, :closed_at).count
when 'issue_authors'
data = scope.issue.group_by_period(period, :created_at).distinct.count(:user)
when 'issue_average_time_to_close'
data = scope.issue.closed.group_by_period(period, :closed_at).average(:time_to_close)
data.update(data){ |_,v| v.to_f.seconds.in_days.to_i }
when 'pull_requests_opened'
data = scope.pull_request.group_by_period(period, :created_at).count
when 'pull_requests_closed'
data = scope.pull_request.group_by_period(period, :closed_at).count
when 'pull_requests_merged'
data = scope.pull_request.merged.group_by_period(period, :merged_at).count
when 'pull_requests_not_merged'
data = scope.pull_request.not_merged.group_by_period(period, :closed_at).count
when 'pull_request_authors'
data = scope.pull_request.group_by_period(period, :created_at).distinct.count(:user)
when 'pull_request_average_time_to_close'
data = scope.pull_request.closed.group_by_period(period, :closed_at).average(:time_to_close)
data.update(data){ |_,v| v.to_f.seconds.in_days.to_i }
when 'pull_request_average_time_to_merge'
data = scope.pull_request.merged.group_by_period(period, :merged_at).average(:time_to_close)
data.update(data){ |_,v| v.to_f.seconds.in_days.to_i }
end

render json: data
end


def problems
# collectives with no projects
# collectives with no open source licenses
Expand Down
4 changes: 4 additions & 0 deletions app/views/collectives/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<%= line_chart charts_data_collectives_path(chart: 'donations_and_expenses') %>
<%= line_chart charts_data_collectives_path(chart: 'unique_donors_and_spenders') %>

<%= line_chart issue_charts_data_collectives_path(chart: 'issues_opened'), title: 'Issues Opened' %>
<%= line_chart issue_charts_data_collectives_path(chart: 'issue_authors'), title: 'Issue Authors' %>
<%= line_chart issue_charts_data_collectives_path(chart: 'pull_request_average_time_to_merge'), title: 'Average time to merge pull requests' %>

<div class="row my-5">

<%= render @collectives %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
end
collection do
get :charts_data
get :issue_charts_data
get :problems
end
end
Expand Down

0 comments on commit eef7fc2

Please sign in to comment.