Skip to content

Commit

Permalink
add stop id remap function
Browse files Browse the repository at this point in the history
  • Loading branch information
hamima-halim committed May 9, 2024
1 parent 7fef4a3 commit 7074a73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions mbta-performance/chalicelib/lamp/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@
"scheduled_headway",
"scheduled_headway_branch",
]


# Live data will sometimes report an aliased version of stop_id different
# from that which GTFS reports in its schedule. These are the known id's.
STOP_ID_NUMERIC_MAP = {
"Forest Hills-01": "70001",
"Forest Hills-02": "70001",
"Braintree-01": "70105",
"Braintree-02": "70105",
"Oak Grove-01": "70036",
"Oak Grove-02": "70036",
"Union Square-01": "70504",
"Union Square-02": "70504",
}
5 changes: 4 additions & 1 deletion mbta-performance/chalicelib/lamp/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests
from typing import Iterable, Tuple

from .constants import LAMP_COLUMNS, S3_COLUMNS
from .constants import LAMP_COLUMNS, S3_COLUMNS, STOP_ID_NUMERIC_MAP
from ..date import format_dateint, get_current_service_date
from mbta_gtfs_sqlite import MbtaGtfsArchive
from mbta_gtfs_sqlite.models import StopTime, Trip
Expand Down Expand Up @@ -207,6 +207,9 @@ def ingest_pq_file(pq_df: pd.DataFrame, service_date: date) -> pd.DataFrame:
# use trunk headway metrics as default, and add branch metrics when it makes sense.
# TODO: verify and recalculate headway metrics if necessary!
pq_df = pq_df.rename(columns=COLUMN_RENAME_MAP)
# Live data will sometimes report an aliased version of stop_id different
# from that which GTFS reports in its schedule. Replace for better schedule matching.
pq_df["stop_id"] = pq_df["stop_id"].replace(STOP_ID_NUMERIC_MAP)
# drop non-revenue producing events
pq_df = pq_df[~pq_df["trip_id"].str.startswith(TRIP_IDS_TO_DROP)]

Expand Down

0 comments on commit 7074a73

Please sign in to comment.