Module: Gitlang::GithubStats
- Included in:
- Organization
- Defined in:
- lib/gitlang/github_stats.rb
Overview
Module for extracting useful Github statistics.
Instance Method Summary collapse
-
#absolute_usage_per_language(usage_per_repo) ⇒ Object
Creates a hash with the absolute usage for each language.
-
#relative_usage_per_language(usage_per_repo) ⇒ Object
Creates a hash with the relative usage for each language.
Instance Method Details
#absolute_usage_per_language(usage_per_repo) ⇒ Object
Creates a hash with the absolute usage for each language.
13 14 15 16 17 |
# File 'lib/gitlang/github_stats.rb', line 13 def absolute_usage_per_language(usage_per_repo) usage_per_repo.each_with_object(Hash.new(0)) do |repository, total| repository.each { |language, usage| total[language] += usage } end end |
#relative_usage_per_language(usage_per_repo) ⇒ Object
Creates a hash with the relative usage for each language.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gitlang/github_stats.rb', line 25 def relative_usage_per_language(usage_per_repo) absolute_usage = absolute_usage_per_language(usage_per_repo) total = absolute_usage.values.inject(&:+) results_pre_lare = absolute_usage.merge(absolute_usage) do |_, usage| (BigDecimal.new(usage) / total * 100) end return results_pre_lare if results_pre_lare.empty? # Largest remainder method is used in order to avoid cases where the sum # of the relative usage is over or under 100%. # More info at https://en.wikipedia.org/wiki/Largest_remainder_method. results_after_lare = LareRound.round(results_pre_lare, 2) results_after_lare.merge(results_after_lare) { |_, usage| usage.to_f } end |