Show time raced by competitors.
authorCMDR furrycat <elite@furrycat.net>
Mon, 8 Feb 2016 15:23:47 +0000 (10:23 -0500)
committerCMDR furrycat <elite@furrycat.net>
Mon, 8 Feb 2016 15:23:47 +0000 (10:23 -0500)
lib/race.php
race.js

index 6435544..33a7bc3 100644 (file)
       echo "<div id=\"plot_legs\"></div>\n";
       echo "<div id=\"plot_speeds\"></div>\n";
       echo "<div id=\"plot_laps\"></div>\n";
+      echo "<div id=\"plot_raced_times\"></div>\n";
       echo "<div class=\"classification\">\n";
 
       /* Sort options. */
       $hulls = array();
       $lap_counts = array();
       $lap_distances = array();
+      $time_raced = array();
       foreach ($filtered_entries as $entry) {
         $ship = $entry->getShip();
         $cmdr_name = $ship->getCompetitor()->getCmdrName();
         $hull_name = $ship->getHull()->getName();
+        if (! array_key_exists($cmdr_name, $time_raced)) $time_raced[$cmdr_name] = 0;
+        $time_raced[$cmdr_name] += $entry->getRacedTime();
         $lap_count = $entry->getCompleteLaps();
         $lap_count = sprintf("%d lap%s", $lap_count, ($lap_count == 1) ? "" : "s");
         $lap_distance = format_distance($entry->getLapDistance()) . "Ly";
         $laps["fastest_laps"]["x"][] = "Lap " . $row["lap_number"];
         $laps["fastest_laps"]["y"][] = (int) $row["n"];
       }
+      arsort($time_raced);
+      foreach ($time_raced as $cmdr_name => $time) {
+        $raced_times["raced_times"]["x"][] = $cmdr_name;
+        $raced_times["raced_times"]["y"][] = "2000-01-01 " . format_time($time);
+      }
+      /* Time raced. */
       echo "<script type=\"text/javascript\"><!--\n";
       echo "var pies = " . json_encode(array_values($plots)) . ";\n";
       echo "var legs = " . json_encode(array_values($legs)) . ";\n";
       echo "var speeds = " . json_encode(array_values($speeds)) . ";\n";
       echo "var laps = " . json_encode(array_values($laps)) . ";\n";
+      echo "var raced_times = " . json_encode(array_values($raced_times)) . ";\n";
       echo "//--></script>\n";
     }
     echo "<hr>\n";
diff --git a/race.js b/race.js
index 87128c8..832c5dc 100644 (file)
--- a/race.js
+++ b/race.js
@@ -168,6 +168,11 @@ function loaded() {
   if (canvas && laps) Plotly.plot(canvas, laps, {
     title: 'Fastest individual laps',
   });
+  canvas = document.getElementById('plot_raced_times');
+  if (canvas && raced_times) Plotly.plot(canvas, raced_times, {
+    title: 'Time raced',
+    yaxis: { title: 'Time', tickformat: '%H:%M:%S' }
+  });
 }
 
 document.onload = loaded();