Module: Hubstats::MetricsHelper

Defined in:
app/helpers/hubstats/metrics_helper.rb

Instance Method Summary collapse

Instance Method Details

#dashboardObject

Public - Formats statistics for all repos/users/teams of Hubstats

Returns - all of the stats in a corresponding hash



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/hubstats/metrics_helper.rb', line 88

def dashboard
  @stats_row_one = {
    developer_count: get_developer_count,
    pull_count: get_pull_count,
    pulls_per_dev: get_pulls_per_dev,
    deploy_count: get_deploy_count,
    net_additions: get_net_additions
  }
  @stats_row_two = {
    reviewer_count: get_reviewer_count,
    comment_count: get_comment_count,
    comments_per_rev: get_comments_per_rev,
    avg_additions: get_avg_additions,
    avg_deletions: get_avg_deletions
  }
end

#get_avg_additionsObject

Public - Gets the average number of additions from all pull requests within the start date and end date

Returns - the average additions



72
73
74
75
# File 'app/helpers/hubstats/metrics_helper.rb', line 72

def get_avg_additions
  num = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).average(:additions) || 0
  return num.round.to_i
end

#get_avg_deletionsObject

Public - Gets the average number of deletions from all pull requests within the start date and end date

Returns - the average deletions



80
81
82
83
# File 'app/helpers/hubstats/metrics_helper.rb', line 80

def get_avg_deletions
  num = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).average(:deletions) || 0
  return num.round.to_i
end

#get_comment_countObject

Public - Gets the number of comments within the start date and end date

Returns - the number of comments



35
36
37
# File 'app/helpers/hubstats/metrics_helper.rb', line 35

def get_comment_count
  Hubstats::Comment.created_in_date_range(@start_date, @end_date).count(:all)
end

#get_comments_per_revObject

Public - Gets the number of comments per reviewer within the start date and end date

Returns - the number of comments per reviewer



42
43
44
45
46
47
48
# File 'app/helpers/hubstats/metrics_helper.rb', line 42

def get_comments_per_rev
  if get_reviewer_count != 0
    comments_per_rev = (get_comment_count.to_f / get_reviewer_count.to_f).round(2)
  else
    comments_per_rev = 0
  end
end

#get_deploy_countObject

Public - Gets the number of deployments within the start date and end date

Returns - the number of deployments



21
22
23
# File 'app/helpers/hubstats/metrics_helper.rb', line 21

def get_deploy_count
  Hubstats::Deploy.deployed_in_date_range(@start_date, @end_date).count(:all)
end

#get_developer_countObject

Public - Gets the number of active developers within the start date and end date

Returns - the number of developers



7
8
9
# File 'app/helpers/hubstats/metrics_helper.rb', line 7

def get_developer_count
  Hubstats::User.count_active_developers(@start_date, @end_date)
end

#get_net_additionsObject

Public - Gets the total net additions from all pull requests within the start date and end date

Returns - the net additions



64
65
66
67
# File 'app/helpers/hubstats/metrics_helper.rb', line 64

def get_net_additions
  Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).sum(:additions).to_i - 
    Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).sum(:deletions).to_i
end

#get_pull_countObject

Public - Gets the number of pull requests within the start date and end date

Returns - the number of pull requests



28
29
30
# File 'app/helpers/hubstats/metrics_helper.rb', line 28

def get_pull_count
  Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).count(:all)
end

#get_pulls_per_devObject

Public - Gets the number of pull requests per developer within the start date and end date

Returns - the number of pull requests per developer



53
54
55
56
57
58
59
# File 'app/helpers/hubstats/metrics_helper.rb', line 53

def get_pulls_per_dev
  if get_developer_count != 0
    pulls_per_dev = (get_pull_count.to_f / get_developer_count.to_f).round(2)
  else
    pulls_per_dev = 0
  end
end

#get_reviewer_countObject

Public - Gets the number of active reviewers within the start date and end date

Returns - the number of reviewers



14
15
16
# File 'app/helpers/hubstats/metrics_helper.rb', line 14

def get_reviewer_count
  Hubstats::User.count_active_reviewers(@start_date, @end_date)
end