mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-18 08:10:13 +01:00
Tweak to running averages
This commit is contained in:
parent
ff54506e7f
commit
3d2c048c44
1 changed files with 5 additions and 1 deletions
|
|
@ -450,9 +450,13 @@ class StatsController < ApplicationController
|
||||||
(set.fetch(i,0) + set.fetch(i+1,0) + set.fetch(i+2,0)) / 3.0
|
(set.fetch(i,0) + set.fetch(i+1,0) + set.fetch(i+2,0)) / 3.0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_three_month_avg(set,upper_bound)
|
||||||
|
(0..upper_bound-1).map { |i| three_month_avg(set, i) }
|
||||||
|
end
|
||||||
|
|
||||||
# sets "null" on first column and - if necessary - cleans up last two columns, which may have insufficient data
|
# sets "null" on first column and - if necessary - cleans up last two columns, which may have insufficient data
|
||||||
def compute_running_avg_array(set, upper_bound)
|
def compute_running_avg_array(set, upper_bound)
|
||||||
result = Array.new(upper_bound) { |i| three_month_avg(set, i) }
|
result = set_three_month_avg(set, upper_bound)
|
||||||
result[upper_bound-1] = result[upper_bound-1] * 3 if upper_bound == set.length
|
result[upper_bound-1] = result[upper_bound-1] * 3 if upper_bound == set.length
|
||||||
result[upper_bound-2] = result[upper_bound-2] * 3 / 2 if upper_bound > 1 and upper_bound == set.length
|
result[upper_bound-2] = result[upper_bound-2] * 3 / 2 if upper_bound > 1 and upper_bound == set.length
|
||||||
result[0] = "null"
|
result[0] = "null"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue