Update app.py
Browse files
app.py
CHANGED
|
@@ -54,7 +54,6 @@ def fetch_available_standards():
|
|
| 54 |
})
|
| 55 |
return sorted(list(set([d["standard"] for d in db_registry])))
|
| 56 |
|
| 57 |
-
# ๐ก [ํต์ฌ ์์ ] ๋จ์ผ ์กฐํ ์ "์ ๋ถ ๋ณด์ฌ์ฃผ๊ธฐ" ์ํด Display_Columns ํํฐ๋ง ์กฑ์๋ฅผ ์์ ํ ์ ๊ฑฐํ์ต๋๋ค!
|
| 58 |
def fetch_database_records(std, ver, cat, table_type):
|
| 59 |
try:
|
| 60 |
db_path = os.path.join(UPLOAD_DIR, f"{std}_{ver}.db")
|
|
@@ -101,7 +100,6 @@ def fetch_database_records(std, ver, cat, table_type):
|
|
| 101 |
if matched_config is None:
|
| 102 |
matched_config = config_df.iloc[0]
|
| 103 |
|
| 104 |
-
# ๋ผ๋(Anchor)๋ ์ฐพ๋, ํ์ํ ์ด(Display) ์ ํ์ ํ์์ต๋๋ค!
|
| 105 |
anchors = [x.strip() for x in matched_config['Anchor_Column'].split(',')]
|
| 106 |
|
| 107 |
query = f"SELECT * FROM [{main_table}]"
|
|
@@ -125,7 +123,11 @@ def fetch_database_records(std, ver, cat, table_type):
|
|
| 125 |
|
| 126 |
real_anchors = [c for c in df.columns if any(a.lower() == c.lower() for a in anchors)]
|
| 127 |
|
| 128 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
for c in df.columns:
|
| 130 |
df[c] = df[c].apply(convert_blob_to_html_img)
|
| 131 |
|
|
@@ -433,13 +435,11 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 433 |
else: new_cols.append(col)
|
| 434 |
return df[new_cols]
|
| 435 |
|
| 436 |
-
# ๐ก ๋จ์ผ ์กฐํ ์: Table_Config ์ ํ ์์ด ์๋ ๊ทธ๋๋ก '์ ๋ถ' ๋์ ธ์ค๋๋ค. (combine_code_desc ์ ์ฉ X)
|
| 437 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 438 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 439 |
if "Error" in df.columns: return df
|
| 440 |
return apply_visual_merge(df, df.columns)
|
| 441 |
|
| 442 |
-
# ๐ก ๋น๊ต ์กฐํ ์: combine_code_desc ํจ์๋ฅผ ์ ์ฉํ์ฌ _Code์ _Description์ ํฉ์นฉ๋๋ค.
|
| 443 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
| 444 |
df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 445 |
df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, type_c)
|
|
@@ -460,10 +460,13 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 460 |
s = s[:-2]
|
| 461 |
return s.replace(" ", "")
|
| 462 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
|
| 464 |
df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
|
| 465 |
|
| 466 |
-
# ๐ก [1.o o, 2.o x, 3.x o ๋ก์ง] ๊ฐ์ ๋ฒ๊ท์ธ ๊ฒฝ์ฐ ํฉ์งํฉ(Union) ์์ฑ
|
| 467 |
is_same_std = (base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper())
|
| 468 |
|
| 469 |
if is_same_std:
|
|
@@ -537,10 +540,7 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 537 |
else:
|
| 538 |
bridge = pd.DataFrame(columns=['Base_section', 'Comp_section'])
|
| 539 |
|
| 540 |
-
rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
|
| 541 |
df_base = df_base.rename(columns=rename_b)
|
| 542 |
-
|
| 543 |
-
rename_c = {c: f"{c}_{comp_ver}" for c in df_comp.columns if c != 'merge_key'}
|
| 544 |
df_comp = df_comp.rename(columns=rename_c)
|
| 545 |
|
| 546 |
df_base['base_idx'], df_comp['comp_idx'] = range(len(df_base)), range(len(df_comp))
|
|
@@ -575,7 +575,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 575 |
row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
|
| 576 |
result_rows.append(row_dict)
|
| 577 |
|
| 578 |
-
# ๐ก ๋น๊ต ์กฐํ ์ ํฉ์น๊ธฐ ํจ์(combine_code_desc) ์ ์ฉ!
|
| 579 |
final_df = combine_code_desc(pd.DataFrame(result_rows))
|
| 580 |
|
| 581 |
if final_df.empty:
|
|
@@ -587,8 +586,9 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 587 |
if final_df.empty:
|
| 588 |
return pd.DataFrame({"Info": ["๐ก ์ ํํ์ ์กฐ๊ฑด ๊ฐ์ ๋ณ๊ฒฝ๋ ๋ด์ฉ์ด ์์ต๋๋ค. (100% ๋์ผ)"]})
|
| 589 |
|
| 590 |
-
|
| 591 |
-
|
|
|
|
| 592 |
|
| 593 |
final_df = apply_visual_merge(final_df, b_cols_final)
|
| 594 |
final_df = apply_visual_merge(final_df, c_cols_final)
|
|
|
|
| 54 |
})
|
| 55 |
return sorted(list(set([d["standard"] for d in db_registry])))
|
| 56 |
|
|
|
|
| 57 |
def fetch_database_records(std, ver, cat, table_type):
|
| 58 |
try:
|
| 59 |
db_path = os.path.join(UPLOAD_DIR, f"{std}_{ver}.db")
|
|
|
|
| 100 |
if matched_config is None:
|
| 101 |
matched_config = config_df.iloc[0]
|
| 102 |
|
|
|
|
| 103 |
anchors = [x.strip() for x in matched_config['Anchor_Column'].split(',')]
|
| 104 |
|
| 105 |
query = f"SELECT * FROM [{main_table}]"
|
|
|
|
| 123 |
|
| 124 |
real_anchors = [c for c in df.columns if any(a.lower() == c.lower() for a in anchors)]
|
| 125 |
|
| 126 |
+
# ๐ก [ํต์ฌ ํด๊ฒฐ] UI ํ
์คํธ๋ฐ์ค์ Status๊ฐ ํ๊ธฐ๋๋ฏ๋ก, ์๋ ํ์์๋ Status ์ด์ ์น ์ง์์ค๋๋ค.
|
| 127 |
+
status_cols = [c for c in df.columns if c.lower() == 'status']
|
| 128 |
+
if status_cols:
|
| 129 |
+
df = df.drop(columns=status_cols)
|
| 130 |
+
|
| 131 |
for c in df.columns:
|
| 132 |
df[c] = df[c].apply(convert_blob_to_html_img)
|
| 133 |
|
|
|
|
| 435 |
else: new_cols.append(col)
|
| 436 |
return df[new_cols]
|
| 437 |
|
|
|
|
| 438 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 439 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 440 |
if "Error" in df.columns: return df
|
| 441 |
return apply_visual_merge(df, df.columns)
|
| 442 |
|
|
|
|
| 443 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
| 444 |
df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 445 |
df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, type_c)
|
|
|
|
| 460 |
s = s[:-2]
|
| 461 |
return s.replace(" ", "")
|
| 462 |
|
| 463 |
+
# ๐ก [ํด๊ฒฐ 1] ๊ฐ์ ์ด๋ฆ ์ถฉ๋ ๋ฐฉ์ง: ๋ณํฉ ์ ๊ฐ๊ฐ (๊ธฐ์ค), (๋น๊ต) ํ๊ทธ๋ฅผ ๋ฌ์์ค๋๋ค.
|
| 464 |
+
rename_b = {c: f"{c}_{base_ver}(๊ธฐ์ค)" for c in df_base.columns if c != 'merge_key'}
|
| 465 |
+
rename_c = {c: f"{c}_{comp_ver}(๋น๊ต)" for c in df_comp.columns if c != 'merge_key'}
|
| 466 |
+
|
| 467 |
df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
|
| 468 |
df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
|
| 469 |
|
|
|
|
| 470 |
is_same_std = (base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper())
|
| 471 |
|
| 472 |
if is_same_std:
|
|
|
|
| 540 |
else:
|
| 541 |
bridge = pd.DataFrame(columns=['Base_section', 'Comp_section'])
|
| 542 |
|
|
|
|
| 543 |
df_base = df_base.rename(columns=rename_b)
|
|
|
|
|
|
|
| 544 |
df_comp = df_comp.rename(columns=rename_c)
|
| 545 |
|
| 546 |
df_base['base_idx'], df_comp['comp_idx'] = range(len(df_base)), range(len(df_comp))
|
|
|
|
| 575 |
row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
|
| 576 |
result_rows.append(row_dict)
|
| 577 |
|
|
|
|
| 578 |
final_df = combine_code_desc(pd.DataFrame(result_rows))
|
| 579 |
|
| 580 |
if final_df.empty:
|
|
|
|
| 586 |
if final_df.empty:
|
| 587 |
return pd.DataFrame({"Info": ["๐ก ์ ํํ์ ์กฐ๊ฑด ๊ฐ์ ๋ณ๊ฒฝ๋ ๋ด์ฉ์ด ์์ต๋๋ค. (100% ๋์ผ)"]})
|
| 588 |
|
| 589 |
+
# ๐ก [ํด๊ฒฐ 1 ํธํ] ์๋กญ๊ฒ ์ง์ ํ (๊ธฐ๏ฟฝ๏ฟฝ), (๋น๊ต) ํ๊ทธ๋ก ๋ณํฉ ์
์ฒ๋ฆฌ
|
| 590 |
+
b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}(๊ธฐ์ค)")]
|
| 591 |
+
c_cols_final = [c for c in final_df.columns if c.endswith(f"_{comp_ver}(๋น๊ต)")]
|
| 592 |
|
| 593 |
final_df = apply_visual_merge(final_df, b_cols_final)
|
| 594 |
final_df = apply_visual_merge(final_df, c_cols_final)
|