fix(topology): correct mission anchors and rover ports
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from topology_api.app import create_app
|
from topology_api.app import create_app
|
||||||
@@ -42,6 +43,18 @@ class TopologyApiServingTests(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TopologyApiQueryTests(unittest.TestCase):
|
class TopologyApiQueryTests(unittest.TestCase):
|
||||||
|
EXPECTED_LAST_EVENTS = {
|
||||||
|
"BL-01": "2024-05-17T23:01:00+00:00",
|
||||||
|
"GHC-01": "2024-06-16T07:23:00+00:00",
|
||||||
|
"JC-01": "2024-06-17T08:19:00+00:00",
|
||||||
|
"BL-02": "2024-06-23T05:23:00+00:00",
|
||||||
|
"GHC-02": "2024-07-15T03:16:00+00:00",
|
||||||
|
"GHC-03": "2024-08-30T12:45:00+00:00",
|
||||||
|
"BL-03": "2024-09-23T19:20:00+00:00",
|
||||||
|
"GHC-04": "2024-11-20T13:57:00+00:00",
|
||||||
|
"GHC-05": "2025-01-22T10:52:00+00:00",
|
||||||
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls) -> None:
|
def setUpClass(cls) -> None:
|
||||||
app = create_app()
|
app = create_app()
|
||||||
@@ -75,6 +88,42 @@ class TopologyApiQueryTests(unittest.TestCase):
|
|||||||
self.assertIn("occurrenceStatus", mission)
|
self.assertIn("occurrenceStatus", mission)
|
||||||
self.assertIn("lastEventAt", mission)
|
self.assertIn("lastEventAt", mission)
|
||||||
|
|
||||||
|
def test_each_mission_uses_its_last_timeline_record(self) -> None:
|
||||||
|
response = self.client.get("/api/v1/bases/guanghan/missions")
|
||||||
|
actual = {
|
||||||
|
mission["code"]: datetime.fromisoformat(
|
||||||
|
mission["lastEventAt"]
|
||||||
|
).astimezone(timezone.utc)
|
||||||
|
for mission in response.get_json()["missions"]
|
||||||
|
}
|
||||||
|
expected = {
|
||||||
|
code: datetime.fromisoformat(value)
|
||||||
|
for code, value in self.EXPECTED_LAST_EVENTS.items()
|
||||||
|
}
|
||||||
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
def test_binglun_connections_use_west_south_east_hub_ports(self) -> None:
|
||||||
|
response = self.client.get(
|
||||||
|
"/api/v1/bases/guanghan/snapshot?mission=GHC-05"
|
||||||
|
)
|
||||||
|
connections = response.get_json()["connections"]
|
||||||
|
hub_ports = {}
|
||||||
|
for connection in connections:
|
||||||
|
from_component = connection["fromPort"].split(".", 1)[0]
|
||||||
|
if (
|
||||||
|
from_component in {"binglun_1", "binglun_2", "binglun_3"}
|
||||||
|
and connection["type"] == "power"
|
||||||
|
):
|
||||||
|
hub_ports[from_component] = connection["toPort"]
|
||||||
|
self.assertEqual(
|
||||||
|
hub_ports,
|
||||||
|
{
|
||||||
|
"binglun_1": "power_module_hub.west",
|
||||||
|
"binglun_2": "power_module_hub.south",
|
||||||
|
"binglun_3": "power_module_hub.east",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ def seed():
|
|||||||
# ============================================================
|
# ============================================================
|
||||||
# PHASE 0: Clean existing data (reverse dependency order)
|
# PHASE 0: Clean existing data (reverse dependency order)
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
cur.execute("DELETE FROM diagram_nodes")
|
||||||
|
cur.execute("DELETE FROM diagram_layouts")
|
||||||
cur.execute("DELETE FROM topology_connections")
|
cur.execute("DELETE FROM topology_connections")
|
||||||
cur.execute("DELETE FROM component_states")
|
cur.execute("DELETE FROM component_states")
|
||||||
cur.execute("DELETE FROM component_versions")
|
cur.execute("DELETE FROM component_versions")
|
||||||
@@ -106,6 +108,9 @@ def seed():
|
|||||||
events["BL-01_0"] = add_event("BL-01",
|
events["BL-01_0"] = add_event("BL-01",
|
||||||
ts("2024-04-19T22:58:00Z"), 0, "component_introduced",
|
ts("2024-04-19T22:58:00Z"), 0, "component_introduced",
|
||||||
"冰轮一号着陆东方海", source_ref="Timeline.md BL-01")
|
"冰轮一号着陆东方海", source_ref="Timeline.md BL-01")
|
||||||
|
events["BL-01_terminal"] = add_event("BL-01",
|
||||||
|
ts("2024-05-17T23:01:00Z"), 1, "mission_checkpoint",
|
||||||
|
"BL-01任务最后记录", source_ref="Timeline.md BL-01末条记录")
|
||||||
|
|
||||||
# ---- GHC-01 ----
|
# ---- GHC-01 ----
|
||||||
events["GHC-01_0"] = add_event("GHC-01",
|
events["GHC-01_0"] = add_event("GHC-01",
|
||||||
@@ -128,6 +133,9 @@ def seed():
|
|||||||
ts("2024-07-01T10:37:00Z"), 0, "connection_established",
|
ts("2024-07-01T10:37:00Z"), 0, "connection_established",
|
||||||
"冰轮一号与冰轮二号通过柔性管道完成燃料连接",
|
"冰轮一号与冰轮二号通过柔性管道完成燃料连接",
|
||||||
source_ref="Timeline.md GHC-02 EVA-1")
|
source_ref="Timeline.md GHC-02 EVA-1")
|
||||||
|
events["GHC-02_terminal"] = add_event("GHC-02",
|
||||||
|
ts("2024-07-15T03:16:00Z"), 1, "mission_checkpoint",
|
||||||
|
"GHC-02任务最后记录", source_ref="Timeline.md GHC-02末条记录")
|
||||||
|
|
||||||
# ---- GHC-03 ----
|
# ---- GHC-03 ----
|
||||||
events["GHC-03_0"] = add_event("GHC-03",
|
events["GHC-03_0"] = add_event("GHC-03",
|
||||||
@@ -150,6 +158,9 @@ def seed():
|
|||||||
"核反应堆以15%功率开始运行",
|
"核反应堆以15%功率开始运行",
|
||||||
details={"time_precision": "date", "power_percent": 15},
|
details={"time_precision": "date", "power_percent": 15},
|
||||||
source_ref="Timeline.md GHC-03")
|
source_ref="Timeline.md GHC-03")
|
||||||
|
events["GHC-03_terminal"] = add_event("GHC-03",
|
||||||
|
ts("2024-08-30T12:45:00Z"), 5, "mission_checkpoint",
|
||||||
|
"GHC-03任务最后记录", source_ref="Timeline.md GHC-03末条记录")
|
||||||
|
|
||||||
# ---- BL-03 ----
|
# ---- BL-03 ----
|
||||||
events["BL-03_0"] = add_event("BL-03",
|
events["BL-03_0"] = add_event("BL-03",
|
||||||
@@ -186,6 +197,9 @@ def seed():
|
|||||||
ts("2024-11-08T00:00:00Z"), 6, "connection_established",
|
ts("2024-11-08T00:00:00Z"), 6, "connection_established",
|
||||||
"冰轮三号接入基地统一燃料/电力网络",
|
"冰轮三号接入基地统一燃料/电力网络",
|
||||||
details={"time_precision": "date"}, source_ref="Timeline.md GHC-04 EVA-16")
|
details={"time_precision": "date"}, source_ref="Timeline.md GHC-04 EVA-16")
|
||||||
|
events["GHC-04_terminal"] = add_event("GHC-04",
|
||||||
|
ts("2024-11-20T13:57:00Z"), 7, "mission_checkpoint",
|
||||||
|
"GHC-04任务最后记录", source_ref="Timeline.md GHC-04末条记录")
|
||||||
|
|
||||||
# ---- GHC-05 ----
|
# ---- GHC-05 ----
|
||||||
events["GHC-05_0"] = add_event("GHC-05",
|
events["GHC-05_0"] = add_event("GHC-05",
|
||||||
@@ -224,6 +238,9 @@ def seed():
|
|||||||
"核反应堆功率调整至30%,全基地整合验证完成",
|
"核反应堆功率调整至30%,全基地整合验证完成",
|
||||||
details={"time_precision": "date", "power_percent": 30},
|
details={"time_precision": "date", "power_percent": 30},
|
||||||
source_ref="Timeline.md GHC-05 EVA-15")
|
source_ref="Timeline.md GHC-05 EVA-15")
|
||||||
|
events["GHC-05_terminal"] = add_event("GHC-05",
|
||||||
|
ts("2025-01-22T10:52:00Z"), 9, "mission_checkpoint",
|
||||||
|
"GHC-05任务最后记录", source_ref="Timeline.md GHC-05末条记录")
|
||||||
|
|
||||||
print(f"Events: {len(events)}")
|
print(f"Events: {len(events)}")
|
||||||
|
|
||||||
@@ -511,10 +528,13 @@ def seed():
|
|||||||
# GHC-04: Binglun fuel & power network
|
# GHC-04: Binglun fuel & power network
|
||||||
bl_events = {"binglun_1": "GHC-04_4", "binglun_2": "GHC-04_5",
|
bl_events = {"binglun_1": "GHC-04_4", "binglun_2": "GHC-04_5",
|
||||||
"binglun_3": "GHC-04_6"}
|
"binglun_3": "GHC-04_6"}
|
||||||
|
hub_ports = {"binglun_1": "west", "binglun_2": "south",
|
||||||
|
"binglun_3": "east"}
|
||||||
for bl, ev in bl_events.items():
|
for bl, ev in bl_events.items():
|
||||||
add_connection(bl, "fuel_port", "power_module_hub", "west",
|
hub_port = hub_ports[bl]
|
||||||
|
add_connection(bl, "fuel_port", "power_module_hub", hub_port,
|
||||||
"fuel", ev)
|
"fuel", ev)
|
||||||
add_connection(bl, "power_port", "power_module_hub", "west",
|
add_connection(bl, "power_port", "power_module_hub", hub_port,
|
||||||
"power", ev)
|
"power", ev)
|
||||||
|
|
||||||
# GHC-05: Core <-> four new modules (structural)
|
# GHC-05: Core <-> four new modules (structural)
|
||||||
|
|||||||
Reference in New Issue
Block a user