遗传002
This commit is contained in:
@@ -63,7 +63,7 @@ def fitness(individual, controller_db_obj):
|
||||
|
||||
do_process(controller_db_obj,ga_id,dct_exp,job)
|
||||
# ========== 3️⃣ 获取数据库连接并提取结果 ==========
|
||||
simulated_vulnerable_industries = get_vulnerable100_code(connection,ga_id)
|
||||
simulated_vulnerable_industries = get_vulnerable35_code(connection,ga_id)
|
||||
print(simulated_vulnerable_industries)
|
||||
# ========== 4️⃣ 获取目标产业集合 ==========
|
||||
target_vulnerable_industries = get_target_vulnerable_industries()
|
||||
@@ -154,9 +154,11 @@ def get_target_vulnerable_industries():
|
||||
{"product": "过程工艺检测", "category": "制程检测", "chain_id": 513740}
|
||||
]
|
||||
# 手工转换
|
||||
industry_list_index = vulnerable100_index = \
|
||||
['100', '58', '61', '9', '7', '98', '57', '8', '65', '68', '66', '38',
|
||||
'90', '21', '96', '71', '27', '74', '99', '95', '11', '77', '59', '56', '97']
|
||||
merged_list = [
|
||||
'61', '68', '65', '66', '59', '71', '77', '7', '38', '95', '58', '90', '56', '57', '97', '98',
|
||||
'27', '8', '11', '9', '21', '96', '99', '100', '44', '45', '46', '47', '48', '49', '50', '51',
|
||||
'52', '53', '54', '55'
|
||||
]
|
||||
# # 提取所有 chain_id,并去重
|
||||
# chain_ids = set()
|
||||
# for item in industry_list:
|
||||
@@ -167,9 +169,10 @@ def get_target_vulnerable_industries():
|
||||
# else:
|
||||
# chain_ids.add(str(item["chain_id"]))
|
||||
|
||||
return industry_list_index
|
||||
return merged_list
|
||||
|
||||
# 从数据库计算脆弱产业集合
|
||||
def get_vulnerable100_code(engine, ga_id):
|
||||
def get_vulnerable35_code(engine, ga_id):
|
||||
"""
|
||||
计算最脆弱前100产品的 Code 列表(去重),只针对指定 ga_id。
|
||||
"""
|
||||
@@ -221,7 +224,7 @@ def get_vulnerable100_code(engine, ga_id):
|
||||
# ===============================
|
||||
# 5️⃣ 选出最脆弱的前100个产品(出现次数最多)
|
||||
# ===============================
|
||||
vulnerable100_product = count_prod.nlargest(100, "count")["id_product"].tolist()
|
||||
vulnerable100_product = count_prod.nlargest(35, "count")["id_product"].tolist()
|
||||
print(f"[信息] ga_id={ga_id} 查询完成,共找到 {len(vulnerable100_product)} 个脆弱产品")
|
||||
|
||||
# ===============================
|
||||
|
||||
Reference in New Issue
Block a user