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

Method get_system_data

backend/core.py:2214–2288  ·  view source on GitHub ↗

获取系统完整数据 - 优化锁持有时间

(self)

Source from the content-addressed store, hash-verified

2212 }
2213
2214 def get_system_data(self):
2215 """获取系统完整数据 - 优化锁持有时间"""
2216 # ⭐ 快速获取关键数据的快照,减少锁持有时间
2217 with self.lock:
2218 current_time = self.current_time
2219 # 复制请求列表引用(快照)
2220 all_reqs = list(self.transmission_requests) + list(self.request_history)
2221 stats_copy = self.stats.copy()
2222 leo_sats = list(self.leo_satellites)
2223 meo_sats = list(self.meo_satellites)
2224 geo_relays = list(self.geo_relays)
2225 ground_stations = list(self.ground_stations)
2226 all_gs = list(self.all_ground_stations) # 快照,避免锁外迭代被并发改写
2227
2228 # ⭐ 在锁外进行数据序列化(耗时操作)
2229 requests_data = [req.to_dict() for req in all_reqs]
2230
2231 data = {
2232 "time": current_time,
2233 "satellites": [],
2234 "ground_stations": [],
2235 "geo_relays": [],
2236 "all_ground_stations": all_gs,
2237 "requests": requests_data,
2238 "stats": stats_copy
2239 }
2240
2241 # LEO卫星(在锁外计算位置)
2242 for sat in leo_sats:
2243 pos = self.get_satellite_position(sat)
2244 data["satellites"].append({
2245 "id": sat.sat_id,
2246 "name": sat.name,
2247 "type": "LEO",
2248 "lat": pos["lat"],
2249 "lon": pos["lon"],
2250 "alt": pos["alt"],
2251 "orbit_period": sat.get_orbital_period()
2252 })
2253
2254 # MEO卫星
2255 for sat in meo_sats:
2256 pos = self.get_satellite_position(sat)
2257 data["satellites"].append({
2258 "id": sat.sat_id,
2259 "name": sat.name,
2260 "type": "MEO",
2261 "lat": pos["lat"],
2262 "lon": pos["lon"],
2263 "alt": pos["alt"],
2264 "orbit_period": sat.get_orbital_period()
2265 })
2266
2267 # GEO中继星
2268 for geo in geo_relays:
2269 pos = self.get_geo_position(geo)
2270 coverage = geo.get("coverage", {})
2271 data["geo_relays"].append({

Callers 1

get_simulation_dataFunction · 0.80

Calls 6

get_geo_positionMethod · 0.95
appendMethod · 0.80
get_orbital_periodMethod · 0.80
to_dictMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected