codes rapair

This commit is contained in:
hsafaei
2026-02-21 13:52:57 +03:30
parent 763490f395
commit ea011dfc9d
4 changed files with 176 additions and 39 deletions
+129 -29
View File
@@ -129,7 +129,7 @@ def extract_json_context_id_rules_labels(
print(f"failed -=>{failed}<=-")
def extract_json_files(elastic, file_json, file_import_ids, file_type="groups", version_key="v2"):
def extract_groups_of_json_files(elastic, file_json, file_import_ids, file_type="groups", version_key="v2"):
bulk_data = []
total_count = 0
@@ -161,6 +161,8 @@ def extract_json_files(elastic, file_json, file_import_ids, file_type="groups",
version_key
)
jump_ids.append(qanon_id)
except Exception as e:
print("error in file " + qanon_id + str(e))
@@ -791,7 +793,7 @@ def import_rules_qanon(elastic, qanon_id, data, bulk_data, total_count, index_na
log_file.write(5 * "*" + error + "\n")
continue
if "qanon_etebar" in source:
if "qanon_title" in source:
qanon_title = source["qanon_title"]
if "qanon_etebar" in source:
qanon_etebar = source["qanon_etebar"]
@@ -842,6 +844,93 @@ def import_rules_qanon(elastic, qanon_id, data, bulk_data, total_count, index_na
return bulk_data, total_count
def import_rules_of_json(elastic, file, index_name_o, version_key="v2"):
bulk_data = []
total_count = 0
input_data = DataHelper.load_orjson(file)
index_name_i = "mj_qa_context"
for item in input_data:
context_id = item["groups_id"]
qanon_id = item["qanon_id"]
rule_order = 0
rule_id = item["id"]
rule_order = int(rule_id.split('-')[1]) + 1
content = item["content"]
rule_type = item["main_type"]
qanon_title = ""
qanon_etebar = ""
state_etebar = ""
ts_date = None
ts_ref = ""
group_section_ids = []
source = None
try:
res = elastic.get_document(index_name_i, context_id)
source = res["_source"]
except:
error = (
" section_mom_id not found in qa_context :"
+ qanon_id
+ ":"
+ context_id
)
if log_file:
log_file.write(5 * "*" + error + "\n")
continue
if "qanon_title" in source:
qanon_title = source["qanon_title"]
if "qanon_etebar" in source:
qanon_etebar = source["qanon_etebar"]
if "ts_date" in source:
ts_date = source["ts_date"]
if "ts_ref" in source:
ts_ref = source["ts_ref"]
if "state_etebar" in source:
state_etebar = source["state_etebar"]
if "group_section_ids" in source:
group_section_ids = source["group_section_ids"]
eid = rule_id
data = {
"id": eid,
"context_id": context_id,
"version_key": "base_"+version_key,
"qanon_id": qanon_id,
"qanon_title": qanon_title,
"qanon_etebar": qanon_etebar,
"state_etebar": state_etebar,
"ts_date": ts_date,
"ts_ref": ts_ref,
"rule_order": rule_order,
"rule_type": rule_type,
"content": content,
"group_section_ids": group_section_ids,
"time_create": int(round(time.time() * 1000)),
}
bulk_data.append({"_id": eid, "_source": data})
if len(bulk_data) >= 100:
total_count += len(bulk_data)
print(
"=" * 10, "to_elastic , total=" + str(total_count), ", id=" + eid
)
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
return bulk_data, total_count
if __name__ == "__main__":
@@ -854,7 +943,7 @@ if __name__ == "__main__":
# log_file = open(f"G:/Project2/102_gpu/v2/log_{data_key}_1.txt", mode="w", encoding="utf8")
# file = f"G:/Project2/102_gpu/v2/mj_qa_chunks.json"
# file_import_ids = f"G:/Project2/102_gpu/v2/{data_key}_import_ids.txt"
# extract_json_files(elastic, file, file_import_ids, data_key, "v2")
# extract_groups_of_json_files(elastic, file, file_import_ids, data_key, "v2")
# log_file.close()
# ### ----------------------------------------------
@@ -874,17 +963,50 @@ if __name__ == "__main__":
# file_import_ids = f"G:/Project2/102_gpu/{data_key}_import_ids.txt"
# extract_zip_files(elastic, filezip, file_import_ids, data_key, "v2")
# log_file.close()
### -------- repai error 1 groups--------------------------------------
### -------------------------------------------
# در گروه بندی که با nlp_child
# بود ، ترتیب بچه درست لحاظ نشده بود و باعث خطا در محتوای گروههای چند سکشنی شد
# لذا بعد از شناسایی و اصلاح موارد مذکور جدید اضافه شد و قبلی ها پاک شد
# data_key = "groups"
# log_file = open(f"G:/Project2/102_gpu/v2/error_log_{data_key}_1.txt", mode="w", encoding="utf8")
# file = f"G:/Project2/102_gpu/v2/f1_valid_5099_mj_qa_chunked_ids_28_11_1404.json"
# file_import_ids = f"G:/Project2/102_gpu/v2/error1_{data_key}_import_ids.txt"
# import_error_groups_json(elastic, file, file_import_ids, data_key, "v2")
# log_file.close()
# fill_error_context_json(elastic, file, file_import_ids, data_key, "v2")
# log_file.close()
# #--- حذف موارد خطای قبل
# file_json = f"G:/Project2/102_gpu/v2/error1_delete_ids.json"
# data_json = DataHelper.load_orjson(file_json)
# body={
# "query":{
# "ids": {"values": data_json }
# }
# }
# elastic.deleteByQueryIndex("mj_qa_context", body)
# ### ----------------------------------------------
# data_key = "rules"
# log_file = open(
# f"G:/Project2/102_gpu/log_{data_key}_1.txt", mode="w", encoding="utf8"
# f"G:/Project2/102_gpu/v2/log_{data_key}_1.txt", mode="w", encoding="utf8"
# )
# filezip = f"G:/Project2/102_gpu/{data_key}.zip"
# file_import_ids = f"G:/Project2/102_gpu/{data_key}_import_ids.txt"
# extract_zip_files(elastic, filezip, file_import_ids, data_key)
# file = f"G:/Project2/102_gpu/v2/rules_v2_433252.json"
# file_import_ids = f"G:/Project2/102_gpu/v2/{data_key}_import_ids.txt"
# import_rules_of_json(elastic, file, "mj_qa_rule", "v2")
# log_file.close()
# ### ----------------------------------------------
# data_key = "rules_labels"
# # label_object
@@ -907,27 +1029,5 @@ if __name__ == "__main__":
# ### ----------------------------------------------
### -------- repai error 1 groups--------------------------------------
### -------------------------------------------
# در گروه بندی که با nlp_child
# بود ، ترتیب بچه درست لحاظ نشده بود و باعث خطا در محتوای گروههای چند سکشنی شد
# لذا بعد از شناسایی و اصلاح موارد مذکور جدید اضافه شد و قبلی ها پاک شد
# data_key = "groups"
# log_file = open(f"G:/Project2/102_gpu/v2/error_log_{data_key}_1.txt", mode="w", encoding="utf8")
# file = f"G:/Project2/102_gpu/v2/f1_valid_5099_mj_qa_chunked_ids_28_11_1404.json"
# file_import_ids = f"G:/Project2/102_gpu/v2/error1_{data_key}_import_ids.txt"
# import_error_groups_json(elastic, file, file_import_ids, data_key, "v2")
# log_file.close()
# fill_error_context_json(elastic, file, file_import_ids, data_key, "v2")
# log_file.close()
### -------------------------------------------
# python -m dataParsers.app.import_context_rules
# print(":D")