Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update pipeline to use trip_id as unique key #160

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ def trips_for_metrics_subquery(
sa.func.lead(rt_trips_sub.c.vp_move_timestamp)
.over(
partition_by=rt_trips_sub.c.vehicle_id,
order_by=sa.func.coalesce(
rt_trips_sub.c.vp_move_timestamp,
rt_trips_sub.c.vp_stop_timestamp,
rt_trips_sub.c.tu_stop_timestamp,
),
order_by=rt_trips_sub.c.vp_move_timestamp,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this change necessary as well if we're running the VACUUM?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change wasn't necessary, but looking at the field that's being calculated, and how it's used. I don't believe the coalesce is needed.

I think this business logic was a little bit of a hold over from before Ops Analytics decided they wanted all headways as departure to departure calculations.

)
.label("next_station_move"),
)
Expand Down
6 changes: 5 additions & 1 deletion python_src/src/lamp_py/postgres/postgres_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ def truncate_table(
truncate_query = f"{truncate_query} CASCADE"

self.execute(sa.text(f"{truncate_query};"))
self.execute(sa.text(f"ANALYZE {truncat_as};"))

# Execute VACUUM to avoid non-deterministic behavior during testing
with self.session.begin() as cursor:
cursor.execute(sa.text("END TRANSACTION;"))
cursor.execute(sa.text(f"VACUUM (ANALYZE) {truncat_as};"))

def add_metadata_paths(self, paths: List[str]) -> None:
"""
Expand Down
Loading