brnstz / bus

Mobile web app for discovering public transit in NYC --
https://token.live
MIT License
5 stars 2 forks source link

Debug discrepancy between live and scheduled trip ids #29

Closed brnstz closed 8 years ago

brnstz commented 8 years ago

Live departures for buses are showing trip_ids with "SDon" but scheduled departures don't have this string. Both trip_ids exist in the db. But why are they different? Example:

        {
            "departures": {
                "live": [
                    {
                        "time": "2016-05-13T14:29:38.67-04:00",
                        "trip_id": "EN_B6-Weekday-SDon-078100_B15_146"
                    },
                    {
                        "time": "2016-05-13T14:30:57.723-04:00",
                        "trip_id": "EN_B6-Weekday-SDon-078800_B15_147"
                    },
                    {
                        "time": "2016-05-13T14:47:39.743-04:00",
                        "trip_id": "EN_B6-Weekday-SDon-079500_B15_135"
                    },
                    {
                        "time": "2016-05-13T14:49:14.428-04:00",
                        "trip_id": "EN_B6-Weekday-SDon-080200_B15_141"
                    },
                    {
                        "time": "2016-05-13T14:54:07.009-04:00",
                        "trip_id": "EN_B6-Weekday-SDon-080900_B12_8"
                    }
                ],
                "scheduled": [
                    {
                        "time": "2016-05-13T14:19:00-04:00",
                        "trip_id": "EN_B6-Weekday-077400_B15_121"
                    },
                    {
                        "time": "2016-05-13T14:26:00-04:00",
                        "trip_id": "EN_B6-Weekday-078100_B15_146"
                    },
                    {
                        "time": "2016-05-13T14:33:00-04:00",
                        "trip_id": "EN_B6-Weekday-078800_B15_147"
                    },
                    {
                        "time": "2016-05-13T14:40:00-04:00",
                        "trip_id": "EN_B6-Weekday-079500_B15_135"
                    },
                    {
                        "time": "2016-05-13T14:47:00-04:00",
                        "trip_id": "EN_B6-Weekday-080200_B15_141"
                    }
                ]
            },
            "dist": 2342.815458066106,
            "id": "B15_901017",
            "route": {
                "agency_id": "MTA NYCT",
                "route_color": "#B933AD",
                "route_id": "B15",
                "route_text_color": "#FFFFFF",
                "route_type": 3,
                "route_type_name": "bus"
            },
            "stop": {
                "agency_id": "MTA NYCT",
                "direction_id": 1,
                "headsign": "BED-STUY WOODHULL HOSP",
                "lat": 40.699776,
                "lon": -73.941505,
                "route_id": "B15",
                "stop_id": "901017",
                "stop_name": "MARCUS GARVEY BL/BROADWAY"
            }
        },
brnstz commented 8 years ago

This appears to be an issue with overlapping start/end dates. We prefer to get the service with the most recent start date, but the live API isn't returning that one:

bseitz=# select * from service_route_day where service_id = 'JG_B6-Weekday' and route_id = 'B67';
 agency_id | route_id |  service_id   |    day    | start_date |  end_date
-----------+----------+---------------+-----------+------------+------------
 MTA NYCT  | B67      | JG_B6-Weekday | friday    | 2016-04-25 | 2016-06-29
 MTA NYCT  | B67      | JG_B6-Weekday | monday    | 2016-04-25 | 2016-06-29
 MTA NYCT  | B67      | JG_B6-Weekday | tuesday   | 2016-04-25 | 2016-06-29
 MTA NYCT  | B67      | JG_B6-Weekday | wednesday | 2016-04-25 | 2016-06-29
 MTA NYCT  | B67      | JG_B6-Weekday | thursday  | 2016-04-25 | 2016-06-29
(5 rows)

bseitz=#
bseitz=#
bseitz=# select * from service_route_day where service_id = 'JG_B6-Weekday-SDon' and route_id = 'B67';
 agency_id | route_id |     service_id     |    day    | start_date |  end_date
-----------+----------+--------------------+-----------+------------+------------
 MTA NYCT  | B67      | JG_B6-Weekday-SDon | monday    | 2016-04-04 | 2016-07-01
 MTA NYCT  | B67      | JG_B6-Weekday-SDon | tuesday   | 2016-04-04 | 2016-07-01
 MTA NYCT  | B67      | JG_B6-Weekday-SDon | wednesday | 2016-04-04 | 2016-07-01
 MTA NYCT  | B67      | JG_B6-Weekday-SDon | thursday  | 2016-04-04 | 2016-07-01
 MTA NYCT  | B67      | JG_B6-Weekday-SDon | friday    | 2016-04-04 | 2016-07-01