From: CMDR furrycat Date: Thu, 28 Jan 2016 15:08:02 +0000 (-0500) Subject: Show average laps by other calculations. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=a401726b5347d556e2128813efbed069f58defd5;p=furrycat%2Frace-o-matic.git Show average laps by other calculations. --- diff --git a/entry.js b/entry.js index a4b4c8f..a18a9b9 100644 --- a/entry.js +++ b/entry.js @@ -441,6 +441,7 @@ function do_stats(table) { var last_lap = first_column(table); var last_station = last_row(table); var complete_laps = 0; + var complete_time = 0; /* Last lap is removed if we are retrieving an entry. */ var skip = (get_entry_id()) ? 0 : 1; /* Find the last lap and last station visited. */ @@ -449,7 +450,10 @@ function do_stats(table) { var input = get_cell_input(i, j); if (input.value.match(input.pattern)) { last_lap = j; - if (i == last_row(table)) complete_laps++; + if (i == last_row(table)) { + complete_laps++; + complete_time = from_iso8601(real_date(input.value)); + } break; } } @@ -545,7 +549,13 @@ function do_stats(table) { do_stat('fastest_lap', fastest_lap, format_time(fastest_lap)); /* Average lap. */ var average_lap = Math.floor(total_time / complete_laps); - do_stat('average_lap', average_lap, format_time(average_lap)); + var partial_distance = (total_distance - (lap_distance * complete_laps)) / lap_distance; + var average_lap_by_distance = Math.floor(total_time / (complete_laps + partial_distance)); + /* Only if at least one leg completed in the last lap. */ + var partial_station = (partial_distance) ? (last_station - 1) / (last_row(table) - first_row(table)) : 0; + var average_lap_by_station = (total_time / (complete_laps + partial_station)); + var average_lap_by_complete_laps = Math.floor((complete_time - start_time) / complete_laps); + do_stat('average_lap', average_lap, [format_time(average_lap), 'by stations: ' + format_time(average_lap_by_station), 'by distance: ' + format_time(average_lap_by_distance), 'by completed: ' + format_time(average_lap_by_complete_laps)].join(', ')); /* Best speed. */ var best_speed = speed(lap_distance, fastest_lap); do_stat('best_speed', format_speed(best_speed, false), format_speed(best_speed));