Class: Statistics
- Inherits:
-
Object
- Object
- Statistics
- Defined in:
- worklog/statistics.rb
Overview
Module for calculating statistics for the work log.
Instance Method Summary collapse
-
#calculate ⇒ STATS
Calculate statistics for the work log for all days.
-
#initialize(config) ⇒ Statistics
constructor
Initialize the Statistics class.
Constructor Details
#initialize(config) ⇒ Statistics
Initialize the Statistics class.
11 12 13 14 |
# File 'worklog/statistics.rb', line 11 def initialize(config) @config = config @storage = Storage.new(config) end |
Instance Method Details
#calculate ⇒ STATS
Calculate statistics for the work log for all days.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'worklog/statistics.rb', line 18 def calculate all_entries = @storage.all_days return STATS.new(0, 0, 0, 0, Date.today, Date.today) if all_entries.empty? total_days = all_entries.length total_entries = all_entries.sum { |entry| entry.entries.length } total_epics = all_entries.sum { |entry| entry.entries.select { |item| item.epic? }.length } avg_entries = total_entries.to_f / total_days min_day = all_entries.min_by { |entry| entry.date }.date max_day = all_entries.max_by { |entry| entry.date }.date STATS.new( total_days, total_entries, total_epics, avg_entries, min_day, max_day ) end |