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. */
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;
}
}
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));