mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-10 06:32:36 +01:00
Combining the running average methods
This commit is contained in:
parent
91e4717168
commit
5e6b82c3e5
1 changed files with 6 additions and 12 deletions
|
|
@ -27,8 +27,8 @@ class StatsController < ApplicationController
|
||||||
done_in_last_15_months = put_events_into_month_buckets(actions_last12months, 16, :completed_at)
|
done_in_last_15_months = put_events_into_month_buckets(actions_last12months, 16, :completed_at)
|
||||||
created_in_last_15_months = put_events_into_month_buckets(actions_last12months, 16, :created_at)
|
created_in_last_15_months = put_events_into_month_buckets(actions_last12months, 16, :created_at)
|
||||||
|
|
||||||
@actions_done_avg_last12months_array = make_running_avg_array(done_in_last_15_months, 13)
|
@actions_done_avg_last12months_array = compute_running_avg_array(done_in_last_15_months, 13)
|
||||||
@actions_created_avg_last12months_array = make_running_avg_array(created_in_last_15_months, 13)
|
@actions_created_avg_last12months_array = compute_running_avg_array(created_in_last_15_months, 13)
|
||||||
|
|
||||||
# interpolate avg for current month.
|
# interpolate avg for current month.
|
||||||
@interpolated_actions_created_this_month = interpolate_avg_for_current_month(@actions_created_last12months_array)
|
@interpolated_actions_created_this_month = interpolate_avg_for_current_month(@actions_created_last12months_array)
|
||||||
|
|
@ -454,19 +454,13 @@ class StatsController < ApplicationController
|
||||||
(set[0]*(1/percent) + set[1] + set[2]) / 3.0
|
(set[0]*(1/percent) + set[1] + set[2]) / 3.0
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_running_avg_array(set, upper_bound)
|
# sets "null" on first column and - if necessary - cleans up last two columns, which may have insufficient data
|
||||||
result = Array.new(upper_bound) { |i| three_month_avg(set, i) }
|
|
||||||
result[0] = "null"
|
|
||||||
result
|
|
||||||
end
|
|
||||||
|
|
||||||
# sets "null" on first column and cleans up last two columns, which 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 = Array.new(upper_bound) { |i| three_month_avg(set, i) }
|
||||||
result[upper_bound-1] = result[upper_bound-1] * 3
|
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
|
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"
|
||||||
result
|
result
|
||||||
end
|
end # unsolved, not triggered, edge case for set.length == upper_bound + 1
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue