diff options
Diffstat (limited to 'lib/gitlab/cycle_analytics/summary_helper.rb')
-rw-r--r-- | lib/gitlab/cycle_analytics/summary_helper.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/gitlab/cycle_analytics/summary_helper.rb b/lib/gitlab/cycle_analytics/summary_helper.rb new file mode 100644 index 00000000000..06abcd151d4 --- /dev/null +++ b/lib/gitlab/cycle_analytics/summary_helper.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module SummaryHelper + def frequency(count, from, to) + return count if count.zero? + + freq = (count / days(from, to)).round(1) + freq.zero? ? '0' : freq + end + + def days(from, to) + [(to.end_of_day - from.beginning_of_day).fdiv(1.day), 1].max + end + end + end +end |