This commit is contained in:
hsafaei
2026-07-04 14:35:30 +03:30
parent ed1e7fe6b6
commit cd3c93c7ae
3 changed files with 95 additions and 216 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ from elasticsearch import AsyncElasticsearch, helpers
from elasticsearch.helpers import async_bulk ,BulkIndexError from elasticsearch.helpers import async_bulk ,BulkIndexError
class ElasticHelper: class ElasticHelperAsync:
""" """
کلاس ElasticHelper: کلاس ElasticHelper:
نوع ورودی: بدون ورودی مستقیم در تعریف کلاس نوع ورودی: بدون ورودی مستقیم در تعریف کلاس
+22 -15
View File
@@ -377,20 +377,6 @@ body_v3={
} }
} }
# C_avg_su, C_avg_cd, C_avg_rt = compute_avg_all(elastic, "mj_qa_conflict", body_v3)
# #--------------------------------------------------
# #----- subject_unity total_vote, total_count, avge : 283938.199999187 314203 0.9036775587731085
# #----------
# #----- conflict_detections total_vote, total_count, avge : -337630.80000177945 314203 -1.0745626235324917
# #----------
# #----- conflict_relation_identifications total_vote, total_count, avge : 41412.600000000915 114953 0.3602568006054728
# #--------------------------------------------------
# #--------------------------------------------------
C_avg_su = 0.9036775587731085
C_avg_cd = -1.0745626235324917
C_avg_rt = 0.3602568006054728
# C_avg_rt = 0.30
body_103={ body_103={
"query": { "query": {
"nested": { "nested": {
@@ -430,8 +416,29 @@ body_no_rank={
} }
# C_avg_su, C_avg_cd, C_avg_rt = compute_avg_all(elastic, "mj_qa_conflict", body_v3)
# #--------------------------------------------------
# #----- subject_unity total_vote, total_count, avge : 283938.199999187 314203 0.9036775587731085
# #----------
# #----- conflict_detections total_vote, total_count, avge : -337630.80000177945 314203 -1.0745626235324917
# #----------
# #----- conflict_relation_identifications total_vote, total_count, avge : 41412.600000000915 114953 0.3602568006054728
# #--------------------------------------------------
# #--------------------------------------------------
C_avg_su = 0.9036775587731085
# C_avg_cd = -1.0745626235324917
C_avg_cd = 0
C_avg_rt = 0.3602568006054728
### -----103 بسته -----------
# C_avg_su = 0.1315904139433552
# C_avg_cd = 0.09096573208722765
# C_avg_rt = 0.6596421471172959
# re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, body_103) # re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, body_103)
re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, body_no_rank) ### ---------------------------
# re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, body_no_rank)
# re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, body_v3) # re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, body_v3)
## ----------------------------------------------------------------------- ## -----------------------------------------------------------------------
+70 -198
View File
@@ -12,7 +12,8 @@ import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
from app.common.elastic_helper_async import ElasticHelper from app.common.elastic_helper_async import ElasticHelperAsync
from app.common.elastic_helper import ElasticHelper
from app.common.general_functions import * from app.common.general_functions import *
from app.common.text_normalizer import TextNormalizer from app.common.text_normalizer import TextNormalizer
from app.common.data_helper import DataHelper from app.common.data_helper import DataHelper
@@ -178,7 +179,7 @@ def convert_import_data_to_es(item, jump_ids=None):
return es_data return es_data
def import_conflict_to_elastic(input_path, out_put_index_name, file_jump_ids): def import_conflict_to_elastic(elastic, input_path, out_put_index_name, file_jump_ids):
jump_ids = [] jump_ids = []
if os.path.exists(file_jump_ids): if os.path.exists(file_jump_ids):
@@ -270,7 +271,7 @@ async def async_import_data_from_json(file, index_name, file_jumps, host, passwo
file_name = file.split("/")[-1:][0] file_name = file.split("/")[-1:][0]
print("▶️", file_name) print("▶️", file_name)
elastic = ElasticHelper( elastic = ElasticHelperAsync(
es_url=host, es_pass=password, es_user="elastic" es_url=host, es_pass=password, es_user="elastic"
) )
data_all = [] data_all = []
@@ -785,7 +786,7 @@ async def async_append_conflict_to_elastic(
list_files.append(input_path) list_files.append(input_path)
elastic = ElasticHelper( es_url=host, es_pass=password, es_user="elastic") elastic = ElasticHelperAsync( es_url=host, es_pass=password, es_user="elastic")
for file in list_files: for file in list_files:
@@ -951,50 +952,39 @@ def genrate_excel_data(
] ]
} }
}, },
"sort": [{"previous_info.ts_date": "desc"}], "sort": [
{"conflict_rank.subject_unity_bayes": "desc"},
{"conflict_rank.conflict_detection_bayes": "desc"},
{"conflict_rank.relation_identification_bayes": "desc"},
]
} }
print(body) print(body)
columns = [ columns = [
"ردیف", "ردیف",
"شناسه", "شناسه",
"لینک داخلی",
"لینک", "لینک",
"موضوع/تعداد",
"موضوع/میانگین",
"موضوع/امتیاز",
"وحدت موضوع خبره", "وحدت موضوع خبره",
"توضیح خبره", "توضیح خبره",
"امتیاز ماشینی",
"وحدت موضوع oss120", "تخالف/تعداد",
"وحدت موضوع qwen3-6", "تخالف/میانگین",
"وحدت موضوع gemma4-p2", "تخالف/امتیاز",
"وحدت موضوع oss120-p2",
"وحدت موضوع qwen3-6-p2", "تخالف خبره",
"وحدت موضوع openyourmind",
"تخالف حکمی خبره",
"توضیح خبره", "توضیح خبره",
"امتیاز ماشینی",
"تخالف حکمی oss120", "نوع رابطه/تعداد",
"تخالف حکمی qwen3-6", "نوع رابطه/میانگین",
"تخالف حکمی gemma4-p2", "نوع رابطه/امتیاز",
"تخالف حکمی oss120-p2",
"تخالف حکمی qwen3-6-p2",
"تخالف حکمی openyourmind",
"نوع رابطه خبره", "نوع رابطه خبره",
"توضیح خبره", "توضیح خبره",
"امتیاز ماشینی",
"نوع رابطه oss120",
"نوع رابطه qwen3-6",
"نوع رابطه gemma4-p2",
"نوع رابطه oss120-p2",
"نوع رابطه qwen3-6-p2",
"نوع رابطه openyourmind",
"ارزیابی آخر خبره",
"توضیح خبره",
"امتیاز ماشینی",
"ارزیابی آخر oss120",
"ارزیابی آخر qwen3-6",
"ارزیابی آخر gemma4-p2",
"ارزیابی آخر oss120-p2",
"ارزیابی آخر qwen3-6-p2",
"ارزیابی آخر openyourmind",
] ]
# Create DataFrame with column names # Create DataFrame with column names
@@ -1004,13 +994,6 @@ def genrate_excel_data(
print(str(e)) print(str(e))
return return
# data_out = [
# ["John", 25, "New York"],
# ["Sarah", 30, "London"],
# ["Mike", 28, "Toronto"],
# ["Emma", 35, "Sydney"],
# ]
data = list(list_) data = list(list_)
total = len(data) total = len(data)
count = 0 count = 0
@@ -1027,169 +1010,40 @@ def genrate_excel_data(
next_info = entry.get("next_info", {}) next_info = entry.get("next_info", {})
previous_info = entry.get("previous_info", {}) previous_info = entry.get("previous_info", {})
subject_unitys = entry.get("subject_unitys", {}) # subject_unitys = entry.get("subject_unitys", {})
conflict_detections = entry.get("conflict_detections", {}) # conflict_detections = entry.get("conflict_detections", {})
conflict_type_detections = entry.get("conflict_type_detections", {}) # # conflict_type_detections = entry.get("conflict_type_detections", {})
conflict_relation_identifications = entry.get( # conflict_relation_identifications = entry.get(
"conflict_relation_identifications", {} # "conflict_relation_identifications", {}
) # )
conflict_evaluations = entry.get("conflict_evaluations", {}) # conflict_evaluations = entry.get("conflict_evaluations", {})
conflict_finals = entry.get("conflict_finals", {}) # # conflict_finals = entry.get("conflict_finals", {})
conflict_rank = entry.get("conflict_rank", {})
link = f'=HYPERLINK("{base_url}/refine/conflict/{_id}", "لینک")' link1 = f'=HYPERLINK("{base_url}/refine/conflict/{_id}", "لینک داخلی")'
link2 = f'=HYPERLINK("https://majles.tavasi.ir/refine/conflict/{_id}", "لینک")'
subject_rate = 0
subject_oss120 = ""
subject_qwen3_6 = ""
subject_gemma4_p2 = ""
subject_oss120_p2 = ""
subject_qwen3_6p2 = ""
subject_openyourmind = ""
for su in subject_unitys:
if su["ref_key"] == "oss120":
subject_oss120 = su["main_type"]
# subject_rate += getRate(su["main_type"])
if su["ref_key"] == "qwen3-6":
subject_qwen3_6 = su["main_type"]
subject_rate += getRate(su["main_type"])
if su["ref_key"] == "gemma4-p2":
subject_gemma4_p2 = su["main_type"]
subject_rate += getRate(su["main_type"])
if su["ref_key"] == "oss120-p2":
subject_oss120_p2 = su["main_type"]
subject_rate += getRate(su["main_type"])
if su["ref_key"] == "qwen3-6-p2":
subject_qwen3_6p2 = su["main_type"]
subject_rate += getRate(su["main_type"])
if su["ref_key"] == "openyourmind":
subject_openyourmind = su["main_type"]
subject_rate += getRate(su["main_type"])
conflict_rate = 0
conflict_oss120 = ""
conflict_qwen3_6 = ""
conflict_gemma4_p2 = ""
conflict_oss120_p2 = ""
conflict_qwen3_6p2 = ""
conflict_openyourmind = ""
for su in conflict_detections:
if su["ref_key"] == "oss120":
conflict_oss120 = str(su["has_conflict"])
# conflict_rate += getRate(su["has_conflict"])
if su["ref_key"] == "qwen3-6":
conflict_qwen3_6 = str(su["has_conflict"])
conflict_rate += getRate(su["has_conflict"])
if su["ref_key"] == "gemma4-p2":
conflict_gemma4_p2 = str(su["has_conflict"])
conflict_rate += getRate(su["has_conflict"])
if su["ref_key"] == "oss120-p2":
conflict_oss120_p2 = str(su["has_conflict"])
conflict_rate += getRate(su["has_conflict"])
if su["ref_key"] == "qwen3-6-p2":
conflict_qwen3_6p2 = str(su["has_conflict"])
conflict_rate += getRate(su["has_conflict"])
if su["ref_key"] == "openyourmind":
conflict_openyourmind = str(su["has_conflict"])
conflict_rate += getRate(su["has_conflict"])
relation_rate = 0
relation_oss120 = ""
relation_qwen3_6 = ""
relation_gemma4_p2 = ""
relation_oss120_p2 = ""
relation_qwen3_6p2 = ""
relation_openyourmind = ""
for su in conflict_relation_identifications:
if su["ref_key"] == "oss120":
relation_oss120 = su["main_type"]
# relation_rate += getRate(su["main_type"])
if su["ref_key"] == "qwen3-6":
relation_qwen3_6 = su["main_type"]
relation_rate += getRate(su["main_type"])
if su["ref_key"] == "gemma4-p2":
relation_gemma4_p2 = su["main_type"]
relation_rate += getRate(su["main_type"])
if su["ref_key"] == "oss120-p2":
relation_oss120_p2 = su["main_type"]
relation_rate += getRate(su["main_type"])
if su["ref_key"] == "qwen3-6-p2":
relation_qwen3_6p2 = su["main_type"]
relation_rate += getRate(su["main_type"])
if su["ref_key"] == "openyourmind":
relation_openyourmind = su["main_type"]
relation_rate += getRate(su["main_type"])
evalution_rate = 0
evalution_oss120 = ""
evalution_qwen3_6 = ""
evalution_gemma4_p2 = ""
evalution_oss120_p2 = ""
evalution_qwen3_6p2 = ""
evalution_openyourmind = ""
for su in conflict_evaluations:
if su["ref_key"] == "qwen3-6":
evalution_oss120 = su["main_type"]
# evalution_rate += getRate(su["main_type"])
if su["ref_key"] == "qwen3-6":
evalution_qwen3_6 = su["main_type"]
evalution_rate += getRate(su["main_type"])
if su["ref_key"] == "gemma4-p2":
evalution_gemma4_p2 = su["main_type"]
evalution_rate += getRate(su["main_type"])
if su["ref_key"] == "oss120-p2":
evalution_oss120_p2 = su["main_type"]
evalution_rate += getRate(su["main_type"])
if su["ref_key"] == "qwen3-6-p2":
evalution_qwen3_6p2 = su["main_type"]
evalution_rate += getRate(su["main_type"])
if su["ref_key"] == "openyourmind":
evalution_openyourmind = su["main_type"]
evalution_rate += getRate(su["main_type"])
item = [ item = [
str(count), str(count),
_id, _id,
link, link1,
link2,
conflict_rank["subject_unity_count"],
conflict_rank["subject_unity_avg"],
conflict_rank["subject_unity_bayes"],
"", "",
"", "",
subject_rate, conflict_rank["conflict_detection_count"],
subject_oss120, conflict_rank["conflict_detection_avg"],
subject_qwen3_6, conflict_rank["conflict_detection_bayes"],
subject_gemma4_p2,
subject_oss120_p2,
subject_qwen3_6p2,
subject_openyourmind,
"", "",
"", "",
conflict_rate, conflict_rank["relation_identification_count"],
conflict_oss120, conflict_rank["relation_identification_avg"],
conflict_qwen3_6, conflict_rank["relation_identification_bayes"],
conflict_gemma4_p2,
conflict_oss120_p2,
conflict_qwen3_6p2,
conflict_openyourmind,
"", "",
"", ""
relation_rate,
relation_oss120,
relation_qwen3_6,
relation_gemma4_p2,
relation_oss120_p2,
relation_qwen3_6p2,
relation_openyourmind,
"",
"",
evalution_rate,
evalution_oss120,
evalution_qwen3_6,
evalution_gemma4_p2,
evalution_oss120_p2,
evalution_qwen3_6p2,
evalution_openyourmind,
] ]
print(item) print(item)
@@ -1228,10 +1082,18 @@ if __name__ == "__main__":
print(".... host ......", host) print(".... host ......", host)
path_base_map = "G:/Project2/tavasi_160/src/repo/_other/"
## ---------------------------------------------------- ## ----------------------------------------------------
## ---------------------------------------------------- ## ----------------------------------------------------
# path_base_map = "G:/Project2/tavasi_160/src/repo/_other/" # elastic = ElasticHelper(es_url=host,es_pass= password,es_user= "elastic", path_mappings=path_base_map)
# elastic = ElasticHelper(es_url=f"http://{host}:6900",es_pass= password,es_user= "elastic", path_mappings=path_base_map)
# elastic.backupIndexToZipfile("G:/Project2/111/server160", "mj_qa_context", "mj_qa_context")
# elastic.backupIndexToZipfile("G:/Project2/111/server160", "mj_qa_rule", "mj_qa_rule")
# elastic.backupIndexToZipfile("G:/Project2/111/server160", "mj_qa_conflict", "mj_qa_conflict")
# elastic.createIndex( 'mj_qa_conflict', 'majles', 'mj_qa_conflict', path_base_map+ 'majles/'+'mj_qa_conflict.json' )
# elastic.restorFileToElastic2('G:/Project2/111/server160/mj_qa_conflict.zip', 'mj_qa_conflict', 'majles', False)
# map_file = "G:/Project2/tavasi_160/src/repo/_other/majles/mj_qa_conflict.json" # map_file = "G:/Project2/tavasi_160/src/repo/_other/majles/mj_qa_conflict.json"
# elastic.createIndex(index_name="mj_qa_conflict",map_name="mj_qa_conflict",mapping_file_path=map_file) # elastic.createIndex(index_name="mj_qa_conflict",map_name="mj_qa_conflict",mapping_file_path=map_file)
@@ -1247,7 +1109,8 @@ if __name__ == "__main__":
# file_jumps = r"G:\Project2\102_gpu\v3_conflict\285k_group_v3_jump_files.json" # file_jumps = r"G:\Project2\102_gpu\v3_conflict\285k_group_v3_jump_files.json"
##---- not async ------ ##---- not async ------
# ## import_conflict_to_elastic(input_path, "mj_qa_conflict", file_jumps) # elastic = ElasticHelper(es_url=host,es_pass= password,es_user= "elastic", path_mappings=path_base_map)
# ## import_conflict_to_elastic(elastic, input_path, "mj_qa_conflict", file_jumps)
# asyncio.run( # asyncio.run(
# async_pack_files_to_elastic( # async_pack_files_to_elastic(
@@ -1263,6 +1126,7 @@ if __name__ == "__main__":
## ----------------------------------------------------------------------- ## -----------------------------------------------------------------------
## ----------------------------------------------------------------------- ## -----------------------------------------------------------------------
# elastic = ElasticHelper(es_url=host,es_pass= password,es_user= "elastic", path_mappings=path_base_map)
# fields=[ # fields=[
# "subject_unity", # "subject_unity",
# "conflict_detection", # "conflict_detection",
@@ -1391,3 +1255,11 @@ if __name__ == "__main__":
# ) # )
# elastic = ElasticHelper(es_url=host,es_pass= password,es_user= "elastic", path_mappings=path_base_map)
# file_ouput = r"G:\Project2\102_gpu\v3_conflict\v3_103_pair.xlsx"
# genrate_excel_data(elastic, file_ouput, "mj_qa_conflict", "subject_unitys", "gemma4_103", "http://192.168.23.160" )
## -----------------------------------------------------------------------
# .\.env\Scripts\activate
# python -m app.majles.majles_conflict_works_v2