Skip to content

Commit

Permalink
FEAT: Remove Commuter Rail data from exports (#325)
Browse files Browse the repository at this point in the history
This change removes commuter rain data from flat file and OPMI ALL_RT export files.

As tested on STAGING, these changes have no significant impact on query duration.

flat file query remained constant at ~4 seconds, for one service_date

ALL_RT query stayed at ~12 seconds, for one service_date

Asana Task: https://app.asana.com/0/1205827492903547/1207059327607966
  • Loading branch information
rymarczy authored May 1, 2024
1 parent 307ef31 commit 46614e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/lamp_py/performance_manager/flat_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
VehicleTrips,
StaticStopTimes,
StaticStops,
StaticRoutes,
TempEventCompare,
)
from lamp_py.postgres.postgres_utils import DatabaseManager
Expand All @@ -40,7 +41,7 @@ class S3Archive:
)
INDEX_FILENAME = "index.csv"
VERSION_KEY = "rpm_version"
RPM_VERSION = "1.0.0"
RPM_VERSION = "1.1.0"


def dates_to_update(db_manager: DatabaseManager) -> Set[datetime]:
Expand Down Expand Up @@ -320,6 +321,7 @@ def write_daily_table(
static_subquery.c.scheduled_headway_branch,
static_subquery.c.scheduled_headway_trunk,
)
.select_from(VehicleEvents)
.join(VehicleTrips, VehicleEvents.pm_trip_id == VehicleTrips.pm_trip_id)
.join(
static_subquery,
Expand All @@ -330,8 +332,18 @@ def write_daily_table(
),
isouter=True,
)
.join(
StaticRoutes,
sa.and_(
VehicleTrips.route_id == StaticRoutes.route_id,
VehicleTrips.static_version_key
== StaticRoutes.static_version_key,
),
)
.where(
VehicleEvents.service_date == service_date_int,
VehicleTrips.static_version_key == static_version_key,
StaticRoutes.route_type < 2,
sa.or_(
VehicleEvents.vp_move_timestamp.is_not(None),
VehicleEvents.vp_stop_timestamp.is_not(None),
Expand Down
10 changes: 8 additions & 2 deletions src/lamp_py/tableau/jobs/rt_rail.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self) -> None:
self,
hyper_file_name="LAMP_ALL_RT_fields.hyper",
remote_parquet_path=f"s3://{os.getenv('PUBLIC_ARCHIVE_BUCKET')}/lamp/tableau/rail/LAMP_ALL_RT_fields.parquet",
lamp_version="1.1.1",
lamp_version="1.1.2",
)
self.table_query = (
"SELECT"
Expand Down Expand Up @@ -90,8 +90,14 @@ def __init__(self) -> None:
" ON "
" prev_ve.stop_id = prev_ss.stop_id"
" AND vt.static_version_key = prev_ss.static_version_key"
" LEFT JOIN "
" static_routes sr"
" ON "
" vt.route_id = sr.route_id"
" AND vt.static_version_key = sr.static_version_key"
" WHERE "
" ("
" sr.route_type < 2"
" AND ("
" ve.canonical_stop_sequence > 1"
" OR ve.canonical_stop_sequence IS NULL"
" )"
Expand Down

0 comments on commit 46614e0

Please sign in to comment.