From: CMDR furrycat Date: Mon, 15 Feb 2016 10:56:03 +0000 (-0500) Subject: Average time per lap graph. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=dfb3bf77abc46e4a91612098314c8fd75d455877;p=furrycat%2Frace-o-matic.git Average time per lap graph. --- diff --git a/lib/race.php b/lib/race.php index bc7e933..e273d1f 100644 --- a/lib/race.php +++ b/lib/race.php @@ -1043,6 +1043,14 @@ "type" => "bar" ) ); + $laptimes = array( + "average_laps" => array( + "x" => array(), + "y" => array(), + "name" => "Average lap times", + "type" => "bar" + ) + ); $laps = array( "fastest_laps" => array( "x" => array(), @@ -1069,8 +1077,12 @@ $speeds["leg_speed"]["y"][] = (float) $row["speed"]; } /* Average time per lap. */ - //$sth = $dbh->prepare("select lap_number, avg(delta) from (select lap_number, timestampdiff(second, min(arrival), max(arrival)) as delta from laptime, lap, entry where laptime.lap_id=lap.id and lap.entry_id=entry.id and lap_number<=entry.complete_laps and race_id=:race_id and entry_id in $(entry_list) group by entry_id, lap_number) as aggregate_laps group by lap_number"); - //$sth->execute(array(":race_id" => $id)); + $sth = $dbh->prepare("select lap_number, avg(delta) as laptime from (select lap_number, timestampdiff(second, min(arrival), max(arrival)) as delta from laptime, lap, entry where laptime.lap_id=lap.id and lap.entry_id=entry.id and lap_number<=entry.complete_laps and race_id=:race_id and entry_id in ($entry_list) group by entry_id, lap_number) as aggregate_laps group by lap_number"); + $sth->execute(array(":race_id" => $id)); + while ($row = $sth->fetch()) { + $laptimes["average_laps"]["x"][] = "Lap " . $row["lap_number"]; + $laptimes["average_laps"]["y"][] = "2000-01-01 " . format_time((int) $row["laptime"]); + } /* Fastest individual lap. */ $sth = $dbh->prepare("select lap_number, count(*) as n from (select lap_number, delta from (select entry_id, lap_number, timestampdiff(second, min(arrival), max(arrival)) as delta from laptime, lap, entry where laptime.lap_id=lap.id and lap.entry_id=entry.id and lap_number<=entry.complete_laps and race_id=:race_id and entry_id in ($entry_list) group by entry_id, lap_number order by entry_id, delta) as aggregate_laps group by entry_id) as aggregate_fastest group by lap_number"); $sth->execute(array(":race_id" => $id)); @@ -1110,6 +1122,8 @@ else echo "var pies = null;\n"; echo "var legs = " . json_encode(array_values($legs)) . ";\n"; echo "var speeds = " . json_encode(array_values($speeds)) . ";\n"; + if (count($laptimes["average_laps"]["x"]) > 1) echo "var laptimes = " . json_encode(array_values($laptimes)) . ";\n"; + else echo "var laptimes = null;\n"; if (count($laps["fastest_laps"]["x"]) > 1) echo "var laps = " . json_encode(array_values($laps)) . ";\n"; else echo "var laps = null;\n"; if (count($raced_times) && count($raced_times[0]["x"]) > 1) echo "var raced_times = " . json_encode(array_values($raced_times)) . ";\n"; @@ -1121,6 +1135,7 @@ echo "
\n"; echo "
\n"; echo "
\n"; + echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; diff --git a/race.js b/race.js index 580b89b..850c0e4 100644 --- a/race.js +++ b/race.js @@ -205,6 +205,11 @@ function loaded() { title: 'Average station to station speed', yaxis: { title: 'Speed (Ly/h)' } }); + canvas = document.getElementById('plot_laptimes'); + if (canvas && laps) Plotly.plot(canvas, laptimes, { + title: 'Average lap times', + yaxis: { title: 'Time', tickformat: '%H:%M:%S' } + }); canvas = document.getElementById('plot_laps'); if (canvas && laps) Plotly.plot(canvas, laps, { title: 'Fastest individual laps',