MCPcopy Create free account
hub / github.com/Tong89/smartNode / load

Method load

backend/scenario.py:128–172  ·  view source on GitHub ↗

从场景字典恢复引擎资源配置。 只恢复可在运行时动态调整的资源数量(地面站、LEO 卫星)。 Parameters ---------- engine: ``SimulationEngine`` 实例。 data: 符合 Scenario Schema 的字典(由 :meth:`save` 生成或导入)。 Returns ------- dict 包含恢复结果摘要的字典。

(engine: Any, data: Dict[str, Any])

Source from the content-addressed store, hash-verified

126
127 @staticmethod
128 def load(engine: Any, data: Dict[str, Any]) -> Dict[str, Any]:
129 """从场景字典恢复引擎资源配置。
130
131 只恢复可在运行时动态调整的资源数量(地面站、LEO 卫星)。
132
133 Parameters
134 ----------
135 engine:
136 ``SimulationEngine`` 实例。
137 data:
138 符合 Scenario Schema 的字典(由 :meth:`save` 生成或导入)。
139
140 Returns
141 -------
142 dict
143 包含恢复结果摘要的字典。
144 """
145 errors = ScenarioManager.validate(data)
146 if errors:
147 raise ValueError("场景数据非法: " + "; ".join(errors))
148
149 changes: List[str] = []
150
151 gs_count = data.get("ground_station_count")
152 if gs_count is not None and isinstance(gs_count, int):
153 current_gs = len(engine.ground_stations)
154 if gs_count != current_gs:
155 engine.update_ground_station_count(gs_count)
156 changes.append(f"地面站: {current_gs} → {gs_count}")
157
158 leo_count = data.get("leo_satellite_count")
159 if leo_count is not None and isinstance(leo_count, int):
160 current_leo = len(engine.leo_satellites)
161 if leo_count != current_leo:
162 engine.update_leo_satellite_count(leo_count)
163 changes.append(f"LEO卫星: {current_leo} → {leo_count}")
164
165 return {
166 "restored": True,
167 "scenario_name": data.get("name", ""),
168 "saved_at": data.get("saved_at", ""),
169 "changes": changes,
170 "ground_station_count": len(engine.ground_stations),
171 "leo_satellite_count": len(engine.leo_satellites),
172 }
173
174 @staticmethod
175 def validate(data: Any) -> List[str]:

Callers 10

load_fileMethod · 0.80
scenario_loadFunction · 0.80
scenario_importFunction · 0.80
load_scenarioFunction · 0.80
switch_toMethod · 0.80
_load_goldenFunction · 0.80
goldenFunction · 0.80
_load_goldenFunction · 0.80
generate_goldenFunction · 0.80

Calls 5

appendMethod · 0.80
validateMethod · 0.45
getMethod · 0.45

Tested by 5

_load_goldenFunction · 0.64
goldenFunction · 0.64
_load_goldenFunction · 0.64
generate_goldenFunction · 0.64