update output. use priority**3.0 (emphasize high priority races). make sure starting date range is correct.
This commit is contained in:
1 parent
9e2003c5ef
commit
7027823886
1 file changed
+21
-10
+21
-10
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
require 'date'
|
require 'date'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'pp'
|
|
||||||
|
|
||||||
def load_races
|
def load_races
|
||||||
# get data from json file and convert to ruby types
|
# get data from json file and convert to ruby types
|
||||||
@@ -36,18 +35,33 @@ def score(start_date, plan, races)
|
|||||||
races.inject(0.0) do |sum, race|
|
races.inject(0.0) do |sum, race|
|
||||||
weeks_from_start = get_plan_week(start_date, race[:date], plan)
|
weeks_from_start = get_plan_week(start_date, race[:date], plan)
|
||||||
week_value = plan[weeks_from_start]
|
week_value = plan[weeks_from_start]
|
||||||
sum + (week_value * race[:priority].to_f)
|
sum + (week_value * (race[:priority].to_f ** 3.0))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO hacky. should be in the data.
|
||||||
|
def get_week_desc(wnum)
|
||||||
|
case wnum
|
||||||
|
when 0..6
|
||||||
|
"building"
|
||||||
|
when 7..10
|
||||||
|
"peaking"
|
||||||
|
when 11..14
|
||||||
|
"recovery"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def dump(start_date, plan, races)
|
def dump(start_date, plan, races)
|
||||||
|
puts "================================================================================"
|
||||||
puts "starting on #{start_date}"
|
puts "starting on #{start_date}"
|
||||||
puts "in week #{get_plan_week(start_date, Date.today, plan)+1} as of today (#{Date.today})"
|
puts "in week #{get_plan_week(start_date, Date.today, plan)+1} as of today (#{Date.today})"
|
||||||
|
puts "--------------------------------------------------------------------------------"
|
||||||
races.each do |race|
|
races.each do |race|
|
||||||
weeks_from_start = get_plan_week(start_date, race[:date], plan)
|
weeks_from_start = get_plan_week(start_date, race[:date], plan)
|
||||||
week_value = plan[weeks_from_start]
|
puts "week #{weeks_from_start+1} #{get_week_desc(weeks_from_start)} #{race[:date]} #{race[:priority]} #{race[:name]}"
|
||||||
puts "week #{weeks_from_start+1} (#{week_value}) #{race[:date]} #{race[:priority]} #{race[:name]}"
|
|
||||||
end
|
end
|
||||||
|
puts "================================================================================"
|
||||||
|
puts
|
||||||
end
|
end
|
||||||
|
|
||||||
# load data
|
# load data
|
||||||
@@ -56,16 +70,13 @@ plan = load_plan
|
|||||||
|
|
||||||
# find all the mondays from a few months before the first date, through the end
|
# find all the mondays from a few months before the first date, through the end
|
||||||
first_race_date = races[0][:date]
|
first_race_date = races[0][:date]
|
||||||
m = mondays(first_race_date - 180, first_race_date)
|
m = mondays(first_race_date - ((plan.size-1)*7), first_race_date)
|
||||||
|
|
||||||
# score the plan beginning on each monday
|
# score the plan beginning on each monday
|
||||||
scores = m.map do |monday|
|
scores = m.map do |monday|
|
||||||
[score(monday,plan,races), monday]
|
[score(monday,plan,races), monday]
|
||||||
end.sort.reverse
|
end.sort.reverse
|
||||||
|
|
||||||
# output three best dates
|
# output the best dates
|
||||||
3.times do |i|
|
dump(scores[0][1], plan, races)
|
||||||
starting = scores[i][1]
|
|
||||||
dump(starting, plan, races)
|
|
||||||
end
|
|
||||||
|
|
||||||
Reference in new issue
Block a user