MouleeswaranM commited on
Commit
4458093
·
verified ·
1 Parent(s): ad7b717

fix: Fix IndexError in consolidation engine when pickupLocation is empty

Browse files
brain/app/services/consolidation_engine.py CHANGED
@@ -719,10 +719,11 @@ class LearningInsightsAgent:
719
  for g in groups:
720
  if g.get("shipmentCount", 0) > 1 and g.get("shipments"):
721
  first = g["shipments"][0]
722
- key = (
723
- f"{first.get('pickupLocation', '').split()[0]} -> "
724
- f"{first.get('dropLocation', '').split()[0]}"
725
- )
 
726
  corridors[key] = corridors.get(key, 0) + g["shipmentCount"]
727
  top = sorted(corridors.items(), key=lambda x: -x[1])
728
  if top:
 
719
  for g in groups:
720
  if g.get("shipmentCount", 0) > 1 and g.get("shipments"):
721
  first = g["shipments"][0]
722
+ pickup_loc = first.get('pickupLocation', '') or f"({first.get('pickupLat', '?')},{first.get('pickupLng', '?')})"
723
+ drop_loc = first.get('dropLocation', '') or f"({first.get('dropLat', '?')},{first.get('dropLng', '?')})"
724
+ pickup_short = pickup_loc.split()[0] if pickup_loc.strip() else "Origin"
725
+ drop_short = drop_loc.split()[0] if drop_loc.strip() else "Dest"
726
+ key = f"{pickup_short} -> {drop_short}"
727
  corridors[key] = corridors.get(key, 0) + g["shipmentCount"]
728
  top = sorted(corridors.items(), key=lambda x: -x[1])
729
  if top: