Update app.py
Browse files
app.py
CHANGED
|
@@ -124,11 +124,6 @@ def fetch_database_records(std, ver, cat, table_type):
|
|
| 124 |
|
| 125 |
real_anchors = [c for c in df.columns if any(a.lower() == c.lower() for a in anchors)]
|
| 126 |
|
| 127 |
-
# π‘ [ν΅μ¬ λ‘μ§] Status μ΄μ UI μλ¨μ νκΈ°λλ―λ‘, μλ νμμλ κΉλνκ² μμ ν©λλ€!
|
| 128 |
-
status_cols = [c for c in df.columns if c.lower() == 'status']
|
| 129 |
-
if status_cols:
|
| 130 |
-
df = df.drop(columns=status_cols)
|
| 131 |
-
|
| 132 |
final_cols = []
|
| 133 |
for d in displays:
|
| 134 |
for c in df.columns:
|
|
@@ -415,6 +410,12 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 415 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 416 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 417 |
if "Error" in df.columns: return df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
return apply_visual_merge(df, df.columns)
|
| 419 |
|
| 420 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
|
@@ -437,14 +438,9 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 437 |
s = s[:-2]
|
| 438 |
return s.replace(" ", "")
|
| 439 |
|
| 440 |
-
# π‘ [ν΅μ¬ λ‘μ§] λ΄λΆ μ²λ¦¬μ© μμ 꼬리νλ₯Ό λ¬μ KeyErrorλ₯Ό μμ² μ°¨λ¨ν©λλ€!
|
| 441 |
-
internal_rename_b = {c: f"{c}_INTERNAL_BASE" for c in df_base.columns if c != 'merge_key'}
|
| 442 |
-
internal_rename_c = {c: f"{c}_INTERNAL_COMP" for c in df_comp.columns if c != 'merge_key'}
|
| 443 |
-
|
| 444 |
df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
|
| 445 |
df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
|
| 446 |
|
| 447 |
-
# π‘ [ν΅μ¬ λ‘μ§] λ§€ν μ₯λΆ(Mapping_registry)λ₯Ό 무쑰건 μ΅μ°μ μΌλ‘ κ²μ¬ν©λλ€.
|
| 448 |
conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
|
| 449 |
registry_query = """
|
| 450 |
SELECT Target_Table FROM Mapping_registry
|
|
@@ -512,14 +508,18 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 512 |
else:
|
| 513 |
bridge = pd.DataFrame(columns=['Base_section', 'Comp_section'])
|
| 514 |
|
| 515 |
-
# π‘ [
|
| 516 |
-
|
| 517 |
-
|
|
|
|
| 518 |
all_keys = list(set(df_base['merge_key']).union(set(df_comp['merge_key'])))
|
| 519 |
bridge = pd.DataFrame({'Base_section': all_keys, 'Comp_section': all_keys})
|
| 520 |
|
| 521 |
-
|
| 522 |
-
|
|
|
|
|
|
|
|
|
|
| 523 |
|
| 524 |
df_base['base_idx'], df_comp['comp_idx'] = range(len(df_base)), range(len(df_comp))
|
| 525 |
merged = pd.merge(bridge, df_base, left_on='Base_section', right_on='merge_key', how='outer')
|
|
@@ -535,21 +535,22 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 535 |
has_b = not pd.isna(row.get('base_idx')) and row.get('base_idx') != float('inf')
|
| 536 |
has_c = not pd.isna(row.get('comp_idx')) and row.get('comp_idx') != float('inf')
|
| 537 |
|
| 538 |
-
for c in
|
| 539 |
-
for c in
|
| 540 |
|
| 541 |
if mapped_only:
|
| 542 |
-
b_has_val = any(str(row_dict[c]).strip() not in ["", "nan", "None", " "] for c in
|
| 543 |
-
c_has_val = any(str(row_dict[c]).strip() not in ["", "nan", "None", " "] for c in
|
|
|
|
| 544 |
if not (b_has_val and c_has_val):
|
| 545 |
continue
|
| 546 |
|
| 547 |
if has_b and has_c:
|
| 548 |
-
for orig_col in
|
| 549 |
-
if ('description' in orig_col.lower() or 'λ΄μ©' in orig_col) and
|
| 550 |
-
b_v, c_v = row_dict[
|
| 551 |
if b_v and c_v and "<img" not in b_v and "<img" not in c_v and b_v != c_v:
|
| 552 |
-
row_dict[
|
| 553 |
result_rows.append(row_dict)
|
| 554 |
|
| 555 |
final_df = combine_code_desc(pd.DataFrame(result_rows))
|
|
@@ -563,16 +564,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 563 |
if final_df.empty:
|
| 564 |
return pd.DataFrame({"Info": ["π‘ μ ννμ 쑰건 κ°μ λ³κ²½λ λ΄μ©μ΄ μμ΅λλ€. (100% λμΌ)"]})
|
| 565 |
|
| 566 |
-
# π‘ [ν΅μ¬ λ‘μ§] νλ©΄ μΆλ ₯ μ§μ μ μ§μ λΆν μμ 꼬리νλ₯Ό κΉλνκ² λΌμ΄λ²λ¦½λλ€.
|
| 567 |
-
final_rename_map = {}
|
| 568 |
-
for col in final_df.columns:
|
| 569 |
-
if col.endswith("_INTERNAL_BASE"):
|
| 570 |
-
final_rename_map[col] = f"{col.replace('_INTERNAL_BASE', '')}_{base_ver}"
|
| 571 |
-
elif col.endswith("_INTERNAL_COMP"):
|
| 572 |
-
final_rename_map[col] = f"{col.replace('_INTERNAL_COMP', '')}_{comp_ver}"
|
| 573 |
-
|
| 574 |
-
final_df = final_df.rename(columns=final_rename_map)
|
| 575 |
-
|
| 576 |
b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]
|
| 577 |
c_cols_final = [c for c in final_df.columns if c.endswith(f"_{comp_ver}")]
|
| 578 |
|
|
@@ -583,8 +574,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 583 |
|
| 584 |
return pd.DataFrame({"Info": ["쑰건μ μ ννμΈμ."]})
|
| 585 |
except Exception as e:
|
| 586 |
-
import traceback
|
| 587 |
-
traceback.print_exc()
|
| 588 |
error_msg = str(e)
|
| 589 |
if "database is locked" in error_msg.lower():
|
| 590 |
return pd.DataFrame({"Error": ["π¨ DBκ° μ 겨μμ΅λλ€! μΌλμΌμ 'DB Browser' νλ‘κ·Έλ¨μ μμ ν μ’
λ£ν λ€ λ€μ μ‘°νν΄ μ£ΌμΈμ."]})
|
|
|
|
| 124 |
|
| 125 |
real_anchors = [c for c in df.columns if any(a.lower() == c.lower() for a in anchors)]
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
final_cols = []
|
| 128 |
for d in displays:
|
| 129 |
for c in df.columns:
|
|
|
|
| 410 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 411 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 412 |
if "Error" in df.columns: return df
|
| 413 |
+
|
| 414 |
+
# π‘ [μμ² λ°μ] λ¨μΌ μ‘°ν μ νλ©΄ νλ¨ νμ Status μ΄μ΄ λμ€μ§ μλλ‘ μ²λ¦¬ν©λλ€.
|
| 415 |
+
status_cols = [c for c in df.columns if c.lower() == 'status']
|
| 416 |
+
if status_cols:
|
| 417 |
+
df = df.drop(columns=status_cols)
|
| 418 |
+
|
| 419 |
return apply_visual_merge(df, df.columns)
|
| 420 |
|
| 421 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
|
|
|
| 438 |
s = s[:-2]
|
| 439 |
return s.replace(" ", "")
|
| 440 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
|
| 442 |
df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
|
| 443 |
|
|
|
|
| 444 |
conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
|
| 445 |
registry_query = """
|
| 446 |
SELECT Target_Table FROM Mapping_registry
|
|
|
|
| 508 |
else:
|
| 509 |
bridge = pd.DataFrame(columns=['Base_section', 'Comp_section'])
|
| 510 |
|
| 511 |
+
# π‘ [μμ²νμ λ± κ·Έ λΆλΆ μμ !]
|
| 512 |
+
# 1μμ: μ₯λΆμ μ ν λ§€ν(bridge)μ κ·Έλλ‘ μλλ€.
|
| 513 |
+
# 2μμ: μ₯λΆκ° λΉμ΄μκ³ μμͺ½ λ²κ·/μΉ΄ν
κ³ λ¦¬κ° μλ²½ν κ°μ λλ§ μμͺ½ μ‘°ν μ 체(ν©μ§ν©)λ₯Ό 1:1λ‘ λ¬Άμ΅λλ€.
|
| 514 |
+
if bridge.empty and base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper():
|
| 515 |
all_keys = list(set(df_base['merge_key']).union(set(df_comp['merge_key'])))
|
| 516 |
bridge = pd.DataFrame({'Base_section': all_keys, 'Comp_section': all_keys})
|
| 517 |
|
| 518 |
+
rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
|
| 519 |
+
df_base = df_base.rename(columns=rename_b)
|
| 520 |
+
|
| 521 |
+
rename_c = {c: f"{c}_{comp_ver}" for c in df_comp.columns if c != 'merge_key'}
|
| 522 |
+
df_comp = df_comp.rename(columns=rename_c)
|
| 523 |
|
| 524 |
df_base['base_idx'], df_comp['comp_idx'] = range(len(df_base)), range(len(df_comp))
|
| 525 |
merged = pd.merge(bridge, df_base, left_on='Base_section', right_on='merge_key', how='outer')
|
|
|
|
| 535 |
has_b = not pd.isna(row.get('base_idx')) and row.get('base_idx') != float('inf')
|
| 536 |
has_c = not pd.isna(row.get('comp_idx')) and row.get('comp_idx') != float('inf')
|
| 537 |
|
| 538 |
+
for c in rename_b.values(): row_dict[c] = str(row[c]) if has_b and not pd.isna(row[c]) else ""
|
| 539 |
+
for c in rename_c.values(): row_dict[c] = str(row[c]) if has_c and not pd.isna(row[c]) else ""
|
| 540 |
|
| 541 |
if mapped_only:
|
| 542 |
+
b_has_val = any(str(row_dict[c]).strip() not in ["", "nan", "None", " "] for c in rename_b.values())
|
| 543 |
+
c_has_val = any(str(row_dict[c]).strip() not in ["", "nan", "None", " "] for c in rename_c.values())
|
| 544 |
+
|
| 545 |
if not (b_has_val and c_has_val):
|
| 546 |
continue
|
| 547 |
|
| 548 |
if has_b and has_c:
|
| 549 |
+
for orig_col in rename_b.keys():
|
| 550 |
+
if ('description' in orig_col.lower() or 'λ΄μ©' in orig_col) and rename_c.get(orig_col) in row_dict:
|
| 551 |
+
b_v, c_v = row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]]
|
| 552 |
if b_v and c_v and "<img" not in b_v and "<img" not in c_v and b_v != c_v:
|
| 553 |
+
row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
|
| 554 |
result_rows.append(row_dict)
|
| 555 |
|
| 556 |
final_df = combine_code_desc(pd.DataFrame(result_rows))
|
|
|
|
| 564 |
if final_df.empty:
|
| 565 |
return pd.DataFrame({"Info": ["π‘ μ ννμ 쑰건 κ°μ λ³κ²½λ λ΄μ©μ΄ μμ΅λλ€. (100% λμΌ)"]})
|
| 566 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]
|
| 568 |
c_cols_final = [c for c in final_df.columns if c.endswith(f"_{comp_ver}")]
|
| 569 |
|
|
|
|
| 574 |
|
| 575 |
return pd.DataFrame({"Info": ["쑰건μ μ ννμΈμ."]})
|
| 576 |
except Exception as e:
|
|
|
|
|
|
|
| 577 |
error_msg = str(e)
|
| 578 |
if "database is locked" in error_msg.lower():
|
| 579 |
return pd.DataFrame({"Error": ["π¨ DBκ° μ 겨μμ΅λλ€! μΌλμΌμ 'DB Browser' νλ‘κ·Έλ¨μ μμ ν μ’
λ£ν λ€ λ€μ μ‘°νν΄ μ£ΌμΈμ."]})
|