QIDNLF commited on
Commit
bfd3483
ยท
verified ยท
1 Parent(s): ce119e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -5
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
- # [ํ•ด๊ฒฐ 1] Diff ์ ์šฉ: ์›๋ณธ ์ปฌ๋Ÿผ๋ช…์— 'description'์ด ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฉด ๋ชจ๋‘ ์ ์šฉ!
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
- final_df = apply_visual_merge(final_df, b_cols_renamed)
436
- final_df = apply_visual_merge(final_df, c_cols_renamed)
 
 
 
 
 
 
 
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