@@ -205,16 +205,21 @@ def _make_bike_park(begin_date_time, duration):
205
205
return bike_park_section
206
206
207
207
208
- def _make_bike_park_street_network (origin , begin_date_time , destination , end_date_time , duration ):
208
+ def _make_bike_park_street_network (origin , begin_date_time , destination , end_date_time , duration , length ):
209
209
bike_park_to_sp_section = response_pb2 .Section ()
210
210
bike_park_to_sp_section .id = "Street_network_section_2"
211
211
bike_park_to_sp_section .origin .CopyFrom (origin )
212
212
bike_park_to_sp_section .destination .CopyFrom (destination )
213
213
bike_park_to_sp_section .type = response_pb2 .STREET_NETWORK
214
214
bike_park_to_sp_section .street_network .mode = response_pb2 .Walking
215
+ bike_park_to_sp_section .street_network .street_information .extend (
216
+ [response_pb2 .StreetInformation (geojson_offset = 0 , cycle_path_type = 0 , length = length )]
217
+ )
218
+ bike_park_to_sp_section .street_network .duration = duration
215
219
bike_park_to_sp_section .begin_date_time = begin_date_time
216
- bike_park_to_sp_section .end_date_time = end_date_time + duration
220
+ bike_park_to_sp_section .end_date_time = bike_park_to_sp_section . begin_date_time + duration
217
221
bike_park_to_sp_section .duration = duration
222
+ bike_park_to_sp_section .street_network .length = length
218
223
return bike_park_to_sp_section
219
224
220
225
@@ -417,19 +422,23 @@ def add_poi_access_point_in_sections(fallback_type, via_poi_access, sections):
417
422
poi_access .is_entrance = True
418
423
419
424
420
- def _update_journey (journey , park_section , street_mode_section , to_replace , new_fallbacks ):
425
+ def _update_journey (journey , park_section , street_mode_section , to_replace ):
421
426
journey .duration += park_section .duration + street_mode_section .duration
422
427
journey .durations .total += park_section .duration + street_mode_section .duration
423
428
journey .arrival_date_time += park_section .duration + street_mode_section .duration
424
429
journey .sections .remove (to_replace )
425
430
journey .sections .extend ([street_mode_section , park_section ])
426
- journey .sections .extend (new_fallbacks )
427
431
journey .nb_sections += 2
428
432
429
433
430
- def walking_time (cord1 , cord2 , walking_speed ):
434
+ def _get_coords_from_pt_object (pt_object ):
435
+ coord = get_pt_object_coord (pt_object )
436
+ return coord
437
+
438
+
439
+ def _get_walking_information (object_1 , object_2 , walking_speed ):
431
440
"""
432
- Calculate the walking time between two coordinates.
441
+ Calculate the walking time and the distance between two coordinates.
433
442
434
443
Args:
435
444
cord1 (tuple): The (latitude, longitude) of the starting point.
@@ -438,12 +447,16 @@ def walking_time(cord1, cord2, walking_speed):
438
447
439
448
Returns:
440
449
float: The walking time in secondes.
450
+ float: The distance in meters
441
451
"""
452
+ cord1 = get_pt_object_coord (object_1 )
453
+ cord2 = get_pt_object_coord (object_2 )
454
+
442
455
distance = crowfly_distance_between (cord1 , cord2 )
443
- return get_manhattan_duration (distance , walking_speed )
456
+ return get_manhattan_duration (distance , walking_speed ), round ( distance )
444
457
445
458
446
- def _get_place (kwargs , uri ):
459
+ def _get_place (kwargs , pt_object ):
447
460
"""
448
461
Retrieve a place instance based on the provided URI.
449
462
@@ -457,6 +470,8 @@ def _get_place(kwargs, uri):
457
470
Returns:
458
471
PlaceByUri: An instance of PlaceByUri after waiting for the result.
459
472
"""
473
+ coord = _get_coords_from_pt_object (pt_object )
474
+ uri = "{};{}" .format (coord .lon , coord .lat )
460
475
place_by_uri_instance = PlaceByUri (kwargs ["future_manager" ], kwargs ["instance" ], uri , kwargs ["request_id" ])
461
476
return place_by_uri_instance .wait_and_get ()
462
477
@@ -465,30 +480,30 @@ def _update_fallback_with_bike_mode(
465
480
journey , fallback_dp , fallback_period_extremity , fallback_type , via_pt_access , via_poi_access , ** kwargs
466
481
):
467
482
"""
468
- Updates the journey with bike mode fallback sections.
469
-
470
- This function updates the journey sections with bike mode fallback sections based on the fallback type
471
- (BEGINNING_FALLBACK or ENDING_FALLBACK). It aligns the fallback direct path datetime, updates the section IDs,
472
- and creates the necessary links between the fallback and public transport parts. It also handles the addition
473
- of POI access points in the sections.
474
-
475
- Args:
476
- journey (Journey): The journey object to be updated.
477
- fallback_dp (DirectPath): The direct path object for the fallback.
478
- fallback_period_extremity (datetime): The extremity datetime for the fallback period.
479
- fallback_type (StreetNetworkPathType): The type of fallback (BEGINNING_FALLBACK or ENDING_FALLBACK).
480
- via_pt_access (PtObject): The public transport access point object.
481
- via_poi_access (POIObject): The point of interest access point object.
482
- **kwargs: Additional keyword arguments, including:
483
- - origin_mode (list): The mode of origin (e.g., ["bike"]).
484
- - destination_mode (list): The mode of destination (e.g., ["bike"]).
485
- - future_manager (FutureManager): The future manager instance.
486
- - instance (Instance): The instance object.
487
- - request_id (str): The request ID.
488
- - additional_time (timedelta): The additional time to be added to the sections.
489
-
490
- Returns:
491
- None
483
+ Updates the journey with bike mode fallback sections.
484
+ access_point
485
+ This function updates the journey sections with bike mode fallback sections based on the fallback type
486
+ (BEGINNING_FALLBACK or ENDING_FALLBACK). It aligns the fallback direct path datetime, updates the section IDs,
487
+ and creates the necessary links between the fallback and public transport parts. It also handles the addition
488
+ of POI access points in the sections.
489
+
490
+ Args:
491
+ journey (Journey): The journey object to be updated.
492
+ fallback_dp (DirectPath): The direct path object for the fallback.
493
+ fallback_period_extremity (datetime): The extremity datetime for the fallback period.
494
+ fallback_type (StreetNetworkPathType): The type of fallback (BEGINNING_FALLBACK or ENDING_FALLBACK).
495
+ via_pt_access (PtObject): The public transport access point object.
496
+ via_poi_access (POIObject): The point of interest access point object.
497
+ **kwargs: Additional keyword arguments, including:
498
+ - origin_mode (list): The mode of origin (e.g., ["bike"]).
499
+ - destination_mode (list): The mode of destination (e.g., ["bike"]).
500
+ - future_manager (FutureManager): The future manager instance.
501
+ - instance (Instance): The instance object.
502
+ - request_id (str): The request ID.
503
+ - additional_time (timedelta): The additional time to be added to the sections.
504
+
505
+ Returns:
506
+ None
492
507
"""
493
508
# Validate required arguments
494
509
if not all (kwargs .get (key ) for key in ("future_manager" , "instance" , "request_id" )):
@@ -500,76 +515,97 @@ def _update_fallback_with_bike_mode(
500
515
fallback_sections = aligned_fallback .journeys [0 ].sections
501
516
_rename_fallback_sections_ids (fallback_sections )
502
517
503
- # We have to create the link between the fallback and the pt part manually here
504
- if fallback_type == StreetNetworkPathType .BEGINNING_FALLBACK and "bike" in kwargs ["origin_mode" ]:
505
- address = _get_place (kwargs , fallback_sections [- 1 ].destination .uri )
506
- walktime = walking_time (
507
- address .address .coord ,
508
- journey .sections [0 ].destination .stop_point .coord ,
518
+ if (
519
+ fallback_type == StreetNetworkPathType .BEGINNING_FALLBACK
520
+ and fallback_sections [- 1 ].street_network .mode is response_pb2 .Bike
521
+ ):
522
+
523
+ place = _get_place (kwargs , fallback_sections [- 1 ].destination )
524
+ walktime , walking_distance = _get_walking_information (
525
+ place ,
526
+ journey .sections [0 ].destination ,
509
527
kwargs ["instance" ].walking_speed ,
510
528
)
511
- fallback_sections [ - 1 ]. destination . CopyFrom ( address )
512
- for s in journey . sections :
513
- s . begin_date_time + = kwargs ["additional_time" ] + walktime
514
- s . end_date_time + = kwargs ["additional_time" ] + walktime
529
+
530
+ fallback_sections [ - 1 ]. destination . CopyFrom ( place )
531
+ fallback_sections [ - 1 ]. end_date_time - = kwargs ["additional_time" ] + walktime
532
+ fallback_sections [ - 1 ]. begin_date_time - = kwargs ["additional_time" ] + walktime
515
533
park_section = _make_bike_park (fallback_sections [- 1 ].end_date_time , kwargs ["additional_time" ])
534
+ journey .durations .walking += walktime
516
535
street_mode_section = _make_bike_park_street_network (
517
536
fallback_sections [- 1 ].destination ,
518
537
park_section .end_date_time ,
519
538
journey .sections [0 ].destination ,
520
539
(fallback_sections [- 1 ].end_date_time + park_section .duration ) - journey .sections [0 ].end_date_time ,
521
540
walktime ,
541
+ walking_distance ,
522
542
)
523
543
street_mode_section .street_network .coordinates .extend (
524
544
[journey .sections [0 ].destination .stop_point .coord , fallback_sections [- 1 ].destination .address .coord ]
525
545
)
526
- _update_journey (journey , park_section , street_mode_section , journey .sections [0 ], fallback_sections )
527
- if fallback_type == StreetNetworkPathType .BEGINNING_FALLBACK and "bike" not in kwargs ["origin_mode" ]:
546
+ _update_journey (journey , park_section , street_mode_section , journey .sections [0 ])
547
+ if (
548
+ fallback_type == StreetNetworkPathType .BEGINNING_FALLBACK
549
+ and fallback_sections [- 1 ].street_network .mode is not response_pb2 .Bike
550
+ ):
528
551
section_to_replace = journey .sections [0 ]
529
552
journey .sections .remove (section_to_replace )
530
553
fallback_sections [- 1 ].destination .CopyFrom (journey .sections [0 ].origin )
531
- journey .sections .extend (fallback_sections )
532
- elif fallback_type == StreetNetworkPathType .ENDING_FALLBACK and "bike" in kwargs ["destination_mode" ]:
533
- walktime = walking_time (
534
- journey .sections [- 1 ].origin .stop_point .coord ,
535
- fallback_sections [0 ].origin .address .coord ,
554
+ elif (
555
+ fallback_type == StreetNetworkPathType .ENDING_FALLBACK
556
+ and fallback_sections [0 ].street_network .mode is response_pb2 .Bike
557
+ ):
558
+ walktime , walking_distance = _get_walking_information (
559
+ journey .sections [- 1 ].origin ,
560
+ fallback_sections [0 ].origin ,
536
561
kwargs ["instance" ].walking_speed ,
537
562
)
538
- address = _get_place (kwargs , fallback_sections [0 ].origin .uri )
539
- fallback_sections [0 ].origin .CopyFrom (address )
563
+ journey .durations .walking += walktime
564
+ place = _get_place (kwargs , fallback_sections [0 ].origin )
565
+ fallback_sections [0 ].origin .CopyFrom (place )
540
566
street_mode_section = _make_bike_park_street_network (
541
567
journey .sections [- 1 ].origin ,
542
568
fallback_sections [0 ].begin_date_time ,
543
569
fallback_sections [0 ].origin ,
544
570
(fallback_sections [0 ].begin_date_time + kwargs ["additional_time" ])
545
571
- journey .sections [- 1 ].begin_date_time ,
546
572
walktime ,
573
+ walking_distance ,
547
574
)
548
575
park_section = _make_bike_park (street_mode_section .begin_date_time , kwargs ["additional_time" ])
549
576
fallback_sections [0 ].begin_date_time += kwargs ["additional_time" ]
550
577
street_mode_section .street_network .coordinates .extend (
551
578
[journey .sections [- 1 ].origin .stop_point .coord , fallback_sections [0 ].origin .address .coord ]
552
579
)
553
- _update_journey (journey , park_section , street_mode_section , journey .sections [- 1 ], fallback_sections )
554
- elif fallback_type == StreetNetworkPathType .ENDING_FALLBACK and "bike" not in kwargs ["destination_mode" ]:
580
+ _update_journey (journey , park_section , street_mode_section , journey .sections [- 1 ])
581
+ elif (
582
+ fallback_type == StreetNetworkPathType .ENDING_FALLBACK
583
+ and fallback_sections [0 ].street_network .mode is not response_pb2 .Bike
584
+ ):
555
585
section_to_replace = journey .sections [- 1 ]
556
586
journey .sections .remove (section_to_replace )
557
587
fallback_sections [0 ].origin .CopyFrom (journey .sections [- 1 ].destination )
558
- journey .sections .extend (fallback_sections )
559
588
560
589
add_poi_access_point_in_sections (fallback_type , via_poi_access , fallback_sections )
561
590
562
591
if isinstance (via_pt_access , type_pb2 .PtObject ) and via_pt_access .embedded_type == type_pb2 .ACCESS_POINT :
563
592
if fallback_type == StreetNetworkPathType .BEGINNING_FALLBACK :
564
- journey .sections [- 1 ].vias .add ().CopyFrom (via_pt_access .access_point )
565
593
target_section = next ((s for s in journey .sections if s .id == "Street_network_section_2" ), None )
566
594
if target_section :
567
- target_section .vias .extend ( journey . sections [ - 1 ]. vias )
595
+ target_section .vias .add (). CopyFrom ( via_pt_access . access_point )
568
596
target_section .street_network .path_items .extend (
569
- [journey . sections [- 1 ].street_network .path_items [- 1 ]]
597
+ [fallback_sections [- 1 ].street_network .path_items [- 1 ]]
570
598
)
599
+ fallback_sections [- 1 ].street_network .path_items .pop ()
600
+ target_section .duration += via_pt_access .access_point .traversal_time
601
+ target_section .length += via_pt_access .access_point .length
602
+ fallback_sections [- 1 ].duration -= via_pt_access .access_point .traversal_time
603
+ else :
604
+ fallback_sections [- 1 ].vias .add ().CopyFrom (via_pt_access .access_point )
605
+
571
606
else :
572
- journey .sections [0 ].vias .add ().CopyFrom (via_pt_access .access_point )
607
+ fallback_sections [0 ].vias .add ().CopyFrom (via_pt_access .access_point )
608
+ journey .sections .extend (fallback_sections )
573
609
journey .sections .sort (key = cmp_to_key (SectionSorter ()))
574
610
575
611
@@ -821,9 +857,7 @@ def _build_fallback(
821
857
fallback_dp_copy , fallback_type , requested_obj , via_poi_access , language
822
858
)
823
859
824
- if request ["park_mode" ] == [ParkMode .on_street .name ] and (
825
- request ["origin_mode" ] == ["bike" ] or request ["destination_mode" ] == ["bike" ]
826
- ):
860
+ if request ["park_mode" ] == ParkMode .on_street .name :
827
861
_update_fallback_with_bike_mode (
828
862
pt_journey ,
829
863
fallback_dp_copy ,
0 commit comments