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

Method update_leo_satellite_count

backend/core.py:2057–2091  ·  view source on GitHub ↗

⭐ 更新LEO卫星数量 - 轨道参数预先已知,支持动态生成补充,无上限。 合并自此前两份重复定义:保留动态生成(_generate_random_leo)与减少时的 _handle_removed_satellites 处理,并按前后激活列表的 ID 差集精确计算被移除卫星。

(self, new_count)

Source from the content-addressed store, hash-verified

2055 return False
2056
2057 def update_leo_satellite_count(self, new_count):
2058 """⭐ 更新LEO卫星数量 - 轨道参数预先已知,支持动态生成补充,无上限。
2059
2060 合并自此前两份重复定义:保留动态生成(_generate_random_leo)与减少时的
2061 _handle_removed_satellites 处理,并按前后激活列表的 ID 差集精确计算被移除卫星。
2062 """
2063 with self.lock:
2064 # 仅验证最小值
2065 new_count = max(MIN_LEO_SATELLITE_COUNT, int(new_count))
2066
2067 old_count = len(self.leo_satellites)
2068 old_ids = [sat.sat_id for sat in self.leo_satellites]
2069 if new_count == old_count:
2070 return False
2071
2072 # 新数量超过库存时动态生成补充
2073 current_total = len(self.all_leo_satellites)
2074 if new_count > current_total:
2075 for i in range(new_count - current_total):
2076 self.all_leo_satellites.append(
2077 self._generate_random_leo(current_total + i + 1)
2078 )
2079
2080 # 更新激活的卫星列表(轨道参数已知,位置实时计算)
2081 self.leo_satellite_count = new_count
2082 self.leo_satellites = self.all_leo_satellites[:self.leo_satellite_count]
2083
2084 # 减少卫星时,按前后激活 ID 差集精确处理被移除卫星上的请求
2085 if new_count < old_count:
2086 active_ids = set(sat.sat_id for sat in self.leo_satellites)
2087 removed_sat_ids = [sid for sid in old_ids if sid not in active_ids]
2088 if removed_sat_ids:
2089 self._handle_removed_satellites(removed_sat_ids)
2090
2091 return True
2092
2093 def _handle_removed_satellites(self, removed_sat_ids):
2094 """处理被移除卫星上的请求 - 重新分配或拒绝"""

Callers 4

update_leo_satellitesFunction · 0.80
loadMethod · 0.80

Calls 3

_generate_random_leoMethod · 0.95
appendMethod · 0.80

Tested by 2