From d30b0d5d505ef3b57f8ec936ed1e2c8726b022f1 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Mon, 8 Feb 2016 11:58:28 -0500 Subject: [PATCH] Hide trivial graphs. --- lib/race.php | 67 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/lib/race.php b/lib/race.php index 71b04f8..6b97238 100644 --- a/lib/race.php +++ b/lib/race.php @@ -751,26 +751,39 @@ if (! in_array($lap_distance, array_keys($lap_distances))) $lap_distances[$lap_distance] = 0; $lap_distances[$lap_distance]++; } - foreach ($cmdrs as $cmdr_name => $count) { - $plots["cmdr"]["values"][] = $count; - $plots["cmdr"]["labels"][] = $cmdr_name; + $show_pies = false; + if (count($cmdrs) > 1) { + $show_pies = true; + foreach ($cmdrs as $cmdr_name => $count) { + $plots["cmdr"]["values"][] = $count; + $plots["cmdr"]["labels"][] = $cmdr_name; + } + $plots["cmdr"]["pull"] = pull($plots["cmdr"]["values"]); } - $plots["cmdr"]["pull"] = pull($plots["cmdr"]["values"]); - foreach ($hulls as $hull_name => $count) { - $plots["hull"]["values"][] = $count; - $plots["hull"]["labels"][] = $hull_name; + if (count($hulls) > 1) { + $show_pies = true; + foreach ($hulls as $hull_name => $count) { + $plots["hull"]["values"][] = $count; + $plots["hull"]["labels"][] = $hull_name; + } + $plots["hull"]["pull"] = pull($plots["hull"]["values"]); } - $plots["hull"]["pull"] = pull($plots["hull"]["values"]); - foreach ($lap_counts as $lap_count => $count) { - $plots["lap_count"]["values"][] = $count; - $plots["lap_count"]["labels"][] = $lap_count; + if (count($lap_counts) > 1) { + $show_pies = true; + foreach ($lap_counts as $lap_count => $count) { + $plots["lap_count"]["values"][] = $count; + $plots["lap_count"]["labels"][] = $lap_count; + } + $plots["lap_count"]["pull"] = pull($plots["lap_count"]["values"]); } - $plots["lap_count"]["pull"] = pull($plots["lap_count"]["values"]); - foreach ($lap_distances as $lap_distance => $count) { - $plots["lap_distance"]["values"][] = $count; - $plots["lap_distance"]["labels"][] = $lap_distance; + if (count($lap_distances) > 1) { + $show_pies = true; + foreach ($lap_distances as $lap_distance => $count) { + $plots["lap_distance"]["values"][] = $count; + $plots["lap_distance"]["labels"][] = $lap_distance; + } + $plots["lap_distance"]["pull"] = pull($plots["lap_distance"]["values"]); } - $plots["lap_distance"]["pull"] = pull($plots["lap_distance"]["values"]); $legs = array( "leg_times" => array( @@ -796,9 +809,7 @@ "type" => "bar" ) ); - $raced_times = array( - "raced_times" => array() - ); + $raced_times = array(); $dbh = Propel::getConnection(); /* Average station to station speed. */ $sth = $dbh->prepare("select s1.name as station1, s2.name as station2, avg(timestampdiff(second, l1.arrival, l2.arrival)) as delta from laptime l1, laptime l2, station s1, station s2, lap, entry, course where l1.lap_id=l2.lap_id and l1.station_id=s1.id and l2.station_id=s2.id and l1.lap_id=lap.id and lap.entry_id=entry.id and course.race_id=entry.race_id and l2.station_order=l1.station_order+1 and entry.race_id=:race_id group by station1, station2 order by delta"); @@ -825,24 +836,24 @@ $laps["fastest_laps"]["y"][] = (int) $row["n"]; } uasort($time_raced, "by_raced"); - $raced_times_bars = array(); foreach ($time_raced as $cmdr_name => $times) { for ($n = 0; $n < count($times); $n++) { $time = (int) $times[$n]; - if (count($raced_times_bars) <= $n) $raced_times_bars[] = array("x" => array(), "y" => array(), "name" => "Entry " . ($n + 1), "text" => array(), "type" => "bar"); - $raced_times_bars[$n]["x"][] = $cmdr_name; - $raced_times_bars[$n]["y"][] = $time; - $raced_times_bars[$n]["text"][] = format_time($time); + if (count($raced_times) <= $n) $raced_times[] = array("x" => array(), "y" => array(), "name" => "Entry " . ($n + 1), "text" => array(), "type" => "bar"); + $raced_times[$n]["x"][] = $cmdr_name; + $raced_times[$n]["y"][] = $time; + $raced_times[$n]["text"][] = format_time($time); } } - $raced_times = $raced_times_bars; /* Time raced. */ echo "\n"; } echo "
\n"; -- 2.7.4