-
-
Notifications
You must be signed in to change notification settings - Fork 29
feat: Smart/Origin parcours 3 itinévert #2100
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
base: master
Are you sure you want to change the base?
Changes from all commits
b2d3301
24c84bb
0dd9ad6
905fa55
b11143b
288e183
1d0480f
fbaf190
b6caaa4
6a88e18
3a540a1
8233f1d
bb40e9e
830581a
ddb2f03
bcb9a97
e28025a
94e05a3
eb86874
cfa6f73
5f13610
479e003
2a1a847
2bd8db5
72df94c
4950c16
8a55a1a
9054d05
971fea1
c67b0b3
e2b423e
10057e6
3bb8456
3b999d3
0ba34c3
3d6d24c
7dd7b2b
90bb53d
37e245d
7af8240
499b96b
53ff11f
2f5d6cb
c32e727
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """Add coverages | ||
|
|
||
| Revision ID: 335e0bc4df28 | ||
| Revises: 6b40cb9c7c3d | ||
| Create Date: 2025-11-18 14:15:26.377504 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '335e0bc4df28' | ||
| down_revision = '6b40cb9c7c3d' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
| def upgrade(): | ||
| coverage_type = sa.Enum('fr-idf', 'fr-ne', 'fr-nw', 'fr-se', 'fr-sw', name='coverage_type', schema='guidebook') | ||
| op.create_table('coverages', | ||
| sa.Column('coverage_type', coverage_type, nullable=True), | ||
| sa.Column('document_id', sa.Integer(), nullable=False), | ||
| sa.ForeignKeyConstraint(['document_id'], ['guidebook.documents.document_id'], ), | ||
| sa.PrimaryKeyConstraint('document_id'), | ||
| schema='guidebook' | ||
| ) | ||
| op.create_table('coverages_archives', | ||
| sa.Column('coverage_type', coverage_type, nullable=True), | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.ForeignKeyConstraint(['id'], ['guidebook.documents_archives.id'], ), | ||
| sa.PrimaryKeyConstraint('id'), | ||
| schema='guidebook' | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.drop_table('coverages_archives', schema='guidebook') | ||
| op.drop_table('coverages', schema='guidebook') | ||
| sa.Enum('fr-idf', 'fr-ne', 'fr-nw', 'fr-se', 'fr-sw', name='coverage_type', schema='guidebook').drop(op.get_bind()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,26 +101,31 @@ def configure_anonymous(settings, config): | |
| config.registry.anonymous_user_id = account_id | ||
|
|
||
|
|
||
| def delete_waypoint_stopareas(connection, waypoint_id): | ||
| # Delete existing stopareas for waypoint | ||
| delete_relation_query = text( | ||
| """ | ||
| DELETE FROM guidebook.waypoints_stopareas | ||
| WHERE waypoint_id = :waypoint_id | ||
| """ | ||
| ) | ||
|
|
||
| connection.execute( | ||
| delete_relation_query, | ||
| { | ||
| "waypoint_id": waypoint_id, | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| @event.listens_for(DocumentGeometry, "after_insert") | ||
| @event.listens_for(DocumentGeometry, "after_update") | ||
| def process_new_waypoint(mapper, connection, geometry): | ||
| """Processes a new waypoint to find its public transports after | ||
| inserting it into documents_geometries.""" | ||
| log.debug("Entering process_new_waypoint callback") | ||
| # Check if document is a waypoint | ||
| waypoint_id = geometry.document_id | ||
|
|
||
| max_distance_waypoint_to_stoparea = int( | ||
| os.getenv("MAX_DISTANCE_WAYPOINT_TO_STOPAREA") | ||
| ) | ||
| walking_speed = float(os.getenv("WALKING_SPEED")) | ||
| max_stop_area_for_1_waypoint = int(os.getenv("MAX_STOP_AREA_FOR_1_WAYPOINT")) # noqa: E501 | ||
| api_key = os.getenv("NAVITIA_API_KEY") | ||
| max_duration = int(max_distance_waypoint_to_stoparea / walking_speed) | ||
|
|
||
| # Augmenter le nombre d'arrêts récupérés pour avoir plus de choix (comme dans le bash) # noqa: E501 | ||
| max_stop_area_fetched = max_stop_area_for_1_waypoint * 3 | ||
|
|
||
| # Check if document is a waypoint | ||
| document_type = connection.execute( | ||
| text( | ||
| """ | ||
|
|
@@ -134,6 +139,18 @@ def process_new_waypoint(mapper, connection, geometry): | |
| if document_type != "w": | ||
| return | ||
|
|
||
| log.debug("Entering process_new_waypoint callback") | ||
| max_distance_waypoint_to_stoparea = int( | ||
| os.getenv("MAX_DISTANCE_WAYPOINT_TO_STOPAREA") | ||
| ) | ||
| walking_speed = float(os.getenv("WALKING_SPEED")) | ||
| max_stop_area_for_1_waypoint = int(os.getenv("MAX_STOP_AREA_FOR_1_WAYPOINT")) # noqa: E501 | ||
| api_key = os.getenv("NAVITIA_API_KEY") | ||
| max_duration = int(max_distance_waypoint_to_stoparea / walking_speed) | ||
|
|
||
| # Augmenter le nombre d'arrêts récupérés pour avoir plus de choix (comme dans le bash) # noqa: E501 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Les commentaires devraient être en anglais, comme pour le reste du code |
||
| max_stop_area_fetched = max_stop_area_for_1_waypoint * 3 | ||
|
|
||
| waypoint_type = connection.execute( | ||
| text( | ||
| """ | ||
|
|
@@ -182,7 +199,8 @@ def process_new_waypoint(mapper, connection, geometry): | |
| places_data = places_response.json() | ||
|
|
||
| if "places_nearby" not in places_data or not places_data["places_nearby"]: | ||
| log.warning(f"No Navitia stops found for the waypoint {waypoint_id}") | ||
| log.warning(f"No Navitia stops found for the waypoint {waypoint_id}; deleting previously registered stops") # noqa: E501 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Préférer l'utilisation de %s ou .format pour une meilleure homogénéité du code (les f-string ne sont utilisés nulle part ailleurs)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Est-ce vraiment un warning ? C'est plutôt un comportement normal qui ne nécessite pas d'attention particulière ? (dans ce cas, préférer un .info) |
||
| delete_waypoint_stopareas(connection, waypoint_id) | ||
| return | ||
|
|
||
| # --- NOUVEAU : Filtrage par diversité de transport (comme dans bash) --- | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. traduire en anglias |
||
|
|
@@ -226,23 +244,11 @@ def process_new_waypoint(mapper, connection, geometry): | |
| known_transports.update(current_stop_transports) | ||
| selected_count += 1 | ||
|
|
||
| # Delete existing stopareas for waypoint | ||
| delete_relation_query = text( | ||
| """ | ||
| DELETE FROM guidebook.waypoints_stopareas | ||
| WHERE waypoint_id = :waypoint_id | ||
| """ | ||
| ) | ||
|
|
||
| connection.execute( | ||
| delete_relation_query, | ||
| { | ||
| "waypoint_id": waypoint_id, | ||
| }, | ||
| ) | ||
|
|
||
| log.warning(f"Selected {selected_count} stops out of {len(places_data['places_nearby'])} for waypoint {waypoint_id}") # noqa: E501 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem: format + # noqa: E501
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. éviter les f-string (%s ou .format) |
||
|
|
||
| log.warning("Deleting previously registered stops") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem -> log.info |
||
| delete_waypoint_stopareas(connection, waypoint_id) | ||
|
|
||
| # Traiter uniquement les arrêts sélectionnés | ||
| for place in selected_stops: | ||
| stop_id = place["id"] | ||
|
|
@@ -363,7 +369,7 @@ def calculate_route_duration(mapper, connection, route): | |
| jour du script bash. | ||
| """ | ||
| route_id = route.document_id | ||
| log.warn(f"Calculating duration for route ID: {route_id}") | ||
| log.warning(f"Calculating duration for route ID: {route_id}") | ||
|
|
||
| # Récupération des activités et normalisation des dénivelés | ||
| activities = route.activities if route.activities is not None else [] | ||
|
|
@@ -440,15 +446,15 @@ def _calculate_climbing_duration(route, height_diff_up, height_diff_down, route_ | |
| return None # Pas de données utilisables pour le calcul | ||
|
|
||
| dm = dp / v_diff | ||
| log.warn(f"Calculated climbing route duration for route {route_id} (activity {activity}, no difficulties_height): {dm:.2f} hours") # noqa: E501 | ||
| log.warning(f"Calculated climbing route duration for route {route_id} (activity {activity}, no difficulties_height): {dm:.2f} hours") # noqa: E501 | ||
| return dm | ||
|
|
||
| # CAS 2: Le dénivelé des difficultés est renseigné | ||
| d_diff = float(difficulties_height) | ||
|
|
||
| # Vérification de cohérence | ||
| if dp > 0 and d_diff > dp: | ||
| log.warn(f"Route {route_id}: Inconsistent difficulties_height ({d_diff}m) > height_diff_up ({dp}m). Returning NULL.") # noqa: E501 | ||
| log.warning(f"Route {route_id}: Inconsistent difficulties_height ({d_diff}m) > height_diff_up ({dp}m). Returning NULL.") # noqa: E501 | ||
| return None | ||
|
|
||
| # Calcul du temps des difficultés | ||
|
|
@@ -466,7 +472,7 @@ def _calculate_climbing_duration(route, height_diff_up, height_diff_down, route_ | |
| # Calcul final selon le cadrage: max(t_diff, t_app) + 0.5 * min(t_diff, t_app) # noqa: E501 | ||
| dm = max(t_diff, t_app) + 0.5 * min(t_diff, t_app) | ||
|
|
||
| log.warn(f"Calculated climbing route duration for route {route_id} (activity {activity}): {dm:.2f} hours (t_diff={t_diff:.2f}, t_app={t_app:.2f})") # noqa: E501 | ||
| log.warning(f"Calculated climbing route duration for route {route_id} (activity {activity}): {dm:.2f} hours (t_diff={t_diff:.2f}, t_app={t_app:.2f})") # noqa: E501 | ||
| return dm | ||
|
|
||
|
|
||
|
|
@@ -517,7 +523,7 @@ def _calculate_standard_duration(activity, route, height_diff_up, height_diff_do | |
| else: | ||
| dm = (dv / 2) + dh | ||
|
|
||
| log.warn(f"Calculated standard route duration for route {route_id} (activity {activity}): {dm:.2f} hours") # noqa: E501 | ||
| log.warning(f"Calculated standard route duration for route {route_id} (activity {activity}): {dm:.2f} hours") # noqa: E501 | ||
| return dm | ||
|
|
||
|
|
||
|
|
@@ -531,8 +537,9 @@ def _validate_and_convert_duration(min_duration, route_id): | |
| or min_duration < min_duration_hours | ||
| or min_duration > max_duration_hours | ||
| ): | ||
| log.warn( | ||
| f"Route {route_id}: Calculated duration ({min_duration:.2f} hours if not None) is out of bounds (min={min_duration_hours}h, max={max_duration_hours}h) or NULL. Setting duration to NULL." # noqa: E501 | ||
| min_duration_str = "None" if min_duration is None else f"{min_duration:.2f}" # noqa: E501 | ||
| log.warning( | ||
| f"Route {route_id}: Calculated duration (min_duration={min_duration_str}) is out of bounds (min={min_duration_hours}h, max={max_duration_hours}h) or NULL. Setting duration to NULL." # noqa: E501 | ||
| ) | ||
| return None | ||
|
|
||
|
|
@@ -551,6 +558,6 @@ def _update_route_duration(connection, route_id, calculated_duration_in_days): | |
| ), | ||
| {"duration": calculated_duration_in_days, "route_id": route_id}, | ||
| ) | ||
| log.warn( | ||
| log.warning( | ||
| f"Route {route_id}: Database updated with calculated_duration = {calculated_duration_in_days} days." # noqa: E501 | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -785,3 +785,11 @@ | |
| 'highline', | ||
| 'waterline' | ||
| ] | ||
|
|
||
| coverage_types = [ | ||
| 'fr-idf', | ||
| 'fr-ne', | ||
| 'fr-nw', | ||
| 'fr-se', | ||
| 'fr-sw' | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| DEFAULT_FIELDS = [ | ||
| 'coverage_type' | ||
| 'geometry.geom_detail' | ||
| ] | ||
|
|
||
| DEFAULT_REQUIRED = [ | ||
| 'coverage_type', | ||
| 'geometry', | ||
| 'geometry.geom_detail' | ||
| ] | ||
|
|
||
| LISTING_FIELDS = [ | ||
| 'coverage_type', | ||
| 'geometry.geom_detail' | ||
| ] | ||
|
|
||
| fields_coverage = { | ||
| 'fields': DEFAULT_FIELDS, | ||
| 'required': DEFAULT_REQUIRED, | ||
| 'listing': LISTING_FIELDS | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corriger l'erreur plutôt que de l'ignorer
idem sur tous les # noqa: E501