fix(agent): stabilize sandboxed streaming workflows
This commit is contained in:
@@ -29,6 +29,13 @@ COLORS = [
|
||||
"rgba(204,153,204,0.7)", "rgba(153,153,153,0.7)"
|
||||
]
|
||||
|
||||
|
||||
def norm_time(t):
|
||||
"""把 ISO8601 字符串归一化为 UTC 的 ISO 字符串,用于跨时区比较"""
|
||||
from datetime import datetime
|
||||
return datetime.fromisoformat(t.replace("Z", "+00:00")).astimezone(
|
||||
__import__("datetime").timezone.utc).isoformat()
|
||||
|
||||
def load_json(path, label):
|
||||
print(f"Loading {label}...", file=sys.stderr)
|
||||
with open(path) as f:
|
||||
@@ -63,11 +70,12 @@ def main():
|
||||
|
||||
# --- Step 3: Load link flow at target time ---
|
||||
ldata = load_json(args.links, "link flows")["data"]
|
||||
target_links = [l for l in ldata if l["time"] == args.target_time]
|
||||
target_ts = norm_time(args.target_time)
|
||||
target_links = [l for l in ldata if norm_time(l["time"]) == target_ts]
|
||||
flow_direction = {}
|
||||
pipe_flow = {}
|
||||
for l in target_links:
|
||||
lid = l["id"]
|
||||
lid = l.get("link_id") or l.get("id")
|
||||
flow_val = l["flow"]
|
||||
pipe_flow[lid] = abs(flow_val)
|
||||
if lid in pipe_topology:
|
||||
@@ -81,11 +89,11 @@ def main():
|
||||
|
||||
# --- Step 4: Load node data at target time ---
|
||||
ndata = load_json(args.nodes, "node data")["data"]
|
||||
target_nodes = [n for n in ndata if n["time"] == args.target_time]
|
||||
target_nodes = [n for n in ndata if norm_time(n["time"]) == target_ts]
|
||||
node_pressure = {}
|
||||
node_demand = {}
|
||||
for n in target_nodes:
|
||||
nid = n["id"]
|
||||
nid = n.get("node_id") or n.get("id")
|
||||
node_pressure[nid] = n.get("pressure", 0)
|
||||
node_demand[nid] = n.get("actual_demand", 0)
|
||||
print(f" {len(target_nodes)} nodes", file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user