Skip to content

Commit f2d8294

Browse files
committed
style: Reformat files with black for Python 3.11
1 parent 0c34c39 commit f2d8294

5 files changed

Lines changed: 31 additions & 27 deletions

File tree

src/mandala/alerts.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ async def dead_zone(event: MandalaEvent, state: StateStore, redis: object) -> li
207207

208208
async def customs_hold_vector_stall(event: MandalaEvent, state: StateStore, redis: object) -> list[MandalaEvent]:
209209
"""Laredo Vector Stall detector: Fire alert when customs hold lands before driver reaches bridge.
210-
210+
211211
The "Vector Stall" problem: Customs broker knows about the hold hours before the driver
212212
does. If the driver is still >30 minutes from the bridge, we can reroute them to a
213213
hold lot instead of wasting hours in the queue.
@@ -218,24 +218,24 @@ async def customs_hold_vector_stall(event: MandalaEvent, state: StateStore, redi
218218
EventType.CUSTOMS_INSPECTION_REQUIRED.value,
219219
):
220220
return []
221-
221+
222222
data = event.data if isinstance(event.data, dict) else {}
223223
shipment_urn = event.subject or ""
224-
224+
225225
# Extract Laredo-specific context from Descartes normalization
226226
eta_to_bridge = data.get("eta_to_bridge_minutes")
227227
truck_location = data.get("truck_location", "unknown")
228228
port_of_entry = data.get("port_of_entry", "unknown")
229229
hold_reason = data.get("hold_reason", "unknown")
230-
230+
231231
# Only alert if driver hasn't reached bridge yet (>30 minutes away)
232232
if eta_to_bridge is None or eta_to_bridge <= 30:
233233
return []
234-
234+
235235
# Debounce per shipment to avoid duplicate alerts
236236
if not await _debounce(redis, f"vectorstall:{shipment_urn}", ttl=3600):
237237
return []
238-
238+
239239
log.info(
240240
"customs_hold.vector_stall",
241241
shipment=shipment_urn,
@@ -244,7 +244,7 @@ async def customs_hold_vector_stall(event: MandalaEvent, state: StateStore, redi
244244
truck_location=truck_location,
245245
hold_reason=hold_reason,
246246
)
247-
247+
248248
return [
249249
new_event(
250250
type=EventType.ALERT_CUSTOMS_HOLD_VECTOR_STALL,

src/mandala/connectors/descartes/macropoint/normalize.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,21 @@ def normalize(payload: dict[str, Any]) -> list[MandalaEvent]:
110110
data["location"] = {"lat": float(body["Latitude"]), "lon": float(body["Longitude"])}
111111
if body.get("Eta") or body.get("eta"):
112112
data["eta"] = body.get("Eta") or body.get("eta")
113-
113+
114114
# Laredo Vector Stall: Extract context for customs holds
115115
if status_str in ("CustomsHoldLanded", "CustomsDocumentationMissing", "CustomsInspectionRequired"):
116-
data.update({
117-
"port_of_entry": body.get("PortOfEntry") or body.get("portOfEntry") or "unknown",
118-
"filing_number": body.get("FilingNumber") or body.get("filingNumber"),
119-
"hold_reason": body.get("HoldReason") or body.get("holdReason") or status_str,
120-
"truck_location": body.get("TruckLocation") or body.get("truckLocation") or "unknown",
121-
"eta_to_bridge_minutes": body.get("EtaToBridgeMinutes") or body.get("etaToBridgeMinutes"),
122-
"estimated_clearance_hours": body.get("EstimatedClearanceHours") or body.get("estimatedClearanceHours"),
123-
})
124-
116+
data.update(
117+
{
118+
"port_of_entry": body.get("PortOfEntry") or body.get("portOfEntry") or "unknown",
119+
"filing_number": body.get("FilingNumber") or body.get("filingNumber"),
120+
"hold_reason": body.get("HoldReason") or body.get("holdReason") or status_str,
121+
"truck_location": body.get("TruckLocation") or body.get("truckLocation") or "unknown",
122+
"eta_to_bridge_minutes": body.get("EtaToBridgeMinutes") or body.get("etaToBridgeMinutes"),
123+
"estimated_clearance_hours": body.get("EstimatedClearanceHours")
124+
or body.get("estimatedClearanceHours"),
125+
}
126+
)
127+
125128
events = [
126129
new_event(
127130
type=et,

src/mandala/mcp/server.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ async def tool_inspect_dlq(limit: int = 50) -> dict[str, Any]:
297297

298298
async def tool_get_trailer_handoff_chain(trailer_id: str) -> dict[str, Any]:
299299
"""Return the full handoff chain for a trailer (Mexican → Drayage → US trucks).
300-
300+
301301
Uses the graph view to query temporal HAULED edges, showing which truck
302302
hauled the trailer at which time. This solves the Laredo "Brokerage Fog"
303303
problem by linking all three tractors via the constant trailer ID.
@@ -345,7 +345,7 @@ async def tool_get_trailer_handoff_chain(trailer_id: str) -> dict[str, Any]:
345345

346346
async def tool_get_shipment_via_trailer(trailer_id: str) -> dict[str, Any]:
347347
"""Return the shipment currently linked to a trailer.
348-
348+
349349
This is the inverse of the handoff chain query — useful for answering
350350
"which shipment is this trailer carrying right now?"
351351
"""
@@ -366,6 +366,7 @@ async def tool_get_shipment_via_trailer(trailer_id: str) -> dict[str, Any]:
366366

367367
# Get current truck (if any)
368368
from mandala.views.graph import GraphView
369+
369370
view = GraphView(r)
370371
current_truck = None
371372
if await view._probe():
@@ -568,7 +569,10 @@ async def tool_get_bridge_capabilities() -> dict[str, Any]:
568569
"name": "check_customs_status",
569570
"description": "Return customs status, authority, broker, and hold reason",
570571
},
571-
{"name": "get_trailer_handoff_chain", "description": "Return full handoff chain for a trailer (Mexican → Drayage → US trucks)"},
572+
{
573+
"name": "get_trailer_handoff_chain",
574+
"description": "Return full handoff chain for a trailer (Mexican → Drayage → US trucks)",
575+
},
572576
{"name": "get_shipment_via_trailer", "description": "Return shipment currently linked to a trailer"},
573577
],
574578
"alerts_monitoring": [

src/mandala/projection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ async def project(event: MandalaEvent, state: StateStore) -> None:
142142
if k in data and data[k] is not None:
143143
patch[k] = data[k]
144144
await state.upsert("trailer", trailer_urn, patch)
145-
145+
146146
# Link trailer to shipment
147147
shipment_urn = data.get("shipment_urn")
148148
if shipment_urn:
149149
await state.link(trailer_urn, shipment_urn)
150-
150+
151151
# Link truck to trailer (for handoff chain tracking)
152152
truck_urn = subject
153153
if truck_urn and truck_urn.startswith("urn:mandala:truck:"):

src/mandala/views/graph.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ async def _apply_inner(self, event: MandalaEvent) -> None:
151151
if truck_urn and trailer_id:
152152
# Update temporal edge: set end time
153153
await self._query(
154-
"MATCH (t:Truck {urn: $t})-[r:HAULED]->(trl:Trailer {id: $trl}) "
155-
"SET r.end = $end_time",
154+
"MATCH (t:Truck {urn: $t})-[r:HAULED]->(trl:Trailer {id: $trl}) " "SET r.end = $end_time",
156155
{"t": truck_urn, "trl": str(trailer_id), "end_time": event.time.isoformat()},
157156
)
158157
return
@@ -163,9 +162,7 @@ async def _apply_inner(self, event: MandalaEvent) -> None:
163162
shipment_urn = data.get("shipment_urn")
164163
if trailer_id and shipment_urn:
165164
await self._query(
166-
"MERGE (trl:Trailer {id: $trl}) "
167-
"MERGE (s:Shipment {urn: $s}) "
168-
"MERGE (trl)-[:CARRIES]->(s)",
165+
"MERGE (trl:Trailer {id: $trl}) " "MERGE (s:Shipment {urn: $s}) " "MERGE (trl)-[:CARRIES]->(s)",
169166
{"trl": str(trailer_id), "s": shipment_urn},
170167
)
171168
return

0 commit comments

Comments
 (0)