From ec48f3f1d9f0c91dbef27ffcefbb23d41a4beeb0 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Tue, 9 Feb 2016 10:08:41 -0500 Subject: [PATCH] Filter graphs correctly. --- lib/race.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/race.php b/lib/race.php index a20c789..35f83db 100644 --- a/lib/race.php +++ b/lib/race.php @@ -733,6 +733,7 @@ $lap_counts = array(); $lap_distances = array(); $time_raced = array(); + $filtered_entry_ids = array(); foreach ($filtered_entries as $entry) { $ship = $entry->getShip(); $cmdr_name = $ship->getCompetitor()->getCmdrName(); @@ -750,6 +751,7 @@ $lap_counts[$lap_count]++; if (! in_array($lap_distance, array_keys($lap_distances))) $lap_distances[$lap_distance] = 0; $lap_distances[$lap_distance]++; + $filtered_entry_ids[] = $entry->getId(); } $show_pies = false; if (count($cmdrs) > 1) { @@ -810,26 +812,27 @@ ) ); $raced_times = array(); + $entry_list = implode(",", $filtered_entry_ids); $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"); + /* Average station to station time. */ + $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 and entry.id in ($entry_list) group by station1, station2 order by delta"); $sth->execute(array(":race_id" => $id)); while ($row = $sth->fetch()) { $legs["leg_times"]["x"][] = sprintf("%s - %s", $row["station1"], $row["station2"]); $legs["leg_times"]["y"][] = "2000-01-01 " . format_time((int) $row["delta"]); } /* Average station to station speed. */ - $sth = $dbh->prepare("select s1.name as station1, s2.name as station2, avg((distance / (timestampdiff(second, l1.arrival, l2.arrival) / 3600))) as speed from laptime l1, laptime l2, station s1, station s2, lap, entry, course, raikogram 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 system1=(select case when s1.system_idprepare("select s1.name as station1, s2.name as station2, avg((distance / (timestampdiff(second, l1.arrival, l2.arrival) / 3600))) as speed from laptime l1, laptime l2, station s1, station s2, lap, entry, course, raikogram 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 system1=(select case when s1.system_idexecute(array(":race_id" => $id)); while ($row = $sth->fetch()) { $speeds["leg_speed"]["x"][] = sprintf("%s - %s", $row["station1"], $row["station2"]); $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 group by entry_id, lap_number) as aggregate_laps group by lap_number"); + //$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)); /* 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 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 = $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)); while ($row = $sth->fetch()) { $laps["fastest_laps"]["x"][] = "Lap " . $row["lap_number"]; -- 2.7.4