1
This commit is contained in:
@@ -325,19 +325,18 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, file_l
|
|||||||
# file2.write(json.dumps(dic_error_section_title, ensure_ascii=False, indent=4))
|
# file2.write(json.dumps(dic_error_section_title, ensure_ascii=False, indent=4))
|
||||||
|
|
||||||
|
|
||||||
def parseCodesToExcel(elastic, file_excel, index_name_o, tcode_label, file_log, result_path, col_index, head_top=False):
|
def parseCodesToExcel(elastic, file_excel, index_name_o, tcode_label, file_log, result_path, col_index, head_top=False, jump_rows = []):
|
||||||
|
|
||||||
if head_top :
|
if head_top :
|
||||||
df = pd.read_excel(file_excel, sheet_name=0, header=1)
|
df = pd.read_excel(file_excel, sheet_name=0, header=1)
|
||||||
else:
|
else:
|
||||||
df = pd.read_excel(file_excel, sheet_name=0, header=None)
|
df = pd.read_excel(file_excel, sheet_name=0, header=None)
|
||||||
count = 0
|
|
||||||
rows_list = df.to_dict(orient='records')
|
rows_list = df.to_dict(orient='records')
|
||||||
total = len(rows_list)
|
total = len(rows_list)
|
||||||
print('total : ', total)
|
print('total : ', total)
|
||||||
|
|
||||||
column_names = df.columns.tolist()
|
column_names = df.columns.tolist()
|
||||||
print('=========== parseCodesToExcel ===== column_names : ', column_names)
|
|
||||||
|
|
||||||
col_names = {}
|
col_names = {}
|
||||||
col_new_count = 0
|
col_new_count = 0
|
||||||
@@ -359,13 +358,27 @@ def parseCodesToExcel(elastic, file_excel, index_name_o, tcode_label, file_log,
|
|||||||
bulk_data = []
|
bulk_data = []
|
||||||
total_update=0
|
total_update=0
|
||||||
row_number = 0
|
row_number = 0
|
||||||
|
count = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for row in rows_list:
|
for row in rows_list:
|
||||||
|
|
||||||
|
count = count + 1
|
||||||
|
if (count % 10) == 0 :
|
||||||
|
print("%s, %.2f " % ( '================== ', (count / total) * 100 if total > 0 else 0))
|
||||||
|
|
||||||
|
row_number = count
|
||||||
|
if "row_number" in col_names :
|
||||||
|
row_number = row[col_names["row_number"]]
|
||||||
|
|
||||||
|
|
||||||
|
if jump_rows and row_number in jump_rows :
|
||||||
|
continue
|
||||||
|
|
||||||
section_title = row[col_names["section_title"]]
|
section_title = row[col_names["section_title"]]
|
||||||
ts_date = row[col_names["ts_date"]]
|
ts_date = row[col_names["ts_date"]]
|
||||||
qanon_title = row[col_names["qanon_title"]]
|
qanon_title = row[col_names["qanon_title"]]
|
||||||
code_state = row[col_names["code_state"]]
|
code_state = row[col_names["code_state"]]
|
||||||
row_number = row[col_names["row_number"]]
|
|
||||||
|
|
||||||
if section_title != section_title : # Nan
|
if section_title != section_title : # Nan
|
||||||
continue
|
continue
|
||||||
@@ -378,10 +391,6 @@ def parseCodesToExcel(elastic, file_excel, index_name_o, tcode_label, file_log,
|
|||||||
section_id = 0
|
section_id = 0
|
||||||
state = ''
|
state = ''
|
||||||
|
|
||||||
count = count + 1
|
|
||||||
if (count % 10) == 0 :
|
|
||||||
print("%s, %.2f " % ( '================== ', (count / total) * 100 if total > 0 else 0))
|
|
||||||
|
|
||||||
|
|
||||||
if section_title is None or is_nan_or_none_or_empty(section_title) or qanon_title is None or is_nan_or_none_or_empty(qanon_title) :
|
if section_title is None or is_nan_or_none_or_empty(section_title) or qanon_title is None or is_nan_or_none_or_empty(qanon_title) :
|
||||||
file.write('!!!!!! nan error !!!!!!!' + str(count) + '\n')
|
file.write('!!!!!! nan error !!!!!!!' + str(count) + '\n')
|
||||||
@@ -449,6 +458,10 @@ def parseCodesToExcel(elastic, file_excel, index_name_o, tcode_label, file_log,
|
|||||||
if result_path == '' :
|
if result_path == '' :
|
||||||
directory_path = os.path.dirname(file_excel)
|
directory_path = os.path.dirname(file_excel)
|
||||||
result_path = directory_path + "/result/"
|
result_path = directory_path + "/result/"
|
||||||
|
try:
|
||||||
|
os.makedirs(result_path, exist_ok=True)
|
||||||
|
except :
|
||||||
|
pass
|
||||||
|
|
||||||
file_name = os.path.basename(file_excel)
|
file_name = os.path.basename(file_excel)
|
||||||
file_excel2 = result_path + file_name.replace('.xlsx', '_result.xlsx')
|
file_excel2 = result_path + file_name.replace('.xlsx', '_result.xlsx')
|
||||||
@@ -592,7 +605,7 @@ def importCodesToElastic(elastic, file_excel, index_name_o, tcode_label, file_lo
|
|||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_top=False, with_history_code={}, jump_ids = []):
|
def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_top=False, with_history_code={}, jump_rows = []):
|
||||||
|
|
||||||
|
|
||||||
if head_top :
|
if head_top :
|
||||||
@@ -600,7 +613,6 @@ def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_t
|
|||||||
else:
|
else:
|
||||||
df = pd.read_excel(file_excel, sheet_name=0, header=None)
|
df = pd.read_excel(file_excel, sheet_name=0, header=None)
|
||||||
|
|
||||||
count = 0
|
|
||||||
rows_list = df.to_dict(orient='records')
|
rows_list = df.to_dict(orient='records')
|
||||||
|
|
||||||
column_names = df.columns.tolist()
|
column_names = df.columns.tolist()
|
||||||
@@ -620,14 +632,28 @@ def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_t
|
|||||||
total_update=0
|
total_update=0
|
||||||
row_number = 0
|
row_number = 0
|
||||||
correct_rows = []
|
correct_rows = []
|
||||||
|
count = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for row in rows_list:
|
for row in rows_list:
|
||||||
|
|
||||||
|
|
||||||
|
count = count + 1
|
||||||
|
if (count % 10) == 0 :
|
||||||
|
print("%s, %.2f " % ( '================== ', (count / total) * 100 if total > 0 else 0))
|
||||||
|
|
||||||
|
|
||||||
|
row_number = count
|
||||||
|
if "row_number" in col_names :
|
||||||
|
row_number = row[col_names["row_number"]]
|
||||||
|
|
||||||
|
if jump_rows and row_number in jump_rows :
|
||||||
|
continue
|
||||||
|
|
||||||
section_title = ""
|
section_title = ""
|
||||||
section_id = ""
|
section_id = ""
|
||||||
|
|
||||||
row_number = row[col_names["row_number"]]
|
|
||||||
section_title = row[col_names["section_title"]]
|
section_title = row[col_names["section_title"]]
|
||||||
code_state = row[col_names["code_state"]]
|
code_state = row[col_names["code_state"]]
|
||||||
section_id = row[col_names["section_id"]]
|
section_id = row[col_names["section_id"]]
|
||||||
@@ -643,17 +669,11 @@ def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_t
|
|||||||
if not is_nan_or_none_or_empty(section_id_new) and section_id_new != 0 :
|
if not is_nan_or_none_or_empty(section_id_new) and section_id_new != 0 :
|
||||||
section_id = section_id_new
|
section_id = section_id_new
|
||||||
|
|
||||||
count = count + 1
|
|
||||||
if (count % 10) == 0 :
|
|
||||||
print("%s, %.2f " % ( '================== ', (count / total) * 100 if total > 0 else 0))
|
|
||||||
|
|
||||||
|
|
||||||
data={}
|
data={}
|
||||||
# ذخیره کد برای شناسه های یافت شده
|
# ذخیره کد برای شناسه های یافت شده
|
||||||
if section_id and section_id != 0:
|
if section_id and section_id != 0:
|
||||||
|
|
||||||
if jump_ids and section_id in jump_ids :
|
|
||||||
continue
|
|
||||||
|
|
||||||
_source = {}
|
_source = {}
|
||||||
history_codes= []
|
history_codes= []
|
||||||
@@ -807,9 +827,9 @@ def run_codes_extract_directory(directory, output, all_codes, col_index={}, head
|
|||||||
#-- موارد فوق استخراج و دوباره ارسال شود
|
#-- موارد فوق استخراج و دوباره ارسال شود
|
||||||
file_json = output + f"/{code_name}_err.json"
|
file_json = output + f"/{code_name}_err.json"
|
||||||
correct_rows = extract_codes_to_json(file_path, code_name, file_json, col_index, head_top, with_history_code)
|
correct_rows = extract_codes_to_json(file_path, code_name, file_json, col_index, head_top, with_history_code)
|
||||||
parseCodesToExcel(elastic, file_path, "mj_qa_section", code_name, log_file, "", col_index, head_top)
|
parseCodesToExcel(elastic, file_path, "mj_qa_section", code_name, log_file, "", col_index, head_top, correct_rows)
|
||||||
|
|
||||||
extract_codes_to_json(file_path, code_name, output + f"/{code_name}.json", col_index, head_top, with_history_code, correct_rows)
|
new_correct_rows = extract_codes_to_json(file_path, code_name, output + f"/{code_name}.json", col_index, head_top, with_history_code, correct_rows)
|
||||||
else :
|
else :
|
||||||
print('00000 error 000000 ', code_name)
|
print('00000 error 000000 ', code_name)
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,17 @@ col_index = {
|
|||||||
# run_codes_to_elastic_directory( elastic, "./data/tcodes/corrected_majles/not_edit4", "./data/tcodes/corrected_majles/not_edit4/result", all_codes, False, True, col_index, False)
|
# run_codes_to_elastic_directory( elastic, "./data/tcodes/corrected_majles/not_edit4", "./data/tcodes/corrected_majles/not_edit4/result", all_codes, False, True, col_index, False)
|
||||||
# run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit4/result","./data/tcodes/corrected_majles/not_edit4/result_json",all_codes,col_index,True)
|
# run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit4/result","./data/tcodes/corrected_majles/not_edit4/result_json",all_codes,col_index,True)
|
||||||
|
|
||||||
|
|
||||||
|
col_index = {
|
||||||
|
"section_title" : 0,
|
||||||
|
"ts_date" : 1,
|
||||||
|
"qanon_title" : 2,
|
||||||
|
"code_state" : 3,
|
||||||
|
"code_title" : 4,
|
||||||
|
"qanon_id" : 5,
|
||||||
|
"section_id" : 6,
|
||||||
|
"state_match" : 7,
|
||||||
|
}
|
||||||
##--- استخراج موارد خطای کد
|
##--- استخراج موارد خطای کد
|
||||||
run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit4/result","./data/tcodes/corrected_majles/not_edit4/result_json",all_codes,col_index, head_top=False, by_repair_error = True, elastic=elastic)
|
run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit4/result","./data/tcodes/corrected_majles/not_edit4/result_json",all_codes,col_index, head_top=False, by_repair_error = True, elastic=elastic)
|
||||||
|
|
||||||
|
|||||||
@@ -1017,8 +1017,10 @@ if __name__ == "__main__":
|
|||||||
# )
|
# )
|
||||||
|
|
||||||
# ### ----------------------------------------------
|
# ### ----------------------------------------------
|
||||||
|
|
||||||
# elastic.backupIndexToZipfile("G:/Project2/102_gpu/v2", "mj_qa_context", "mj_qa_context")
|
# elastic.backupIndexToZipfile("G:/Project2/102_gpu/v2", "mj_qa_context", "mj_qa_context")
|
||||||
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_rule", "mj_qa_rule")
|
# elastic.backupIndexToZipfile("G:/Project2/102_gpu/V2", "mj_qa_rule", "mj_qa_rule")
|
||||||
|
# elastic.backupIndexToZipfile("G:/Project2/102_gpu/V2", "mj_qa_conflict", "mj_qa_conflict")
|
||||||
|
|
||||||
# mapping_file_path = "G:/\Project2/tavasi_160/src/repo/_other/majles/mj_qa_context.json"
|
# mapping_file_path = "G:/\Project2/tavasi_160/src/repo/_other/majles/mj_qa_context.json"
|
||||||
# elastic.restorFileToElastic2('G:/Project2/102_gpu/mj_qa_context.zip', 'mj_qa_context', 'majles', False, 'mj_qa_context', mapping_file_path)
|
# elastic.restorFileToElastic2('G:/Project2/102_gpu/mj_qa_context.zip', 'mj_qa_context', 'majles', False, 'mj_qa_context', mapping_file_path)
|
||||||
|
|||||||
@@ -254,11 +254,22 @@ def process_after_simple(df, period_map, base_subfolder_name):
|
|||||||
|
|
||||||
folder_contents = folder_cache[full_path]
|
folder_contents = folder_cache[full_path]
|
||||||
|
|
||||||
found_file_name = None
|
found_file_name = []
|
||||||
for f in folder_contents:
|
for f in folder_contents:
|
||||||
root, ext = os.path.splitext(f)
|
root, ext = os.path.splitext(f)
|
||||||
if normalize_file_number(root).startswith(norm_search):
|
if normalize_file_number(root).startswith(norm_search):
|
||||||
found_file_name = f
|
pp = full_path + "/" + f
|
||||||
|
if os.path.isfile(pp) :
|
||||||
|
name = f.replace(full_path, '')
|
||||||
|
found_file_name.append( name )
|
||||||
|
if os.path.isdir(pp):
|
||||||
|
ff1 = os.listdir(pp)
|
||||||
|
for f1 in ff1 :
|
||||||
|
if os.path.isfile(pp + "/"+ f1) :
|
||||||
|
name = f1.replace(full_path, '')
|
||||||
|
found_file_name.append( root + "/" + name )
|
||||||
|
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
# df.at[idx, "وجود فایل"] = "دارد" if found_file_name else "ندارد"
|
# df.at[idx, "وجود فایل"] = "دارد" if found_file_name else "ندارد"
|
||||||
@@ -275,7 +286,9 @@ def process_after_simple(df, period_map, base_subfolder_name):
|
|||||||
else :
|
else :
|
||||||
df.at[idx, "وجود فایل"] = "دارد"
|
df.at[idx, "وجود فایل"] = "دارد"
|
||||||
df.at[idx, "مسیر"] = full_path.replace(base_folder,'')
|
df.at[idx, "مسیر"] = full_path.replace(base_folder,'')
|
||||||
name_files = os.path.basename(found_file_name) + ','
|
|
||||||
|
# name_files = os.path.basename(found_file_name) + ','
|
||||||
|
name_files =",".join( found_file_name) + ','
|
||||||
df.at[idx, "فایلها"] = name_files
|
df.at[idx, "فایلها"] = name_files
|
||||||
|
|
||||||
if re.match(pattern_after, normalize_file_number(shomare_parvande_val)):
|
if re.match(pattern_after, normalize_file_number(shomare_parvande_val)):
|
||||||
@@ -428,7 +441,7 @@ def main_proccess():
|
|||||||
|
|
||||||
excel_file1 = "data/qavanin_files/فهرست تمام قوانین_1_ 1 الی2378-رشیدزاده.xlsx"
|
excel_file1 = "data/qavanin_files/فهرست تمام قوانین_1_ 1 الی2378-رشیدزاده.xlsx"
|
||||||
excel_file2 = "data/qavanin_files/فهرست تمام قوانین_2_تکمیل شده.xlsx"
|
excel_file2 = "data/qavanin_files/فهرست تمام قوانین_2_تکمیل شده.xlsx"
|
||||||
output_file = "data/qavanin_files/qavanin_output4.xlsx"
|
output_file = "data/qavanin_files/qavanin_output5.xlsx"
|
||||||
df_before = pd.read_excel(excel_file1, sheet_name=0)
|
df_before = pd.read_excel(excel_file1, sheet_name=0)
|
||||||
df_after = pd.read_excel(excel_file2, sheet_name=0)
|
df_after = pd.read_excel(excel_file2, sheet_name=0)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user