@@ -503,16 +503,21 @@ def update_total_co2_emission(pb_resp):
503
503
j .co2_emission .unit = 'gEC'
504
504
505
505
506
- def update_disruptions_on_pois (instance , pb_resp ):
506
+ def update_disruptions_on_pois (instance , api_request , pb_resp ):
507
507
"""
508
- Maintain a set of uri from g.origin_detail and g.destination_detail of type Poi,
509
- call loki with api api_disruptions&pois[]...
508
+ Maintain a set of uri from g.origin_detail and g.destination_detail of type Poi
509
+ Add uri from all journey.section.origin and journey.section.destination of type Poi
510
+ Call loki with api api_disruptions&pois[]...
510
511
For each disruption on poi, add disruption id in the attribute links and add disruptions in the response
511
512
"""
513
+ required_mode_list = {'bss' , 'car' }
514
+ if not api_request .get ('_disruptions_on_poi' ):
515
+ return
512
516
if not pb_resp .journeys :
513
517
return
514
518
# Add uri of all the pois in a set
515
519
poi_uris = set ()
520
+ poi_objets = []
516
521
since_datetime = date_to_timestamp (datetime .utcnow ())
517
522
until_datetime = date_to_timestamp (datetime .utcnow ())
518
523
@@ -523,6 +528,23 @@ def update_disruptions_on_pois(instance, pb_resp):
523
528
if g .destination_detail and g .destination_detail .get ('embedded_type' ) == "poi" :
524
529
poi_uris .add (g .destination_detail .get ('id' ))
525
530
531
+ # Add pois present in all journeys if any of modes={'bss', 'car'} is present in
532
+ # origin_mode or destination_mode or direct_path_mode
533
+ mode_list = api_request .get ('origin_mode' , [])
534
+ mode_list .extend (api_request .get ('destination_mode' , []))
535
+ if set (mode_list ).intersection (required_mode_list ):
536
+ for j in pb_resp .journeys :
537
+ for s in j .sections :
538
+ if s .origin .embedded_type == type_pb2 .POI :
539
+ poi_uris .add (s .origin .uri )
540
+ poi_objets .append (s .origin .poi )
541
+ since_datetime = min (since_datetime , s .begin_date_time )
542
+
543
+ if s .destination .embedded_type == type_pb2 .POI :
544
+ poi_uris .add (s .destination .uri )
545
+ poi_objets .append (s .destination .poi )
546
+ until_datetime = max (until_datetime , s .end_date_time )
547
+
526
548
if since_datetime >= until_datetime :
527
549
since_datetime = until_datetime - 1
528
550
@@ -531,6 +553,14 @@ def update_disruptions_on_pois(instance, pb_resp):
531
553
if poi_disruptions is None :
532
554
return
533
555
556
+ # For each poi in pt_objects:
557
+ # add impact_uris from resp_poi and
558
+ # copy object poi in impact.impacted_objects
559
+ for pt_object in poi_objets :
560
+ impact_uris = get_impact_uris_for_poi (poi_disruptions , pt_object )
561
+ for impact_uri in impact_uris :
562
+ pt_object .impact_uris .append (impact_uri )
563
+
534
564
# Add all impacts from resp_poi to the response
535
565
add_disruptions (pb_resp , poi_disruptions )
536
566
@@ -1507,7 +1537,7 @@ def fill_journeys(self, request_type, api_request, instance):
1507
1537
journey_filter .remove_excess_terminus (pb_resp )
1508
1538
1509
1539
# Update disruptions on pois
1510
- update_disruptions_on_pois (instance , pb_resp )
1540
+ update_disruptions_on_pois (instance , api_request , pb_resp )
1511
1541
1512
1542
# Update booking_url in booking_rule for all sections of type ON_DEMAND_TRANSPORT
1513
1543
update_booking_rule_url_in_response (pb_resp )
0 commit comments