TheTransitClock / transitime

TheTransitClock real-time transit information system
GNU General Public License v3.0
78 stars 30 forks source link

Coefficient of variation of headway graph (real-time and historical) #13

Open scrudden opened 6 years ago

scrudden commented 6 years ago

Create a graph which shows the coefficient of variation of headway in real-time for a route. This is the measure which can be used to look at the stability of a route.

scrudden commented 6 years ago

They system current calculates the headway of a vehicle when it arrives at a stop and then used this value along with the headway of all other vehicles to calculate to the coefficient of variation. These values are stored in Headway table. They are being set in

org.transitime.core.headwaygenerator.LastArrivalsHeadwayGenerator

This class needs to only included headway's for the current route in the calculation of the coefficient of variation. For Dynamic time trials this did not matter as they where on a single route.

scrudden commented 6 years ago

This will require two graphs one for real-time and one based on a start and end time.

scrudden commented 6 years ago

Code is on this branch. https://github.com/TheTransitClock/transitime/tree/tc_issue_13

scrudden commented 6 years ago

Now records number of vehicles on route as well as number with headway set in vehiclestate.

scrudden commented 6 years ago

image

First go at this. Need to smooth. It only plots values that where generated when each vehicle on the route has a valid headway.

scrudden commented 6 years ago

This is a smoothed version running this sql. It uses a running average (1800 seconds) and takes a sample every 10 minutes.

select max(avg), minutes from 
(
SELECT cast (extract(minute from h1.creationtime)+ extract(hour from h1.creationtime) * 60 as int) as minutes,
avg(h2.coefficientofvariation) as avg
FROM public.headway h1 JOIN public.headway h2 
ON h2.creationtime >= h1.creationtime - interval '1800 second'
AND h2.creationtime <= h1.creationtime  
AND  h1.routeid='12' AND h1.routeid=h2.routeid  AND h2.coefficientofvariation> 0 
AND h2.numvehiclesonroute=h2.numvehicles AND h1.creationtime BETWEEN '11-15-2017'  
AND TIMESTAMP '11-15-2017' + INTERVAL '1 day'   group by h1.creationtime 
ORDER BY  h1.creationtime
) hwc1
WHERE hwc1.minutes % 10 =0
GROUP BY minutes

image

scrudden commented 6 years ago

Revised based on comments from @simonberrebi. Now goes to two decimal places and using a line.

image