diff --git a/app/for_ai/codes_import_from_excel.py b/app/for_ai/codes_import_from_excel.py index 755d59f..58bdd45 100644 --- a/app/for_ai/codes_import_from_excel.py +++ b/app/for_ai/codes_import_from_excel.py @@ -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)) -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 : df = pd.read_excel(file_excel, sheet_name=0, header=1) else: df = pd.read_excel(file_excel, sheet_name=0, header=None) - count = 0 + rows_list = df.to_dict(orient='records') total = len(rows_list) print('total : ', total) column_names = df.columns.tolist() - print('=========== parseCodesToExcel ===== column_names : ', column_names) col_names = {} col_new_count = 0 @@ -359,29 +358,39 @@ def parseCodesToExcel(elastic, file_excel, index_name_o, tcode_label, file_log, bulk_data = [] total_update=0 row_number = 0 + count = 0 + try: 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"]] ts_date = row[col_names["ts_date"]] qanon_title = row[col_names["qanon_title"]] code_state = row[col_names["code_state"]] - row_number = row[col_names["row_number"]] if section_title != section_title : # Nan continue if isinstance(section_title, int) : # ردیف اول continue - + qanon_id = 0 section_id = 0 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) : 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 == '' : directory_path = os.path.dirname(file_excel) result_path = directory_path + "/result/" + try: + os.makedirs(result_path, exist_ok=True) + except : + pass file_name = os.path.basename(file_excel) 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() -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 : @@ -600,7 +613,6 @@ def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_t else: df = pd.read_excel(file_excel, sheet_name=0, header=None) - count = 0 rows_list = df.to_dict(orient='records') 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 row_number = 0 correct_rows = [] + count = 0 try: 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_id = "" - row_number = row[col_names["row_number"]] + section_title = row[col_names["section_title"]] code_state = row[col_names["code_state"]] 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 : section_id = section_id_new - count = count + 1 - if (count % 10) == 0 : - print("%s, %.2f " % ( '================== ', (count / total) * 100 if total > 0 else 0)) - data={} # ذخیره کد برای شناسه های یافت شده if section_id and section_id != 0: - - if jump_ids and section_id in jump_ids : - continue + _source = {} 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" 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 : print('00000 error 000000 ', code_name) diff --git a/app/for_ai/majles_codes_update_2_steps.py b/app/for_ai/majles_codes_update_2_steps.py index d7edaec..307dc67 100644 --- a/app/for_ai/majles_codes_update_2_steps.py +++ b/app/for_ai/majles_codes_update_2_steps.py @@ -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_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) diff --git a/app/majles/import_context_rules.py b/app/majles/import_context_rules_v1.py similarity index 100% rename from app/majles/import_context_rules.py rename to app/majles/import_context_rules_v1.py diff --git a/app/majles/import_context_rules_v2.py b/app/majles/import_context_rules_v2.py index f453214..2b4a0b0 100644 --- a/app/majles/import_context_rules_v2.py +++ b/app/majles/import_context_rules_v2.py @@ -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", "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" # elastic.restorFileToElastic2('G:/Project2/102_gpu/mj_qa_context.zip', 'mj_qa_context', 'majles', False, 'mj_qa_context', mapping_file_path) diff --git a/app/parvande_qanon/s1_excel_qavanin_procces.py b/app/parvande_qanon/s1_excel_qavanin_procces.py index e3ad411..5ff1430 100644 --- a/app/parvande_qanon/s1_excel_qavanin_procces.py +++ b/app/parvande_qanon/s1_excel_qavanin_procces.py @@ -254,11 +254,22 @@ def process_after_simple(df, period_map, base_subfolder_name): folder_contents = folder_cache[full_path] - found_file_name = None + found_file_name = [] for f in folder_contents: root, ext = os.path.splitext(f) 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 # df.at[idx, "وجود فایل"] = "دارد" if found_file_name else "ندارد" @@ -275,7 +286,9 @@ def process_after_simple(df, period_map, base_subfolder_name): else : df.at[idx, "وجود فایل"] = "دارد" 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 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_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_after = pd.read_excel(excel_file2, sheet_name=0)