Skip to content

Commit

Permalink
Rename origin_dep_time to orig_dep_date and hint correct type
Browse files Browse the repository at this point in the history
  • Loading branch information
gsarrco committed Oct 1, 2023
1 parent 94b5ad4 commit 6537895
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions MuoVErsi/sources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ def __init__(self, stop: Station, origin_id, dep_time: datetime | None, stop_seq
trip_id,
route_name,
arr_time: datetime = None,
origin_dep_time: int = None, destination: str = None):
orig_dep_date: date = None, destination: str = None):
if arr_time is None:
arr_time = dep_time
super().__init__(stop, dep_time, arr_time, stop_sequence, delay, platform, headsign, trip_id, route_name)
self.origin_dep_time = origin_dep_time
self.orig_dep_date = orig_dep_date
self.destination = destination
self.origin_id = origin_id

Expand Down Expand Up @@ -342,11 +342,11 @@ def upload_trip_stop_times_to_postgres(self, stop_times: list[TripStopTime]):
for stop_time in stop_times:
train = self.session.query(Trip).filter_by(orig_id=stop_time.origin_id,
number=stop_time.trip_id,
orig_dep_date=stop_time.origin_dep_time).first()
orig_dep_date=stop_time.orig_dep_date).first()

if not train:
train = Trip(orig_id=stop_time.origin_id, dest_text=stop_time.destination,
number=stop_time.trip_id, orig_dep_date=stop_time.origin_dep_time,
number=stop_time.trip_id, orig_dep_date=stop_time.orig_dep_date,
route_name=stop_time.route_name)
self.session.add(train)
self.session.commit()
Expand Down
20 changes: 10 additions & 10 deletions MuoVErsi/sources/trenitalia.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ def get_stop_times_from_station(self, station) -> list[TripStopTime]:

departures_arrivals = departures + arrivals

# merge departures and arrivals StopTime when they have the same trip_id and origin_dep_time
departures_arrivals.sort(key=lambda x: (x.trip_id, x.origin_dep_time))
# merge departures and arrivals StopTime when they have the same trip_id and orig_dep_date
departures_arrivals.sort(key=lambda x: (x.trip_id, x.orig_dep_date))
merged = []
for i, stop_time in enumerate(departures_arrivals):
if i == 0:
merged.append(stop_time)
else:
if stop_time.trip_id == merged[-1].trip_id and stop_time.origin_dep_time == merged[-1].origin_dep_time:
if stop_time.trip_id == merged[-1].trip_id and stop_time.orig_dep_date == merged[-1].orig_dep_date:
if stop_time.dep_time:
stop_time.merge(merged[-1])
else:
Expand Down Expand Up @@ -121,7 +121,7 @@ def get_stop_times(self, stop: Station, line, start_time, day,
Trip.orig_id.label('origin_id'),
Trip.dest_text.label('destination'),
Trip.number.label('trip_id'),
Trip.orig_dep_date.label('origin_dep_time'),
Trip.orig_dep_date.label('orig_dep_date'),
StopTime.platform.label('platform'),
Trip.route_name.label('route_name')
)
Expand Down Expand Up @@ -160,7 +160,7 @@ def get_stop_times(self, stop: Station, line, start_time, day,
stop_time = TripStopTime(stop, raw_stop_time.origin_id, dep_time, None, 0, raw_stop_time.platform,
raw_stop_time.destination, raw_stop_time.trip_id,
raw_stop_time.route_name, arr_time=arr_time,
origin_dep_time=raw_stop_time.origin_dep_time)
orig_dep_date=raw_stop_time.orig_dep_date)
stop_times.append(stop_time)

return stop_times
Expand Down Expand Up @@ -252,14 +252,14 @@ def get_stop_times_from_start_dt(self, type, stop: Station, start_dt: datetime,
if departure[f'binarioEffettivo{type_text}Descrizione'] != '':
platform = departure[f'binarioEffettivo{type_text}Descrizione']

origin_dep_time = datetime.fromtimestamp(departure['dataPartenzaTreno'] / 1000) if departure[
orig_dep_date = datetime.fromtimestamp(departure['dataPartenzaTreno'] / 1000).date() if departure[
'dataPartenzaTreno'] else None
origin_id = departure['codOrigine']
destination = departure.get('destinazione')
route_name = 'RV' if 3000 <= trip_id < 4000 else 'R'
stop_time = TripStopTime(stop, origin_id, dep_time, stop_sequence, delay, platform, headsign, trip_id,
route_name,
arr_time=arr_time, origin_dep_time=origin_dep_time, destination=destination)
arr_time=arr_time, orig_dep_date=orig_dep_date, destination=destination)
stop_times.append(stop_time)

return stop_times
Expand Down Expand Up @@ -294,7 +294,7 @@ def get_stop_times_between_stops(self, dep_stop: Station, arr_stop: Station, lin
Trip.orig_id.label('origin_id'),
Trip.dest_text.label('destination'),
Trip.number.label('trip_id'),
Trip.orig_dep_date.label('origin_dep_time'),
Trip.orig_dep_date.label('orig_dep_date'),
Trip.route_name.label('route_name'),
d_stop_times.platform.label('d_platform'),
a_stop_times.sched_dep_dt.label('a_dep_time'),
Expand Down Expand Up @@ -341,12 +341,12 @@ def get_stop_times_between_stops(self, dep_stop: Station, arr_stop: Station, lin
d_stop_time = TripStopTime(
dep_stop, raw_stop_time.origin_id, d_dep_time, None, 0, raw_stop_time.d_platform,
raw_stop_time.destination, raw_stop_time.trip_id, raw_stop_time.route_name,
arr_time=d_arr_time, origin_dep_time=raw_stop_time.origin_dep_time)
arr_time=d_arr_time, orig_dep_date=raw_stop_time.orig_dep_date)

a_stop_time = TripStopTime(
arr_stop, raw_stop_time.origin_id, a_dep_time, None, 0, raw_stop_time.a_platform,
raw_stop_time.destination, raw_stop_time.trip_id, raw_stop_time.route_name,
arr_time=a_arr_time, origin_dep_time=raw_stop_time.origin_dep_time)
arr_time=a_arr_time, orig_dep_date=raw_stop_time.orig_dep_date)

route = TrenitaliaRoute(d_stop_time, a_stop_time)
directions.append(Direction([route]))
Expand Down

0 comments on commit 6537895

Please sign in to comment.