From 70278238867d071e1d885982be2c2009b22e4103 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 21 Dec 2014 20:28:19 -0800 Subject: [PATCH] update output. use priority**3.0 (emphasize high priority races). make sure starting date range is correct. --- create-plan.rb | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/create-plan.rb b/create-plan.rb index 8e9bf75..67af9e8 100755 --- a/create-plan.rb +++ b/create-plan.rb @@ -2,7 +2,6 @@ require 'date' require 'json' -require 'pp' def load_races # 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| weeks_from_start = get_plan_week(start_date, race[:date], plan) 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 def dump(start_date, plan, races) + puts "================================================================================" puts "starting on #{start_date}" puts "in week #{get_plan_week(start_date, Date.today, plan)+1} as of today (#{Date.today})" + puts "--------------------------------------------------------------------------------" races.each do |race| weeks_from_start = get_plan_week(start_date, race[:date], plan) - week_value = plan[weeks_from_start] - puts "week #{weeks_from_start+1} (#{week_value}) #{race[:date]} #{race[:priority]} #{race[:name]}" + puts "week #{weeks_from_start+1} #{get_week_desc(weeks_from_start)} #{race[:date]} #{race[:priority]} #{race[:name]}" end + puts "================================================================================" + puts end # load data @@ -56,16 +70,13 @@ plan = load_plan # find all the mondays from a few months before the first date, through the end 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 scores = m.map do |monday| [score(monday,plan,races), monday] end.sort.reverse -# output three best dates -3.times do |i| - starting = scores[i][1] - dump(starting, plan, races) -end +# output the best dates +dump(scores[0][1], plan, races)