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: upload gtfs stop times to postgres #125

Merged
merged 22 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bdf11e9
Make limit on get_stop_times method optional
gsarrco Sep 27, 2023
94b5ad4
Use Source upload_trip_stop_times_to_postgres and TripStopTime for Tr…
gsarrco Oct 1, 2023
6537895
Rename origin_dep_time to orig_dep_date and hint correct type
gsarrco Oct 1, 2023
d0cc8e4
Merge branch 'staging' into feat/upload_gtfs_stop_times_to_postgres
gsarrco Oct 1, 2023
c40d0d6
Merge branch 'staging' into feat/upload_gtfs_stop_times_to_postgres
gsarrco Oct 1, 2023
7e839b1
Make get_stop_times return list of TripStopTime
gsarrco Oct 2, 2023
f1880fd
Disable some superfluous logging
gsarrco Oct 2, 2023
3fe198a
Move Trenitalia get_stop_times and get_stop_times_between_stops to So…
gsarrco Oct 3, 2023
a9ecd06
Rename stop variables in base.py to station variables
gsarrco Oct 3, 2023
9cbaf4a
Save GTFS stop times to postgres and remove child get_stop_times and …
gsarrco Oct 3, 2023
3a5998f
Rename save_trains to save_data and run the function for all sources
gsarrco Oct 3, 2023
5d6b75d
force upload stops clusters in GTFS save data
gsarrco Oct 5, 2023
fafc641
Insert source name at beginning of GTFS stop id
gsarrco Oct 5, 2023
a81a7b0
Get normal headsign instead cluster name headsign for efficiency in G…
gsarrco Oct 5, 2023
806226e
More efficiently upload data to Postgres
gsarrco Oct 6, 2023
c57af6f
Remove stop times test
gsarrco Oct 6, 2023
d022bac
Renable tqdm for stations
gsarrco Oct 7, 2023
ff50412
Allow to skip sources during save_data.py
gsarrco Oct 7, 2023
09e4ae6
Reduce get_sqlite_stop_times queries
gsarrco Oct 7, 2023
ff10a14
Save also end of the line stop times for GTFS
gsarrco Oct 7, 2023
9455e91
Retrieve stop ids from station relationship instead of field
gsarrco Oct 7, 2023
26f0379
Make get_stops_from_trip_id working
gsarrco Oct 7, 2023
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
23 changes: 12 additions & 11 deletions MuoVErsi/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ async def show_stop_from_id(update: Update, context: ContextTypes.DEFAULT_TYPE)
else:
db_file = thismodule.sources[context.user_data['transport_type']]

stop = db_file.get_stop_from_ref(stop_ref)
cluster_name = stop.name
stop_ids = stop.ids
station = db_file.get_stop_from_ref(stop_ref)
cluster_name = station.name
stop_ids = ','.join([stop.id for stop in station.stops])
saved_dep_stop_ids = context.user_data.get('dep_stop_ids')
saved_dep_cluster_name = context.user_data.get('dep_cluster_name')

Expand Down Expand Up @@ -419,14 +419,14 @@ async def trip_view(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
if not all_stops:
dep_stop_ids = stop_times_filter.dep_stop_ids.split(',')
try:
dep_stop_index = next(i for i, v in enumerate(results) if str(v.stop.ids) in dep_stop_ids)
dep_stop_index = next(i for i, v in enumerate(results) if v.station.id in dep_stop_ids)
except StopIteration:
logger.warning('No departure stop found')
if arr_cluster_name:
arr_stop_ids = stop_times_filter.arr_stop_ids.split(',')
try:
arr_stop_index = dep_stop_index + next(
i for i, v in enumerate(results[dep_stop_index:]) if str(v.stop.ids) in arr_stop_ids)
i for i, v in enumerate(results[dep_stop_index:]) if str(v.station.id) in arr_stop_ids)
except StopIteration:
logger.warning('No arrival stop found')

Expand All @@ -440,14 +440,14 @@ async def trip_view(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
dep_time = result.dep_time.strftime('%H:%M') if result.dep_time else ''

if are_dep_and_arr_times_equal:
text += f'\n<b>{arr_time}</b> {result.stop.name}'
text += f'\n<b>{arr_time}</b> {result.station.station.name}'
else:
if i == 0:
text += f'\n{result.stop.name} <b>{dep_time}</b>'
text += f'\n{result.station.station.name} <b>{dep_time}</b>'
elif i == arr_stop_index:
text += f'\n<b>{arr_time}</b> {result.stop.name}'
text += f'\n<b>{arr_time}</b> {result.station.station.name}'
else:
text += f'\n<b>{arr_time}</b> {result.stop.name} <b>{dep_time}</b>'
text += f'\n<b>{arr_time}</b> {result.station.station.name} <b>{dep_time}</b>'

if result.platform:
text += f' ({platform_text} {result.platform})'
Expand Down Expand Up @@ -504,8 +504,9 @@ async def show_line(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
inline_buttons = []

for stop in stops:
stop_id = stop.stop.name
stop_name = stop.stop.name
station = stop.station
stop_id = station.id
stop_name = station.name
inline_buttons.append([InlineKeyboardButton(stop_name, callback_data=f'S{stop_id}/{line}')])

await query.edit_message_text(text=text, reply_markup=InlineKeyboardMarkup(inline_buttons))
Expand Down
2 changes: 1 addition & 1 deletion MuoVErsi/sources/GTFS/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def compute_centroid(stops):
return centroid


def get_loc_from_stop_and_cluster(stop_name, cluster_name):
def get_loc_from_stop_and_cluster(stop_name):
stop_name = stop_name.replace('"', ' ')
stop_name = stop_name.replace(' ', ' ').rstrip()
match = re.match(r'.*? ((?:CORSIA )?[A-Z][0-9]?)$', stop_name)
Expand Down
Loading