codes result
This commit is contained in:
@@ -179,7 +179,7 @@ def searchQanonId(elastic, index_name, qanon_title, ts_data=""):
|
||||
return 0, 0, {}
|
||||
|
||||
|
||||
def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, result_path = ""):
|
||||
def importDataToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_id , file_log, result_path = ""):
|
||||
# excel_helper = ExcelHelper()
|
||||
# df = excel_helper.load_data(file)
|
||||
|
||||
@@ -206,6 +206,8 @@ def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, resu
|
||||
dic_error_qanon_title={}
|
||||
dic_error_section_title={}
|
||||
rows_list_new = []
|
||||
bulk_data = []
|
||||
total_count=0
|
||||
try:
|
||||
for row in rows_list:
|
||||
section_title = row[column_names[0]]
|
||||
@@ -213,7 +215,10 @@ def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, resu
|
||||
qanon_title = row[column_names[2]]
|
||||
code_state = row[column_names[3]]
|
||||
row_number = row[column_names[4]]
|
||||
|
||||
if code_state :
|
||||
print ( 'ddddddddddddddcode_state' , code_state)
|
||||
else :
|
||||
print ( 'ccccccccccccccode_state' , code_state)
|
||||
qanon_id = 0
|
||||
section_id = 0
|
||||
state = ''
|
||||
@@ -236,14 +241,18 @@ def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, resu
|
||||
|
||||
score = 100
|
||||
|
||||
# ابتدا از قانونهای خاص که شناسه ذخیره شده دارند جستجو کند
|
||||
if qanon_title in dict_qanon_id :
|
||||
score = 100
|
||||
qanon_id = dict_qanon_id[qanon_title]
|
||||
state = 'قانون-دستی'
|
||||
# if qanon_id == 0 :
|
||||
# continue # این قانون در بانک ما وجود ندارد
|
||||
|
||||
# اگر پیدا نشد، از الاستیک جستجو کند
|
||||
if qanon_id == 0 :
|
||||
qanon_id, score, item = searchQanonId(elastic, "mj_qa_qanon", qanon_title, ts_date)
|
||||
qanon_id, score, item = searchQanonId(elastic, "mj_qa_qanon", qanon_title, ts_date)
|
||||
# اگر قابل اطمینان نبود، خطا ثبت کند
|
||||
if score < 90 :
|
||||
dic_error_qanon_title[qanon_title]=count
|
||||
print('-'*10 , str(count) , ' qanon error', qanon_title )
|
||||
@@ -252,9 +261,11 @@ def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, resu
|
||||
state = 'خطا-قانون'
|
||||
else:
|
||||
state = 'قانون-جستجو'
|
||||
|
||||
|
||||
# اگر شناسه قانون یافت شد، برای شناسه جزء جستجو کند ...
|
||||
if not qanon_id == 0 :
|
||||
section_id, score, section_item = searchSectionId(elastic, "mj_qa_section", qanon_id , section_title)
|
||||
# - اگر شناسه یافت شده جزء قابل اطمینان نبود خطا ثبت شود
|
||||
if score < 90 :
|
||||
dic_error_section_title[str(qanon_id)+'=='+section_title]=count
|
||||
print('='*10 , str(count) , ' section error', qanon_id, ' --> ', section_title )
|
||||
@@ -263,12 +274,57 @@ def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, resu
|
||||
state = 'خطا-جزء'
|
||||
else :
|
||||
state = 'صحیح'
|
||||
|
||||
|
||||
# ذخیره شناسه ها و وضعیت برای اکسل جدید
|
||||
row[5]=qanon_id
|
||||
row[6]=section_id
|
||||
row[7]=state
|
||||
rows_list_new.append(row)
|
||||
|
||||
data={}
|
||||
# ذخیره کد در الاستیک برای شناسه های یافت شده
|
||||
if section_id and section_id != 0:
|
||||
item = elastic.get_doctument(index_name_o,section_id)
|
||||
tcode_mains = []
|
||||
tcode_subs = []
|
||||
if "tcode_mains" in item['_source'] :
|
||||
tcode_mains= item['_source']["tcode_mains"]
|
||||
if "tcode_subs" in item['_source'] :
|
||||
tcode_subs= item['_source']["tcode_subs"]
|
||||
|
||||
code = {
|
||||
"label" : tcode_label,
|
||||
"id" : tcode_id
|
||||
}
|
||||
if code_state :
|
||||
tcode_mains.append(code)
|
||||
else:
|
||||
tcode_subs.append(code)
|
||||
data={
|
||||
'_id':section_id,
|
||||
'_source' : {
|
||||
'tcode_mains': tcode_mains,
|
||||
'tcode_subs': tcode_subs,
|
||||
}
|
||||
}
|
||||
bulk_data.append(data)
|
||||
|
||||
|
||||
# انتقال دسته جمعی کدها به الاستیک
|
||||
if len(bulk_data) >= 200:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(count))
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
|
||||
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(count) )
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
|
||||
|
||||
# columns=['جزء', 'مصوب', 'قانون', 'اصلی', 'ردیف', 'شناسه قانون', 'شناسه جزء', 'وضعیت پردازش']
|
||||
columns=[0, 1, 2, 3, 4, 5, 6, 7]
|
||||
new_df = pd.DataFrame(rows_list_new, columns=columns)
|
||||
@@ -299,6 +355,17 @@ def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, resu
|
||||
|
||||
|
||||
def run_in_directory(elastic, directory, output):
|
||||
dic_code_id={
|
||||
"آب" : 1,
|
||||
"آمار، برنامه و بودجه" : 2,
|
||||
"آموزش و پرورش" : 3,
|
||||
"آیین دادرسی مدنی" : 5,
|
||||
"سلامت" : 30,
|
||||
"فرهنگ و هنر" : 33,
|
||||
"مسکن و شهرسازی" : 42,
|
||||
"مناطق آزاد و ویژه اقتصادی" : 45,
|
||||
"نفت و گاز" : 49
|
||||
}
|
||||
# List all files in the specified directory
|
||||
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
||||
for file in files :
|
||||
@@ -312,7 +379,14 @@ def run_in_directory(elastic, directory, output):
|
||||
except Exception as e:
|
||||
print(output)
|
||||
|
||||
importDataToElastic(elastic, file_path, "mj_qa_section", code_name, log_file)
|
||||
code_id = 0
|
||||
if code_name in dic_code_id :
|
||||
code_id = dic_code_id[code_name]
|
||||
importDataToElastic(elastic, file_path, "mj_qa_section", code_name, code_id, log_file)
|
||||
else :
|
||||
print('00000 error 000000 ', code_name)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user