<img src="images/logo.png" alt="Buckyball Racing Club" height=100 width=100>
<?php
$links = array();
- foreach (array("competitor", "hull", "ship", "system", "station", "race", "raikogram", "entry", "timeline") as $what) {
+ foreach (array("competitor", "hull", "ship", "system", "station", "race", "raikogram", "entry") as $what) {
$title = preg_replace('/y$/', 'ie', $what);
$links[] = "<span class=\"menu\"><a href=\"?module=$what\">" . ucfirst($title) . "s</a></span>";
}
return false;
}
+ function ordinal($n) {
+ if (($n % 100) >= 11 && ($n % 100) <= 13) return "${n}th";
+ else return $n . array('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th')[$n % 10];
+ }
+
function find_prizewinners($race, $entries) {
$competitors = array();
$prizes = array();
return ($A < $B) ? 1 : -1;
}
+ function show_timeline($race_id, $filtered_entry_ids) {
+ $cq = new CourseQuery;
+ $cq->joinWith('Course.Race');
+ $cq->joinWith('Course.Station');
+ $course = $cq->filterByRaceId($race_id)->find();
+ $race = $start_line = $finish_line = null;
+ $system_ids = array();
+ foreach ($course as $leg) {
+ if (! $race) $race = $leg->getRace();
+ $station_id = $leg->getStationId();
+ if ($leg->getFinishLine()) $finish_line = $station_id;
+ if ($leg->getStartLine()) $start_line = $station_id;
+ $system_ids[] = $leg->getStation()->getSystemId();
+ }
+ $system_ids = array_unique($system_ids);
+
+ $rq = new RaikogramQuery;
+ $rq->filterBySystem1($system_ids);
+ $rq->filterBySystem2($system_ids);
+ $raikograms = $rq->find();
+ $distances = array();
+ foreach ($raikograms as $raikogram) {
+ $system1 = $raikogram->getSystem1();
+ $system2 = $raikogram->getSystem2();
+ $distance = $raikogram->getDistance();
+ $distances["from{$system1}to${system2}"] = $distance;
+ }
+
+ $allotted_time = $race->getAllottedTime();
+ echo "<h3>Timeline</h3>\n";
+ echo "<div id=\"plot_timeline\"></div>\n";
+ $plots = array();
+
+ $json_racers = array();
+ $json_events = array();
+ $eq = new EntryQuery;
+ $eq->joinWith('Entry.Ship');
+ $eq->joinWith('Ship.Competitor');
+ $eq->joinWith('Ship.Hull');
+ $eq->filterByRaceId($race_id);
+ $eq->filterById($filtered_entry_ids);
+ $entry_objects = $eq->find();
+ foreach ($entry_objects as $entry) $entries[] = $entry;
+ $prizewinners = find_prizewinners($race, $entries);
+ uasort($entries, "Entry::StandardSort");
+ $ranked_entries = array();
+ $competitor_entries = array();
+ foreach ($entries as $entry) {
+ if ($entry->isExcluded()) continue;
+ $entry_id = $entry->getId();
+ $ship =$entry->getShip();
+ $competitor = $ship->getCompetitor();
+ $competitor_id = $competitor->getId();
+ $competitor_entries[$competitor_id] = $entry_id;
+ $ranked_entries[$entry_id] = true;
+ $json_racer = array("join" => count($json_racers) + 1);
+ $json_racer["owner"] = $competitor->getCmdrName();
+ $json_racer["user"] = $competitor->getForumName();
+ if (! $json_racer["user"]) $json_racer["user"] = $json_racer["owner"];
+ $json_racer["ship"] = $ship->getName();
+ $json_racer["hull"] = $ship->getHull()->getName();
+ $json_racer["lap_distance"] = $entry->getLapDistance();
+ $json_racer["complete_laps"] = $entry->getCompleteLaps();
+ $json_racer["allotted_time"] = $allotted_time + $entry->getBonusTime();
+ $json_racer["bonus_time"] = (int) $entry->getBonusTime();
+ $json_racer["raced_time"] = $entry->getRacedTime();
+ $json_racer["total_time"] = $entry->getTotalTime();
+ $json_racer["joker"] = (bool) $entry->usedJoker();
+ $json_racer["shields"] = (bool) $entry->shields();
+ $json_racer["docking_computer"] = (bool) $entry->usedDockingComputer();
+ $json_racer["fsd_injection"] = (bool) $entry->usedInjection();
+ $json_racer["cut_short"] = (bool) $entry->cutShort();
+ $json_racers[] = $json_racer;
+ }
+
+ $q = new LaptimeQuery;
+ $q->joinWith('Laptime.Station');
+ $q->joinWith('Station.System');
+ $q->joinWith('Laptime.Lap');
+ $q->joinWith('Lap.Entry');
+ $q->joinWith('Entry.Ship');
+ $q->joinWith('Ship.Competitor');
+ $q->joinWith('Ship.Hull');
+ $q->where('Entry.RaceId=?', $race_id);
+ $q->where('Entry.Id in (' . implode(',', $filtered_entry_ids) . ')');
+ $legs = $q->orderByArrival()->orderBy('Lap.LapNumber')->orderByStationOrder()->orderBy('Competitor.CmdrName')->orderBy('Entry.Id')->find();
+
+ $start_times = array();
+ $ordered_arrivals = array();
+ $entry_system_ids = array();
+ $entry_distance = array();
+ foreach ($legs as $leg) {
+ $id = $leg->getId();
+ $arrival = strtotime($leg->getArrival());
+ $station_order = $leg->getStationOrder();
+ $lap = $leg->getLap();
+ $lap_number = $lap->getLapNumber();
+ $entry = $lap->getEntry();
+ $entry_id = $entry->getId();
+ if (! is_array($entry_system_ids[$entry_id])) $entry_system_ids[$entry_id] = array(null);
+ $entry_system_ids[$entry_id][] = $leg->getStation()->getSystemId();
+ if ($lap_number == 1 && $station_order == 1) $start_times[$entry_id] = $arrival;
+ $delta = $arrival - $start_times[$entry_id];
+ if (! is_array($ordered_arrivals[$delta])) $ordered_arrivals[$delta] = array();
+ $ordered_arrivals[$delta][] = $leg;
+ if (! $entry_distance[$entry_id]) $entry_distance[$entry_id] = 0.0;
+ $plot_key = $entry->getShip()->getCompetitor()->getCmdrName() . " #$entry_id";
+ if (! is_array($plots[$plot_key])) $plots[$plot_key] = array(
+ "x" => array("2001-01-01 00:00:00"),
+ "y" => array(0),
+ "name" => $plot_key,
+ "text" => array("")
+ );
+ }
+
+ ksort($ordered_arrivals);
+
+ foreach($ordered_arrivals as $time => $ordered_legs) {
+ foreach ($ordered_legs as $leg) {
+ $delta = format_time($time);
+ $arrival = elite_time($leg->getArrival());
+ $station_order = $leg->getStationOrder();
+ $nth = ordinal($station_order);
+ $station = $leg->getStation();
+ $station_id = $station->getId();
+ $station_name = $station->getName();
+ $type = strtolower($station->getType());
+ $system = $station->getSystem();
+ $system_name = $system->getName();
+ $lap = $leg->getLap();
+ $lap_number = $lap->getLapNumber();
+ $hull_start = $lap->getHullStart();
+ $hull_end = $lap->getHullEnd();
+ $entry = $lap->getEntry();
+ $entry_id = $entry->getId();
+ $start_time = $entry->getLink(elite_time(date('Y-m-d H:i:s', $start_times[$entry_id])));
+ $ship = $entry->getShip();
+ $ship_name = $ship->getLink();
+ $competitor = $ship->getCompetitor();
+ $cmdr_name = $competitor->getLink();
+ $hull = $ship->getHull();
+ $hull_name = $hull->getLink();
+
+ $distance = 0.0;
+ $previous_system_id = array_shift($entry_system_ids[$entry_id]);
+ if (! is_null($previous_system_id)) {
+ $system_id = $system->getId();
+ if ($system_id != $previous_system_id) {
+ $system1 = min($system_id, $previous_system_id);
+ $system2 = max($system_id, $previous_system_id);
+ $distance = (float) $distances["from${system1}to${system2}"];
+ $entry_distance[$entry_id] += $distance;
+ }
+ $total_distance = $entry_distance[$entry_id];
+ $plot_key = $competitor->getCmdrName() . " #$entry_id";
+ $plots[$plot_key]["x"][] = "2001-01-01 $delta";
+ $plots[$plot_key]["y"][] = $total_distance;
+ $order = "station $station_order";
+ if ($allotted_time) $order = "lap $lap_number $order";
+ $plots[$plot_key]["text"][] = array($system_name, $station_name, $delta, $order);
+ }
+
+ $style_cmdr = "cmdr" . $competitor->getId();
+ $style_entry = "entry$entry_id";
+ $style_hull = "hull" . $hull->getId();
+ $style_ship = "ship" . $ship->getId();
+ $style_lap = "lap$lap_number";
+ $style_order = "order$station_order";
+ $style_station = "station$station_id";
+ $style_system = "system" . $system->getId();
+ $classes = array(
+ "leg",
+ $style_cmdr,
+ $style_entry,
+ $style_hull,
+ $style_lap,
+ $style_order,
+ $style_ship,
+ $style_station,
+ $style_system
+ );
+
+ $verb = ($station_order > 1) ? "arrived at" : "left";
+ echo "<p class=\"" . implode(' ', $classes) . "\">";
+ echo "$delta: CMDR <strong><span class=\"$style_cmdr\">$cmdr_name</span></strong> flying <span class=\"$style_hull\">$hull_name</span> <strong><span class=\"$style_ship\">$ship_name</span></strong> from <span class=\"$style_entry\">$start_time</span> $verb <span class=\"$style_order\">$nth station</span> ";
+ if ($allotted_time) {
+ echo "of <span class=\"$style_lap\">lap $lap_number</span>, ";
+ if ($time <= $allotted_time) $period = "regulation";
+ else if ($time <= $allotted_time + $entry->getBonusTime()) $period = "bonus";
+ else $period = "penalty";
+ }
+ echo "<em><span class=\"$style_station\">$station_name</span></em> $type in <strong><span class=\"$style_system\">$system_name</span></strong> at $arrival";
+ if ($station_id == $finish_line && $station_number > 1 && is_numeric($hull_end)) echo " with $hull_end% hull remaining";
+ else if ($station_id == $start_line && is_numeric($hull_start)) echo " with $hull_start% hull";
+ if ($distance) echo " covering ${distance}Ly of total ${total_distance}Ly";
+ if ($allotted_time) echo " during $period";
+ echo "</p>";
+
+ if (array_key_exists($entry_id, $ranked_entries)) {
+ $json_events[] = array(
+ "ship" => $ship->getName(),
+ "event_type" => explode(" ", $verb)[0],
+ "time" => $time,
+ "timestamp" => $arrival,
+ "time_period" => $period,
+ "location" => $station->getName(),
+ "lap" => $lap_number,
+ "leg" => $station_order,
+ "leg_distance" => (float) $distance,
+ "total_distance" => (float) $total_distance
+ );
+ }
+ }
+ }
+
+ echo "<script type=\"text/javascript\"><!--\n";
+ echo "var points = " . json_encode(array_values($plots)) . ";\n";
+ echo "//--></script>\n";
+
+ echo "<h3>JSON</h3>\n";
+ echo "<div><pre>\n";
+ echo json_encode(array(
+ "racers" => $json_racers,
+ "events" => $json_events,
+ ));
+ echo "</pre></div>\n";
+ }
+
function module_race($action, $args) {
if ($_POST['add_race']) {
if (add_race($_POST["name"], $_POST["allotted_time"])) unset($_POST);
foreach ($race->getPrizeKeys() as $p) $prizes[] = $race->PrizeDescription($p);
echo "<p>Prizes for " . implode(", ", $prizes) . ".</p>\n";
}
- echo "<div id=\"plot_distribution\"></div>\n";
- 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 id=\"plot_raced_days\"></div>\n";
echo "<div class=\"classification\">\n";
/* Sort options. */
if ($show_raced_days) echo "var raced_days = " . json_encode(array_values($raced_days)) . ";\n";
else echo "var raced_days = null;\n";
echo "//--></script>\n";
+
+ echo "<div id=\"plot_distribution\"></div>\n";
+ 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 id=\"plot_raced_days\"></div>\n";
+
+ show_timeline($id, $filtered_entry_ids);
}
echo "<hr>\n";
$sq = new StationQuery;
+++ /dev/null
-<script src="plotly-latest.min.js"></script>
-<h2>Race timelines</h2>
-<?php
-
- function ordinal($n) {
- if (($n % 100) >= 11 && ($n % 100) <= 13) return "${n}th";
- else return $n . array('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th')[$n % 10];
- }
-
- function find_prizewinners($race, $entries) {
- $competitors = array();
- $prizes = array();
- $last_sort_method = null;
- foreach ($race->getPrizeKeys() as $p) {
- $sort_method = $race->PrizeSortMethod($p);
- if ($sort_method != $last_sort_method) uasort($entries, "Entry::$sort_method");
- $last_sort_method = $sort_method;
- foreach ($entries as $entry) {
- if ($entry->isExcluded()) continue;
- $entry_id = $entry->getId();
- if (array_key_exists($entry_id, $prizes)) continue;
- $competitor_id = $entry->getShip()->getCompetitorId();
- if (array_key_exists($competitor_id, $competitors)) continue;
- $prizes[$entry_id] = $p;
- $competitors[$competitor_id] = $entry_id;
- break;
- }
- }
- return array(
- "competitors" => $competitors,
- "entries" => $prizes
- );
- }
-
- function show_timeline($race_id) {
- $cq = new CourseQuery;
- $cq->joinWith('Course.Race');
- $cq->joinWith('Course.Station');
- $course = $cq->filterByRaceId($race_id)->find();
- $race = $start_line = $finish_line = null;
- $system_ids = array();
- foreach ($course as $leg) {
- if (! $race) $race = $leg->getRace();
- $station_id = $leg->getStationId();
- if ($leg->getFinishLine()) $finish_line = $station_id;
- if ($leg->getStartLine()) $start_line = $station_id;
- $system_ids[] = $leg->getStation()->getSystemId();
- }
- $system_ids = array_unique($system_ids);
-
- $rq = new RaikogramQuery;
- $rq->filterBySystem1($system_ids);
- $rq->filterBySystem2($system_ids);
- $raikograms = $rq->find();
- $distances = array();
- foreach ($raikograms as $raikogram) {
- $system1 = $raikogram->getSystem1();
- $system2 = $raikogram->getSystem2();
- $distance = $raikogram->getDistance();
- $distances["from{$system1}to${system2}"] = $distance;
- }
-
- $allotted_time = $race->getAllottedTime();
- echo "<h3>" . $race->getName() . "</h3>\n";
- echo "<div id=\"plot\"></div>\n";
- $plots = array();
-
- $json_racers = array();
- $json_events = array();
- $eq = new EntryQuery;
- $eq->joinWith('Entry.Ship');
- $eq->joinWith('Ship.Competitor');
- $eq->joinWith('Ship.Hull');
- $eq->filterByRaceId($race_id);
- $entry_objects = $eq->find();
- foreach ($entry_objects as $entry) $entries[] = $entry;
- $prizewinners = find_prizewinners($race, $entries);
- uasort($entries, "Entry::StandardSort");
- $ranked_entries = array();
- $competitor_entries = array();
- foreach ($entries as $entry) {
- if ($entry->isExcluded()) continue;
- $entry_id = $entry->getId();
- $ship =$entry->getShip();
- $competitor = $ship->getCompetitor();
- $competitor_id = $competitor->getId();
- if (array_key_exists($entry_id, $prizewinners["entries"]) || (! array_key_exists($competitor_id, $prizewinners["competitors"]) && ! array_key_exists($competitor_id, $competitor_entries))) {
- $competitor_entries[$competitor_id] = $entry_id;
- $ranked_entries[$entry_id] = true;
- $json_racer = array("join" => count($json_racers) + 1);
- $json_racer["owner"] = $competitor->getCmdrName();
- $json_racer["user"] = $competitor->getForumName();
- if (! $json_racer["user"]) $json_racer["user"] = $json_racer["owner"];
- $json_racer["ship"] = $ship->getName();
- $json_racer["hull"] = $ship->getHull()->getName();
- $json_racer["lap_distance"] = $entry->getLapDistance();
- $json_racer["complete_laps"] = $entry->getCompleteLaps();
- $json_racer["allotted_time"] = $allotted_time + $entry->getBonusTime();
- $json_racer["bonus_time"] = (int) $entry->getBonusTime();
- $json_racer["raced_time"] = $entry->getRacedTime();
- $json_racer["total_time"] = $entry->getTotalTime();
- $json_racer["joker"] = (bool) $entry->usedJoker();
- $json_racer["shields"] = (bool) $entry->shields();
- $json_racer["docking_computer"] = (bool) $entry->usedDockingComputer();
- $json_racer["fsd_injection"] = (bool) $entry->usedInjection();
- $json_racer["cut_short"] = (bool) $entry->cutShort();
- $json_racers[] = $json_racer;
- }
- }
-
- $q = new LaptimeQuery;
- $q->joinWith('Laptime.Station');
- $q->joinWith('Station.System');
- $q->joinWith('Laptime.Lap');
- $q->joinWith('Lap.Entry');
- $q->joinWith('Entry.Ship');
- $q->joinWith('Ship.Competitor');
- $q->joinWith('Ship.Hull');
- $q->where('Entry.RaceId=?', $race_id);
- $legs = $q->orderByArrival()->orderBy('Lap.LapNumber')->orderByStationOrder()->orderBy('Competitor.CmdrName')->orderBy('Entry.Id')->find();
-
- $start_times = array();
- $ordered_arrivals = array();
- $entry_system_ids = array();
- $entry_distance = array();
- foreach ($legs as $leg) {
- $id = $leg->getId();
- $arrival = strtotime($leg->getArrival());
- $station_order = $leg->getStationOrder();
- $lap = $leg->getLap();
- $lap_number = $lap->getLapNumber();
- $entry = $lap->getEntry();
- $entry_id = $entry->getId();
- if (! is_array($entry_system_ids[$entry_id])) $entry_system_ids[$entry_id] = array(null);
- $entry_system_ids[$entry_id][] = $leg->getStation()->getSystemId();
- if ($lap_number == 1 && $station_order == 1) $start_times[$entry_id] = $arrival;
- $delta = $arrival - $start_times[$entry_id];
- if (! is_array($ordered_arrivals[$delta])) $ordered_arrivals[$delta] = array();
- $ordered_arrivals[$delta][] = $leg;
- if (! $entry_distance[$entry_id]) $entry_distance[$entry_id] = 0.0;
- $plot_key = $entry->getShip()->getCompetitor()->getCmdrName() . " #$entry_id";
- if (! is_array($plots[$plot_key])) $plots[$plot_key] = array(
- "x" => array("2001-01-01 00:00:00"),
- "y" => array(0),
- "name" => $plot_key,
- "text" => array("")
- );
- }
-
- ksort($ordered_arrivals);
-
- foreach($ordered_arrivals as $time => $ordered_legs) {
- foreach ($ordered_legs as $leg) {
- $delta = format_time($time);
- $arrival = elite_time($leg->getArrival());
- $station_order = $leg->getStationOrder();
- $nth = ordinal($station_order);
- $station = $leg->getStation();
- $station_id = $station->getId();
- $station_name = $station->getName();
- $type = strtolower($station->getType());
- $system = $station->getSystem();
- $system_name = $system->getName();
- $lap = $leg->getLap();
- $lap_number = $lap->getLapNumber();
- $hull_start = $lap->getHullStart();
- $hull_end = $lap->getHullEnd();
- $entry = $lap->getEntry();
- $entry_id = $entry->getId();
- $start_time = $entry->getLink(elite_time(date('Y-m-d H:i:s', $start_times[$entry_id])));
- $ship = $entry->getShip();
- $ship_name = $ship->getLink();
- $competitor = $ship->getCompetitor();
- $cmdr_name = $competitor->getLink();
- $hull = $ship->getHull();
- $hull_name = $hull->getLink();
-
- $distance = 0.0;
- $previous_system_id = array_shift($entry_system_ids[$entry_id]);
- if (! is_null($previous_system_id)) {
- $system_id = $system->getId();
- if ($system_id != $previous_system_id) {
- $system1 = min($system_id, $previous_system_id);
- $system2 = max($system_id, $previous_system_id);
- $distance = (float) $distances["from${system1}to${system2}"];
- $entry_distance[$entry_id] += $distance;
- }
- $total_distance = $entry_distance[$entry_id];
- $plot_key = $competitor->getCmdrName() . " #$entry_id";
- $plots[$plot_key]["x"][] = "2001-01-01 $delta";
- $plots[$plot_key]["y"][] = $total_distance;
- $order = "station $station_order";
- if ($allotted_time) $order = "lap $lap_number $order";
- $plots[$plot_key]["text"][] = array($system_name, $station_name, $delta, $order);
- }
-
- $style_cmdr = "cmdr" . $competitor->getId();
- $style_entry = "entry$entry_id";
- $style_hull = "hull" . $hull->getId();
- $style_ship = "ship" . $ship->getId();
- $style_lap = "lap$lap_number";
- $style_order = "order$station_order";
- $style_station = "station$station_id";
- $style_system = "system" . $system->getId();
- $classes = array(
- "leg",
- $style_cmdr,
- $style_entry,
- $style_hull,
- $style_lap,
- $style_order,
- $style_ship,
- $style_station,
- $style_system
- );
-
- $verb = ($station_order > 1) ? "arrived at" : "left";
- echo "<p class=\"" . implode(' ', $classes) . "\">";
- echo "$delta: CMDR <strong><span class=\"$style_cmdr\">$cmdr_name</span></strong> flying <span class=\"$style_hull\">$hull_name</span> <strong><span class=\"$style_ship\">$ship_name</span></strong> from <span class=\"$style_entry\">$start_time</span> $verb <span class=\"$style_order\">$nth station</span> ";
- if ($allotted_time) {
- echo "of <span class=\"$style_lap\">lap $lap_number</span>, ";
- if ($time <= $allotted_time) $period = "regulation";
- else if ($time <= $allotted_time + $entry->getBonusTime()) $period = "bonus";
- else $period = "penalty";
- }
- echo "<em><span class=\"$style_station\">$station_name</span></em> $type in <strong><span class=\"$style_system\">$system_name</span></strong> at $arrival";
- if ($station_id == $finish_line && $station_number > 1 && is_numeric($hull_end)) echo " with $hull_end% hull remaining";
- else if ($station_id == $start_line && is_numeric($hull_start)) echo " with $hull_start% hull";
- if ($distance) echo " covering ${distance}Ly of total ${total_distance}Ly";
- if ($allotted_time) echo " during $period";
- echo "</p>";
-
- if (array_key_exists($entry_id, $ranked_entries)) {
- $json_events[] = array(
- "ship" => $ship->getName(),
- "event_type" => explode(" ", $verb)[0],
- "time" => $time,
- "timestamp" => $arrival,
- "time_period" => $period,
- "location" => $station->getName(),
- "lap" => $lap_number,
- "leg" => $station_order,
- "leg_distance" => (float) $distance,
- "total_distance" => (float) $total_distance
- );
- }
- }
- }
-
- echo "<script type=\"text/javascript\"><!--\n";
- echo "var points = " . json_encode(array_values($plots)) . ";\n";
- echo "//--></script>\n";
-
- echo "<h3>JSON</h3>\n";
- echo "<div><pre>\n";
- echo json_encode(array(
- "racers" => $json_racers,
- "events" => $json_events,
- ));
- echo "</pre></div>\n";
- }
-
- function module_timeline($action, $args) {
- if ($action) show_timeline($action);
- $rq = new RaceQuery;
- $rq->joinWith('Race.Entry');
- $races = $rq->find();
- foreach ($races as $race) {
- if (! count($race->getEntries())) continue;
- $id = $race->getId();
- $name = $race->getName();
- /* XXX */
- $url = preg_replace('/&action=\d+/', '', $_SERVER['REQUEST_URI']) . "&action=$id";
- echo "<p><a href=\"$url\">$name</a></p>\n";
- }
- }
-
-?>
var finish_flag = 1 << 2;
var mandatory_flags = start_flag | finish_flag;
+/* Set the background for a leg element. */
+function leg_background(classes, colour) {
+ var changed = false;
+ for (var c of classes) {
+ for (var element of document.getElementsByClassName(c)) {
+ if (! element.classList.contains('leg')) continue;
+ element.style.backgroundColor = colour;
+ changed = true;
+ }
+ }
+ return changed;
+}
+
+/* Hover over an element. */
+function enter(event) {
+ if (leg_background(event.target.classList, 'rgba(255, 100, 24, 0.4)')) {
+ event.target.style.textDecoration = 'underline';
+ }
+}
+
+/* Mouse out of an element. */
+function leave(event) {
+ if (leg_background(event.target.classList, 'inherit')) {
+ event.target.style.textDecoration = 'inherit';
+ }
+}
+
/* Copy table to clipboard. */
function copy_classification(event) {
try {
/* Document onload. */
function loaded() {
- for (var classification of document.getElementsByClassName('classification')) {
- classification.addEventListener('dblclick', copy_classification, true);
- }
var waypoints = document.getElementsByClassName('station');
if (waypoints.length) {
var div = document.getElementById('waypoints');
}
validate();
}
- var canvas = document.getElementById('plot_distribution');
- if (canvas && pies) Plotly.plot(canvas, pies, {
- title: 'Entry distribution'
- });
- canvas = document.getElementById('plot_legs');
- if (canvas && legs) Plotly.plot(canvas, legs, {
- title: 'Average station to station time',
- yaxis: { title: 'Time', tickformat: '%H:%M:%S' }
- });
- canvas = document.getElementById('plot_speeds');
- if (canvas && speeds) Plotly.plot(canvas, speeds, {
- title: 'Average station to station speed',
- yaxis: { title: 'Speed (Ly/h)' }
- });
- canvas = document.getElementById('plot_laps');
- 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, {
- barmode: 'stack',
- title: 'Time raced',
- yaxis: { title: 'Time (s)' }
- });
- canvas = document.getElementById('plot_raced_days');
- if (canvas && raced_days) Plotly.plot(canvas, raced_days, {
- barmode: 'stack',
- title: 'Entries per day',
- xaxis: { tickformat: '%b %e' },
- yaxis: { title: 'Entries' }
- });
+ else {
+ for (var classification of document.getElementsByClassName('classification')) {
+ classification.addEventListener('dblclick', copy_classification, true);
+ }
+ for (var span of document.getElementsByTagName('span')) {
+ if (! span.classList.length) continue;
+ span.addEventListener('mouseenter', enter, true);
+ span.addEventListener('mouseleave', leave, true);
+ }
+ var canvas = document.getElementById('plot_timeline');
+ if (canvas && points) {
+ Plotly.plot(canvas, points, {
+ title: 'Competitor distance',
+ xaxis: { title: 'Time', autorange: true, rangemode: 'nonnegative', tickformat: '%H:%M:%S' },
+ yaxis: { title: 'Distance (Ly)', autorange: true, rangemode: 'nonnegative' }
+ });
+ }
+ canvas = document.getElementById('plot_distribution');
+ if (canvas && pies) Plotly.plot(canvas, pies, {
+ title: 'Entry distribution'
+ });
+ canvas = document.getElementById('plot_legs');
+ if (canvas && legs) Plotly.plot(canvas, legs, {
+ title: 'Average station to station time',
+ yaxis: { title: 'Time', tickformat: '%H:%M:%S' }
+ });
+ canvas = document.getElementById('plot_speeds');
+ if (canvas && speeds) Plotly.plot(canvas, speeds, {
+ title: 'Average station to station speed',
+ yaxis: { title: 'Speed (Ly/h)' }
+ });
+ canvas = document.getElementById('plot_laps');
+ 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, {
+ barmode: 'stack',
+ title: 'Time raced',
+ yaxis: { title: 'Time (s)' }
+ });
+ canvas = document.getElementById('plot_raced_days');
+ if (canvas && raced_days) Plotly.plot(canvas, raced_days, {
+ barmode: 'stack',
+ title: 'Entries per day',
+ xaxis: { tickformat: '%b %e' },
+ yaxis: { title: 'Entries' }
+ });
+ }
}
document.onload = loaded();
+++ /dev/null
-/* Set the background for a leg element. */
-function leg_background(classes, colour) {
- var changed = false;
- for (var c of classes) {
- for (var element of document.getElementsByClassName(c)) {
- if (! element.classList.contains('leg')) continue;
- element.style.backgroundColor = colour;
- changed = true;
- }
- }
- return changed;
-}
-
-/* Hover over an element. */
-function enter(event) {
- if (leg_background(event.target.classList, 'rgba(255, 100, 24, 0.4)')) {
- event.target.style.textDecoration = 'underline';
- }
-}
-
-/* Mouse out of an element. */
-function leave(event) {
- if (leg_background(event.target.classList, 'inherit')) {
- event.target.style.textDecoration = 'inherit';
- }
-}
-
-/* Document onload. */
-function loaded() {
- for (var span of document.getElementsByTagName('span')) {
- if (! span.classList.length) continue;
- span.addEventListener('mouseenter', enter, true);
- span.addEventListener('mouseleave', leave, true);
- }
- var canvas = document.getElementById('plot');
- if (canvas && points) {
- Plotly.plot(canvas, points, {
- title: 'Competitor distance',
- xaxis: { title: 'Time', autorange: true, rangemode: 'nonnegative', tickformat: '%H:%M:%S' },
- yaxis: { title: 'Distance (Ly)', autorange: true, rangemode: 'nonnegative' }
- });
- }
-}
-
-document.onload = loaded();