Skip to content

Commit a7d66f1

Browse files
committed
ran pre-commit on rta (#1592)
1 parent 6329430 commit a7d66f1

File tree

10 files changed

+238
-341
lines changed

10 files changed

+238
-341
lines changed

realizable_transit_accessibility/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
5. Obtain the output from the output path provided
88

99
### Testing
10-
This project contains automated tests using pytest. From this directory, run `poetry run pytest` to run tests.
10+
This project contains automated tests using pytest. From this directory, run `poetry run pytest` to run tests.

realizable_transit_accessibility/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ line-length = 120
4141

4242
[tool.poetry.group.dev.dependencies]
4343
black = "24.10.0"
44-
pytest = "^7.2.1"
44+
pytest = "^7.2.1"

realizable_transit_accessibility/retrospective_feed_generation/columns.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Rename these values if column names change in the schedule/rt dataset
2-
# Scheduled arrival time, in seconds after twelve hours before noon
2+
# Scheduled arrival time, in seconds after twelve hours before noon
33
SCHEDULE_ARRIVAL_SEC_NAME = "scheduled_arrival_sec"
44
# RT arrival time, in seconds after twelve hours before noon
55
RT_ARRIVAL_SEC_NAME = "rt_arrival_sec"
@@ -22,7 +22,7 @@
2222
TRIP_INSTANCE_KEY_NAME,
2323
TRIP_ID_NAME,
2424
STOP_ID_NAME,
25-
SCHEDULE_GTFS_DATASET_KEY_NAME
25+
SCHEDULE_GTFS_DATASET_KEY_NAME,
2626
]
2727

2828
RT_ARRIVAL_SEC = "rt_arrival_sec"
@@ -50,5 +50,5 @@
5050
TRIP_INSTANCE_KEY: TRIP_INSTANCE_KEY_NAME,
5151
TRIP_ID: TRIP_ID_NAME,
5252
STOP_ID: STOP_ID_NAME,
53-
SCHEDULE_GTFS_DATASET_KEY: SCHEDULE_GTFS_DATASET_KEY_NAME
53+
SCHEDULE_GTFS_DATASET_KEY: SCHEDULE_GTFS_DATASET_KEY_NAME,
5454
}

realizable_transit_accessibility/retrospective_feed_generation/gtfs_utils.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from gtfslite import GTFS
2-
import pandas as pd
3-
import datetime as dt
4-
from .constants import ARBITRARY_SERVICE_ID, GTFS_DATE_STRFTIME
51
import copy
2+
import datetime as dt
3+
64
import numpy as np
5+
import pandas as pd
6+
from gtfslite import GTFS
7+
8+
from .constants import ARBITRARY_SERVICE_ID, GTFS_DATE_STRFTIME
79

810

911
def subset_schedule_feed_to_one_date(feed: GTFS, service_date: dt.datetime) -> GTFS:
1012
"""Update a gtfslite feed object to only contain service on a specified service date"""
11-
assert feed.valid_date(
12-
service_date
13-
), f"Feed not valid on {service_date.isoformat()}"
13+
assert feed.valid_date(service_date), f"Feed not valid on {service_date.isoformat()}"
1414
# Define a new calendar dates, since the synthetic feed will only be valid on the service date
1515
new_calendar_dates = pd.DataFrame(
1616
{
@@ -25,9 +25,7 @@ def subset_schedule_feed_to_one_date(feed: GTFS, service_date: dt.datetime) -> G
2525
trips_on_service_date["service_id"] = ARBITRARY_SERVICE_ID
2626
# Get only stop_times on the calendar date
2727
stop_times_on_service_date = feed.stop_times.loc[
28-
feed.stop_times["trip_id"].isin(
29-
trips_on_service_date["trip_id"]
30-
) # check if this is slow
28+
feed.stop_times["trip_id"].isin(trips_on_service_date["trip_id"]) # check if this is slow
3129
].reset_index(drop=True)
3230
# TODO: evaluate whether it is necessary to remove stops, shapes, and transfers that do not have service
3331
# TODO: add any additional behavior for feeds with frequencies.txt
@@ -48,30 +46,22 @@ def time_string_to_time_since_midnight(time_str_series: pd.Series) -> pd.Series:
4846
Will give incorrect results on days where a DST transition occurs.
4947
"""
5048
return time_str_series.str.split(":").map(
51-
lambda s: (
52-
int(s[0]) * 3600 + int(s[1]) * 60 + int(s[2]) if len(s) == 3 else np.nan
53-
)
49+
lambda s: (int(s[0]) * 3600 + int(s[1]) * 60 + int(s[2]) if len(s) == 3 else np.nan)
5450
)
5551

5652

5753
DEFAULT_SERVICE_DAY_START_SECONDS = 86400
5854

5955

60-
def seconds_to_gtfs_format_time(
61-
time_column: pd.Series, trip_id_column: pd.Series
62-
) -> pd.Series:
56+
def seconds_to_gtfs_format_time(time_column: pd.Series, trip_id_column: pd.Series) -> pd.Series:
6357
"""Convert time in seconds since midnight (from the warehouse) to gtfs format time"""
6458
# TODO: this will not handle dst correctly
6559
# Get all times as positive times since midnight
6660
absolute_time_relative_to_midnight = time_column.where(
6761
time_column > 0, DEFAULT_SERVICE_DAY_START_SECONDS + time_column
6862
)
6963
# Get the first time of each trip
70-
first_time = (
71-
absolute_time_relative_to_midnight.groupby(trip_id_column)
72-
.first()
73-
.rename("first_time")
74-
)
64+
first_time = absolute_time_relative_to_midnight.groupby(trip_id_column).first().rename("first_time")
7565
# Merge trips with the last times
7666
trips_merged_with_first_times = pd.concat(
7767
[
@@ -87,13 +77,9 @@ def seconds_to_gtfs_format_time(
8777
validate="many_to_one",
8878
)
8979
# Get the "GTFS Time" seconds by allowing
90-
trips_merged_with_first_times["gtfs_time_seconds"] = trips_merged_with_first_times[
91-
"midnight_time"
92-
].where(
93-
trips_merged_with_first_times["midnight_time"]
94-
>= trips_merged_with_first_times["first_time"],
95-
trips_merged_with_first_times["midnight_time"]
96-
+ DEFAULT_SERVICE_DAY_START_SECONDS,
80+
trips_merged_with_first_times["gtfs_time_seconds"] = trips_merged_with_first_times["midnight_time"].where(
81+
trips_merged_with_first_times["midnight_time"] >= trips_merged_with_first_times["first_time"],
82+
trips_merged_with_first_times["midnight_time"] + DEFAULT_SERVICE_DAY_START_SECONDS,
9783
)
9884

9985
trips_merged_with_first_times["hours"] = (

0 commit comments

Comments
 (0)