lib/tabs/metrics/task.rb in tabs-0.7.1 vs lib/tabs/metrics/task.rb in tabs-0.8.0

- old
+ new

@@ -4,10 +4,18 @@ include Tabs::Storage include Tabs::Helpers class UnstartedTaskMetricError < Exception; end + Stats = Struct.new( + :started_within_period, + :completed_within_period, + :started_and_completed_within_period, + :completion_rate, + :average_completion_time + ) + attr_reader :key def initialize(key) @key = key end @@ -28,16 +36,16 @@ completed_tokens = tokens_for_period(range, resolution, "completed") matching_tokens = started_tokens & completed_tokens completion_rate = round_float(matching_tokens.size.to_f / range.size) elapsed_times = matching_tokens.map { |t| t.time_elapsed(resolution) } average_completion_time = (elapsed_times.inject(&:+)) / matching_tokens.size - { - started: started_tokens.size, - completed: completed_tokens.size, - completed_within_period: matching_tokens.size, - completion_rate: completion_rate, - average_completion_time: average_completion_time - } + Stats.new( + started_tokens.size, + completed_tokens.size, + matching_tokens.size, + completion_rate, + average_completion_time + ) end def drop! del_by_prefix("stat:task:#{key}") end