Update app.py
Browse files
app.py
CHANGED
|
@@ -319,6 +319,7 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 319 |
is_main = base_cat == "ALL" or (base_cat and base_cat[0].isdigit() and "." in base_cat)
|
| 320 |
table_type = "Main" if is_main else base_cat
|
| 321 |
|
|
|
|
| 322 |
def apply_visual_merge(df, cols):
|
| 323 |
if not df.empty and len(cols) > 1:
|
| 324 |
is_dup = pd.Series([True] * len(df), index=df.index)
|
|
@@ -330,13 +331,58 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 330 |
df.loc[is_dup, col] = ""
|
| 331 |
return df
|
| 332 |
|
| 333 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 335 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, table_type)
|
| 336 |
if "Error" in df.columns or "Info" in df.columns: return df
|
|
|
|
|
|
|
| 337 |
return apply_visual_merge(df, df.columns)
|
| 338 |
|
| 339 |
-
#
|
|
|
|
|
|
|
| 340 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
| 341 |
df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, table_type)
|
| 342 |
df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, table_type)
|
|
@@ -416,7 +462,7 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 416 |
for c in c_cols_renamed:
|
| 417 |
row_dict[c] = str(row.get(c)) if has_c and not pd.isna(row.get(c)) else ""
|
| 418 |
|
| 419 |
-
#
|
| 420 |
if has_b and has_c:
|
| 421 |
for orig_col in rename_b.keys():
|
| 422 |
if 'description' in orig_col.lower():
|
|
@@ -432,8 +478,15 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 432 |
|
| 433 |
final_df = pd.DataFrame(result_rows)
|
| 434 |
|
| 435 |
-
|
| 436 |
-
final_df =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
|
| 438 |
return final_df
|
| 439 |
|
|
|
|
| 319 |
is_main = base_cat == "ALL" or (base_cat and base_cat[0].isdigit() and "." in base_cat)
|
| 320 |
table_type = "Main" if is_main else base_cat
|
| 321 |
|
| 322 |
+
# ์๊ฐ์ ์ค๋ณต ์ ๊ฑฐ (ํญํฌ์ ๋ฐฉ์)
|
| 323 |
def apply_visual_merge(df, cols):
|
| 324 |
if not df.empty and len(cols) > 1:
|
| 325 |
is_dup = pd.Series([True] * len(df), index=df.index)
|
|
|
|
| 331 |
df.loc[is_dup, col] = ""
|
| 332 |
return df
|
| 333 |
|
| 334 |
+
# [ํต์ฌ ์ถ๊ฐ] Code์ Description ์ปฌ๋ผ์ ์๊ฐ์ ์ผ๋ก ์์๋ ๋ณํฉ
|
| 335 |
+
def combine_code_desc(df):
|
| 336 |
+
cols = list(df.columns)
|
| 337 |
+
new_cols = []
|
| 338 |
+
processed = set()
|
| 339 |
+
|
| 340 |
+
for col in cols:
|
| 341 |
+
if col in processed: continue
|
| 342 |
+
|
| 343 |
+
# _Code ์ _Description ์ง๊ฟ ์ฐพ๊ธฐ
|
| 344 |
+
if "_Code" in col:
|
| 345 |
+
desc_col = col.replace("_Code", "_Description")
|
| 346 |
+
if desc_col in cols:
|
| 347 |
+
new_col_name = col.replace("_Code", "")
|
| 348 |
+
|
| 349 |
+
def combine_cells(row):
|
| 350 |
+
c = str(row[col]).strip()
|
| 351 |
+
d = str(row[desc_col]).strip()
|
| 352 |
+
if c in ["nan", "None", ""]: return d
|
| 353 |
+
if d in ["nan", "None", ""]: return f"<span style='font-weight:bold; color:#1a73e8;'>{c}</span>"
|
| 354 |
+
|
| 355 |
+
# Code๋ ํ๋์ ๋ณผ๋์ฒด๋ก, Description์ ๋ฐ๋ก ์๋ซ์ค์ ์ถ๋ ฅ
|
| 356 |
+
return f"<span style='font-weight:bold; color:#1a73e8; display:block; margin-bottom:4px;'>{c}</span>{d}"
|
| 357 |
+
|
| 358 |
+
df[new_col_name] = df.apply(combine_cells, axis=1)
|
| 359 |
+
new_cols.append(new_col_name)
|
| 360 |
+
processed.add(col)
|
| 361 |
+
processed.add(desc_col)
|
| 362 |
+
else:
|
| 363 |
+
new_cols.append(col)
|
| 364 |
+
elif "_Description" in col:
|
| 365 |
+
code_col = col.replace("_Description", "_Code")
|
| 366 |
+
if code_col not in cols:
|
| 367 |
+
new_cols.append(col)
|
| 368 |
+
else:
|
| 369 |
+
new_cols.append(col)
|
| 370 |
+
|
| 371 |
+
return df[new_cols]
|
| 372 |
+
|
| 373 |
+
# ----------------------------------------
|
| 374 |
+
# 1. ๋จ์ผ ์กฐํ
|
| 375 |
+
# ----------------------------------------
|
| 376 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 377 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, table_type)
|
| 378 |
if "Error" in df.columns or "Info" in df.columns: return df
|
| 379 |
+
|
| 380 |
+
df = combine_code_desc(df) # ๊ฒฐํฉ ์ ์ฉ
|
| 381 |
return apply_visual_merge(df, df.columns)
|
| 382 |
|
| 383 |
+
# ----------------------------------------
|
| 384 |
+
# 2. ๋น๊ต ์กฐํ
|
| 385 |
+
# ----------------------------------------
|
| 386 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
| 387 |
df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, table_type)
|
| 388 |
df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, table_type)
|
|
|
|
| 462 |
for c in c_cols_renamed:
|
| 463 |
row_dict[c] = str(row.get(c)) if has_c and not pd.isna(row.get(c)) else ""
|
| 464 |
|
| 465 |
+
# Diff ์ฒ๋ฆฌ (Description ์ง๊ฟ ์ฐพ์์ ํ์ด๋ผ์ดํ
)
|
| 466 |
if has_b and has_c:
|
| 467 |
for orig_col in rename_b.keys():
|
| 468 |
if 'description' in orig_col.lower():
|
|
|
|
| 478 |
|
| 479 |
final_df = pd.DataFrame(result_rows)
|
| 480 |
|
| 481 |
+
# [ํต์ฌ] Diff ์ฒ๋ฆฌ๋ ๋ฐ์ดํฐํ๋ ์์ Code์ Desc๋ฅผ ํ ์ด๋ก ๋ณํฉ!
|
| 482 |
+
final_df = combine_code_desc(final_df)
|
| 483 |
+
|
| 484 |
+
# ๋ณ๊ฒฝ๋ ์ปฌ๋ผ๋ช
๊ธฐ์ค์ผ๋ก ์ข/์ฐ ์๊ฐ์ ๋ณํฉ(Cascading Blanking) ๋ฐ๋ก ์ ์ฉ
|
| 485 |
+
b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]
|
| 486 |
+
c_cols_final = [c for c in final_df.columns if c.endswith(f"_{comp_ver}")]
|
| 487 |
+
|
| 488 |
+
final_df = apply_visual_merge(final_df, b_cols_final)
|
| 489 |
+
final_df = apply_visual_merge(final_df, c_cols_final)
|
| 490 |
|
| 491 |
return final_df
|
| 492 |
|