Convert myway timeliness visualisations to new GTFS feed
Convert myway timeliness visualisations to new GTFS feed

--- a/myway/index.php
+++ b/myway/index.php
@@ -16,7 +16,7 @@
  */
 include ('../include/common.inc.php');
 
-include_header("Busness R&D", "index");
+include_header("MyWay Balance and Timeliness Survey Results", "index");
 if ($_SESSION['authed'] == true) {
     echo '<ul data-role="listview" data-theme="e" data-groupingtheme="e">
 		<li data-role="list-divider" > Admin Features </li>
@@ -35,6 +35,9 @@
 <ul data-role="listview" data-theme="e" data-groupingtheme="e">
 
     <li data-role="list-divider" > MyWay Timeliness Graphs </li>
+    
+    <li><a href="myway_timeliness_overview.php"><h3>Timeliness Overview</h3>
+            <p>Displays statistics on timeliness split by day/time/month/stop etc.</p></a></li>
     <li><a href="myway_timeliness.php"><h3>Timeliness over Day</h3>
             <p>Displays the deviation from the timetable over the day</p></a></li>
     <li><a href="myway_timeliness_freqdist.php"><h3>Frequency Distribution of Time Deviation</h3>

--- a/myway/myway_timeliness.php
+++ b/myway/myway_timeliness.php
@@ -30,7 +30,7 @@
         var midnight = d.getTime();
 
 <?php
-$query = "select * from myway_timingdeltas where abs(timing_delta) < 2*(select stddev(timing_delta) from myway_timingdeltas)  order by route_full_name;";
+$query = "select * from myway_timingdeltas where abs(timing_delta) < 2*(select stddev(timing_delta) from myway_timingdeltas) order by route_name;";
 $query = $conn->prepare($query);
 $query->execute();
 if (!$query) {
@@ -41,11 +41,12 @@
 $labels = Array();
 $lastRoute = "";
 foreach ($query->fetchAll() as $delta) {
-    $routeName = $delta['route_full_name'];
-    if (strstr($routeName, " 3"))
+    $routeName = $delta['route_name'];
+    if (preg_match('/z/',$routeName)) {
         $routeName = "312-319";
-    else
+    } else {
         $routeName = preg_replace('/\D/', '', $routeName);
+    }
     if ($routeName != $lastRoute) {
         $i++;
         echo "    var d$i = [];";
@@ -78,7 +79,7 @@
             yaxis: {
                 tickFormatter: yformatter
             },
-            grid: { hoverable: true, clickable: true, labelMargin: 32   },
+            grid: { hoverable: true, clickable: true, labelMargin: 32   }
         });
         var o;
         o = plot.pointOffset({ x: midnight+ (9*60*60*1000), y: -1.2});

--- a/myway/myway_timeliness_calculate.php
+++ b/myway/myway_timeliness_calculate.php
@@ -108,6 +108,7 @@
                                 "timeDiff" => $timeDiff,
                                 "stop_id" => $potentialStop['stop_id'],
                                 "stop_sequence" => $trip['stop_sequence'],
+                                "route_name" => "{$potentialRoute['route_short_name']} {$potentialRoute['route_long_name']}",
                                 "route_id" => $trip['route_id']
                             );
                             echo "Found trip {$trip['trip_id']} at stop {$potentialStop['stop_id']} (#{$potentialStop['stop_name']}, sequence #{$trip['stop_sequence']})<br>";
@@ -130,17 +131,25 @@
     usort($timeDeltas, "abssort");
     $lowestDelta = $timeDeltas[0]["timeDiff"];
     if (sizeof($timeDeltas) != 0) {
+        if (abs($lowestDelta) > 9999) {
+             echo "Difference of " . round($lowestDelta / 60, 2) . " minutes is too high. Will not record this observation<br>";
+        } else {
         echo "Lowest difference of " . round($lowestDelta / 60, 2) . " minutes will be recorded for this observation<br>";
         
         $observation_id = $obsv['observation_id'];
+        
+        $route_name = $timeDeltas[0]["route_name"];
         $route_id = $timeDeltas[0]["route_id"];
         $stop_id = $timeDeltas[0]["stop_id"];
+        $myway_stop = $obsv["myway_stop"];
         $stop_sequence = $timeDeltas[0]["stop_sequence"];
-        $stmt = $conn->prepare("insert into myway_timingdeltas (observation_id, route_id, stop_id, timing_delta, time, date, timing_period, stop_sequence)
-				      values (:observation_id, :route_id, :stop_id, :timing_delta, :time, :date, :timing_period, :stop_sequence)");
+        $stmt = $conn->prepare("insert into myway_timingdeltas (observation_id, route_id, stop_id, timing_delta, time, date, timing_period, stop_sequence,myway_stop,route_name)
+				      values (:observation_id, :route_id, :stop_id, :timing_delta, :time, :date, :timing_period, :stop_sequence,:myway_stop,:route_name)");
         $stmt->bindParam(':observation_id', $observation_id);
         $stmt->bindParam(':route_id', $route_id);
+        $stmt->bindParam(':route_name', $route_name);
         $stmt->bindParam(':stop_id', $stop_id);
+        $stmt->bindParam(':myway_stop', $myway_stop);
         $stmt->bindParam(':timing_delta', $lowestDelta);
         $stmt->bindParam(':time', $time_tz);
         $stmt->bindParam(':date', $date);
@@ -153,6 +162,7 @@
         }
         var_dump($conn->errorInfo());
         flush();
+        }
     }
     flush();
 }

--- a/myway/myway_timeliness_overview.php
+++ b/myway/myway_timeliness_overview.php
@@ -77,8 +77,7 @@
 
     <th>Stop </th>
     <?php
-    $query = "select myway_stop, avg(timing_delta), stddev(timing_delta), count(*)  from myway_timingdeltas INNER JOIN myway_observations
-ON myway_observations.observation_id=myway_timingdeltas.observation_id group by myway_stop having  count(*) > 1 order by myway_stop";
+    $query = "select myway_stop, avg(timing_delta), stddev(timing_delta), count(*)  from myway_timingdeltas group by myway_stop having  count(*) > 1 order by myway_stop";
     $query = $conn->prepare($query);
     $query->execute();
     if (!$query) {
@@ -91,7 +90,7 @@
     ?>
     <th>Route </th>
     <?php
-    $query = "select route_full_name, avg(timing_delta), stddev(timing_delta), count(*) from myway_timingdeltas  group by route_full_name having  count(*) > 1 order by route_full_name";
+    $query = "select route_name, avg(timing_delta), stddev(timing_delta), count(*) from myway_timingdeltas  group by route_name having  count(*) > 1 order by route_name";
     $query = $conn->prepare($query);
     $query->execute();
     if (!$query) {

--- a/myway/myway_timeliness_route.json.php
+++ b/myway/myway_timeliness_route.json.php
@@ -23,9 +23,9 @@
 {
 "label": "<?php echo $_REQUEST['routeid']; ?>",
 "data": <?php
-$query = "select * from myway_timingdeltas where route_full_name = :route_full_name AND abs(timing_delta) < 2*(select stddev(timing_delta) from myway_timingdeltas)  order by stop_sequence;";
+$query = "select * from myway_timingdeltas where route_name = :route_name AND abs(timing_delta) < 2*(select stddev(timing_delta) from myway_timingdeltas)  order by stop_sequence;";
 $query = $conn->prepare($query);
-$query->bindParam(':route_full_name', $_REQUEST['routeid'], PDO::PARAM_STR, 42);
+$query->bindParam(':route_name', $_REQUEST['routeid'], PDO::PARAM_STR, 42);
 
 $query->execute();
 if (!$query) {

--- a/myway/myway_timeliness_route.php
+++ b/myway/myway_timeliness_route.php
@@ -24,7 +24,7 @@
 <form method="get" action="">
     <select id="routeid" name="routeid">
         <?php
-        $query = "select distinct route_full_name from myway_routes where myway_route != '' order by route_full_name";
+        $query = "select distinct route_name from myway_timingdeltas order by route_name";
         $query = $conn->prepare($query);
         $query->execute();
         if (!$query) {
@@ -32,7 +32,7 @@
             return Array();
         }
         foreach ($query->fetchAll() as $route) {
-            echo "<option value=\"{$route['route_full_name']}\">{$route['route_full_name']}</option>";
+            echo "<option value=\"{$route['route_name']}\">{$route['route_name']}</option>";
         };
         ?>    </select>
     <center><div id="placeholder" style="width:900px;height:550px"></div></center>

--- a/myway/myway_timeliness_stop.json.php
+++ b/myway/myway_timeliness_stop.json.php
@@ -23,11 +23,10 @@
 {
 "label": "<?php echo $_REQUEST['stopid']; ?>",
 "data": <?php
-$query = "select * from myway_timingdeltas INNER JOIN myway_observations
-ON myway_observations.observation_id=myway_timingdeltas.observation_id
+$query = "select * from myway_timingdeltas
    where myway_stop = :myway_stop
    AND abs(timing_delta) < 2*(select stddev(timing_delta) from myway_timingdeltas)
-   order by myway_timingdeltas.time;";
+   order by time;";
 $query = $conn->prepare($query);
 $query->bindParam(':myway_stop', $_REQUEST['stopid'], PDO::PARAM_STR, 42);
 

--- a/myway/myway_timeliness_stop.php
+++ b/myway/myway_timeliness_stop.php
@@ -24,7 +24,7 @@
 <form method="get" action="">
     <select id="stopid" name="stopid">
         <?php
-        $query = "select distinct myway_stop from myway_stops where myway_stop != '' order by myway_stop";
+        $query = "select distinct myway_stop from myway_timingdeltas where myway_stop != '' order by myway_stop";
         $query = $conn->prepare($query);
         $query->execute();
         if (!$query) {