Update app.py
Browse files
app.py
CHANGED
|
@@ -403,12 +403,14 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 403 |
else: new_cols.append(col)
|
| 404 |
return df[new_cols]
|
| 405 |
|
|
|
|
| 406 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 407 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 408 |
if "Error" in df.columns: return df
|
| 409 |
-
|
| 410 |
return apply_visual_merge(df, df.columns)
|
| 411 |
|
|
|
|
| 412 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
| 413 |
df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 414 |
df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, type_c)
|
|
@@ -433,7 +435,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 433 |
|
| 434 |
conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
|
| 435 |
|
| 436 |
-
# 1. ์์ ์ฝ๋๋ก ๋กค๋ฐฑ: ์ผ๋จ ๋งคํ ๋ฐ์ดํฐ๋ฅผ ์ ๋ถ ๋ค ๊ฐ์ ธ์ต๋๋ค. (DB ์กฐ๊ฑด ์ค๋ฅ ์์ฒ ์ฐจ๋จ)
|
| 437 |
q_fw = "SELECT * FROM Mapping_table WHERE TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Comp_std)=? AND TRIM(Comp_ver)=?"
|
| 438 |
df_fw = pd.read_sql(q_fw, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
|
| 439 |
|
|
@@ -441,25 +442,21 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 441 |
df_rv = pd.read_sql(q_rv, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
|
| 442 |
conn_map.close()
|
| 443 |
|
| 444 |
-
# 2. ํ์ด์ฌ(Pandas)์์ Type์ ์ ํํ๊ณ ์์ ํ๊ฒ ํํฐ๋งํฉ๋๋ค.
|
| 445 |
cols_fw_lower = {c.lower(): c for c in df_fw.columns}
|
| 446 |
|
| 447 |
if 'base_type' in cols_fw_lower and 'comp_type' in cols_fw_lower:
|
| 448 |
b_col = cols_fw_lower['base_type']
|
| 449 |
c_col = cols_fw_lower['comp_type']
|
| 450 |
|
| 451 |
-
# ์ ๋ฐฉํฅ ํํฐ
|
| 452 |
df_fw[b_col] = df_fw[b_col].fillna('Main').astype(str).str.strip().str.upper()
|
| 453 |
df_fw[c_col] = df_fw[c_col].fillna('Main').astype(str).str.strip().str.upper()
|
| 454 |
df_fw = df_fw[(df_fw[b_col] == type_b.strip().upper()) & (df_fw[c_col] == type_c.strip().upper())]
|
| 455 |
|
| 456 |
-
# ์ญ๋ฐฉํฅ ํํฐ (DB์ Comp๊ฐ ๋ด Base, DB์ Base๊ฐ ๋ด Comp)
|
| 457 |
if not df_rv.empty:
|
| 458 |
df_rv[b_col] = df_rv[b_col].fillna('Main').astype(str).str.strip().str.upper()
|
| 459 |
df_rv[c_col] = df_rv[c_col].fillna('Main').astype(str).str.strip().str.upper()
|
| 460 |
df_rv = df_rv[(df_rv[c_col] == type_b.strip().upper()) & (df_rv[b_col] == type_c.strip().upper())]
|
| 461 |
|
| 462 |
-
# 3. ํ์ํ ์ปฌ๋ผ๋ง ์ถ์ถํด์ ๋ณํฉ
|
| 463 |
b_sec = cols_fw_lower.get('base_section', 'Base_section')
|
| 464 |
c_sec = cols_fw_lower.get('comp_section', 'Comp_section')
|
| 465 |
|
|
@@ -482,7 +479,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 482 |
else:
|
| 483 |
df_mapping = pd.DataFrame(columns=['Base_section', 'Comp_section'])
|
| 484 |
|
| 485 |
-
# 4. ๋ค๋ฅธ ๋ฒ๊ท/๋ค๋ฅธ ํ
์ด๋ธ์ผ ๋๋ ๊ฐ์ ์๋ ๋งคํ ๊ธ์ง (์ด ์์น์ ์ ์ง)
|
| 486 |
if base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper():
|
| 487 |
implicit = pd.DataFrame({'Base_section': list(set(df_base['merge_key']) & set(df_comp['merge_key'])),
|
| 488 |
'Comp_section': list(set(df_base['merge_key']) & set(df_comp['merge_key']))})
|
|
@@ -490,10 +486,10 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 490 |
else:
|
| 491 |
bridge = df_mapping.copy()
|
| 492 |
|
| 493 |
-
|
| 494 |
-
|
| 495 |
rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
|
| 496 |
df_base = df_base.rename(columns=rename_b)
|
|
|
|
| 497 |
rename_c = {c: f"{c}_{comp_ver}" for c in df_comp.columns if c != 'merge_key'}
|
| 498 |
df_comp = df_comp.rename(columns=rename_c)
|
| 499 |
|
|
@@ -522,6 +518,7 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 522 |
row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
|
| 523 |
result_rows.append(row_dict)
|
| 524 |
|
|
|
|
| 525 |
final_df = combine_code_desc(pd.DataFrame(result_rows))
|
| 526 |
|
| 527 |
b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]
|
|
|
|
| 403 |
else: new_cols.append(col)
|
| 404 |
return df[new_cols]
|
| 405 |
|
| 406 |
+
# 1. ๋จ์ผ ์กฐํ (์ฌ๊ธฐ์ ์๋ combine_code_desc๋ฅผ ์ญ์ ํ์ต๋๋ค!)
|
| 407 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 408 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 409 |
if "Error" in df.columns: return df
|
| 410 |
+
# ์ด์ ๋ถ๋ฆฌ๋ ์ํ ๊ทธ๋๋ก ์ ์งํ๊ณ , ์ค๋ณต ๋น์นธ ์ฒ๋ฆฌ๋ง ์ํ
|
| 411 |
return apply_visual_merge(df, df.columns)
|
| 412 |
|
| 413 |
+
# 2. ๋น๊ต ์กฐํ
|
| 414 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
| 415 |
df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 416 |
df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, type_c)
|
|
|
|
| 435 |
|
| 436 |
conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
|
| 437 |
|
|
|
|
| 438 |
q_fw = "SELECT * FROM Mapping_table WHERE TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Comp_std)=? AND TRIM(Comp_ver)=?"
|
| 439 |
df_fw = pd.read_sql(q_fw, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
|
| 440 |
|
|
|
|
| 442 |
df_rv = pd.read_sql(q_rv, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
|
| 443 |
conn_map.close()
|
| 444 |
|
|
|
|
| 445 |
cols_fw_lower = {c.lower(): c for c in df_fw.columns}
|
| 446 |
|
| 447 |
if 'base_type' in cols_fw_lower and 'comp_type' in cols_fw_lower:
|
| 448 |
b_col = cols_fw_lower['base_type']
|
| 449 |
c_col = cols_fw_lower['comp_type']
|
| 450 |
|
|
|
|
| 451 |
df_fw[b_col] = df_fw[b_col].fillna('Main').astype(str).str.strip().str.upper()
|
| 452 |
df_fw[c_col] = df_fw[c_col].fillna('Main').astype(str).str.strip().str.upper()
|
| 453 |
df_fw = df_fw[(df_fw[b_col] == type_b.strip().upper()) & (df_fw[c_col] == type_c.strip().upper())]
|
| 454 |
|
|
|
|
| 455 |
if not df_rv.empty:
|
| 456 |
df_rv[b_col] = df_rv[b_col].fillna('Main').astype(str).str.strip().str.upper()
|
| 457 |
df_rv[c_col] = df_rv[c_col].fillna('Main').astype(str).str.strip().str.upper()
|
| 458 |
df_rv = df_rv[(df_rv[c_col] == type_b.strip().upper()) & (df_rv[b_col] == type_c.strip().upper())]
|
| 459 |
|
|
|
|
| 460 |
b_sec = cols_fw_lower.get('base_section', 'Base_section')
|
| 461 |
c_sec = cols_fw_lower.get('comp_section', 'Comp_section')
|
| 462 |
|
|
|
|
| 479 |
else:
|
| 480 |
df_mapping = pd.DataFrame(columns=['Base_section', 'Comp_section'])
|
| 481 |
|
|
|
|
| 482 |
if base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper():
|
| 483 |
implicit = pd.DataFrame({'Base_section': list(set(df_base['merge_key']) & set(df_comp['merge_key'])),
|
| 484 |
'Comp_section': list(set(df_base['merge_key']) & set(df_comp['merge_key']))})
|
|
|
|
| 486 |
else:
|
| 487 |
bridge = df_mapping.copy()
|
| 488 |
|
| 489 |
+
# (์ค๋ณต ์์ฑ๋ rename_b ์ญ์ ์๋ฃ)
|
|
|
|
| 490 |
rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
|
| 491 |
df_base = df_base.rename(columns=rename_b)
|
| 492 |
+
|
| 493 |
rename_c = {c: f"{c}_{comp_ver}" for c in df_comp.columns if c != 'merge_key'}
|
| 494 |
df_comp = df_comp.rename(columns=rename_c)
|
| 495 |
|
|
|
|
| 518 |
row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
|
| 519 |
result_rows.append(row_dict)
|
| 520 |
|
| 521 |
+
# ๋น๊ต ์กฐํ ์์๋ ๋ฒํธ์ ์ค๋ช
์ ํฉ์นฉ๋๋ค
|
| 522 |
final_df = combine_code_desc(pd.DataFrame(result_rows))
|
| 523 |
|
| 524 |
b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]
|