mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Move calculation out of view
This commit is contained in:
parent
27ba50b460
commit
03282638af
3 changed files with 22 additions and 8 deletions
|
|
@ -9,15 +9,15 @@ module Stats
|
|||
end
|
||||
|
||||
def avg
|
||||
@avg ||= (sum / count) / SECONDS_PER_DAY
|
||||
@avg ||= to_days(sum / count)
|
||||
end
|
||||
|
||||
def max
|
||||
@max ||= max_in_seconds / SECONDS_PER_DAY
|
||||
@max ||= to_days(max_in_seconds)
|
||||
end
|
||||
|
||||
def min
|
||||
@min ||= min_in_seconds / SECONDS_PER_DAY
|
||||
@min ||= to_days(min_in_seconds)
|
||||
end
|
||||
|
||||
def min_sec
|
||||
|
|
@ -29,6 +29,10 @@ module Stats
|
|||
|
||||
private
|
||||
|
||||
def to_days(value)
|
||||
(value * 10 / SECONDS_PER_DAY).round / 10.0
|
||||
end
|
||||
|
||||
def min_in_seconds
|
||||
@min_in_seconds ||= durations.min || 0
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<p><%= t('stats.actions_avg_completion_time', :count => (ttc.avg*10).round/10.0) %>
|
||||
<%= t('stats.actions_min_max_completion_days', :max => (ttc.max*10).round/10.0, :min => (ttc.min*10).round/10.0) %>
|
||||
<p><%= t('stats.actions_avg_completion_time', :count => ttc.avg) %>
|
||||
<%= t('stats.actions_min_max_completion_days', :max => ttc.max, :min => ttc.min) %>
|
||||
<%= t('stats.actions_min_completion_time', :time => ttc.min_sec) %></p>
|
||||
|
||||
|
|
|
|||
|
|
@ -52,15 +52,15 @@ class TimeToCompleteTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_minimum
|
||||
assert_equal 2.127835648148148, Stats::TimeToComplete.new(fake_tasks).min
|
||||
assert_equal 2.1, Stats::TimeToComplete.new(fake_tasks).min
|
||||
end
|
||||
|
||||
def test_maximum
|
||||
assert_equal 6.127835648148148, Stats::TimeToComplete.new(fake_tasks).max
|
||||
assert_equal 6.1, Stats::TimeToComplete.new(fake_tasks).max
|
||||
end
|
||||
|
||||
def test_avg
|
||||
assert_equal 4.127835648148148, Stats::TimeToComplete.new(fake_tasks).avg
|
||||
assert_equal 4.1, Stats::TimeToComplete.new(fake_tasks).avg
|
||||
end
|
||||
|
||||
def test_min_sec
|
||||
|
|
@ -71,5 +71,15 @@ class TimeToCompleteTest < Test::Unit::TestCase
|
|||
task = FakeTask.new(day0, now)
|
||||
assert_equal '03:04:05', Stats::TimeToComplete.new([task]).min_sec
|
||||
end
|
||||
|
||||
def test_rounding
|
||||
start_time = Time.utc(2012, 12, 31, 8, 0, 0)
|
||||
task = FakeTask.new(start_time, now)
|
||||
ttc = Stats::TimeToComplete.new([task])
|
||||
assert_equal 1.8, ttc.avg
|
||||
assert_equal 1.8, ttc.min
|
||||
assert_equal 1.8, ttc.max
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue