QIDNLF commited on
Commit
a37dc2c
Β·
verified Β·
1 Parent(s): f36eeb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -66
app.py CHANGED
@@ -330,74 +330,71 @@ def apply_diff_row(row, base_col, comp_col):
330
 
331
 
332
  def unified_search(bs, bv, bc, cs, cv, cc):
333
- if bs and bv and bc and not (cs and cv and cc):
334
- df = display_data(bs, bv, bc)
335
- return df.rename(columns={"section": "Section", "description": "Description"})
336
-
337
- if bs and bv and bc and cs and cv and cc:
338
- df_base = display_data(bs, bv, bc)
339
- df_comp = display_data(cs, cv, cc)
340
-
341
- if 'section' not in df_base.columns or 'section' not in df_comp.columns:
342
- return pd.DataFrame({"Error": ["section μ—†μŒ"]})
343
-
344
- df_base = df_base.rename(columns={
345
- "section": f"Section_{bv}",
346
- "description": f"Description_{bv}"
347
- })
348
-
349
- df_comp = df_comp.rename(columns={
350
- "section": f"Section_{cv}",
351
- "description": f"Description_{cv}"
352
- })
353
-
354
- base_sec = f"Section_{bv}"
355
- comp_sec = f"Section_{cv}"
356
- base_col = f"Description_{bv}"
357
- comp_col = f"Description_{cv}"
358
-
359
- merged = pd.merge(
360
- df_base,
361
- df_comp,
362
- left_on=base_sec,
363
- right_on=comp_sec,
364
- how="outer"
365
- )
366
-
367
- # NaN β†’ ""
368
- merged = merged.fillna("")
369
-
370
- # πŸ”₯ section μ •κ·œν™”
371
- merged[base_sec] = merged[base_sec].astype(str).str.strip()
372
- merged[comp_sec] = merged[comp_sec].astype(str).str.strip()
373
-
374
- # πŸ”₯ diff 적용
375
- merged[[base_col, comp_col]] = merged.apply(
376
- lambda row: apply_diff_row(row, base_col, comp_col),
377
- axis=1
378
- )
379
-
380
- # πŸ”₯ Section 톡합 (핡심)
381
- merged["Section"] = merged[base_sec].where(
382
- merged[base_sec] != "", merged[comp_sec]
383
- )
384
-
385
- # πŸ”₯ μ •λ ¬ 기쀀도 ν†΅ν•©λœ section κΈ°μ€€
386
- merged = merged.sort_values(
387
- by="Section",
388
- key=lambda col: col.map(natural_sort_key)
389
- )
390
-
391
- # πŸ”₯ μ΅œμ’… 컬럼 ꡬ성
392
- merged = merged[[
393
- "Section",
394
- base_col,
395
- comp_col
396
- ]]
397
 
398
- return merged
399
 
400
- return pd.DataFrame({"Info": ["선택 ν•„μš”"]})
 
 
401
 
402
  # --------------------------
403
  # UI
 
330
 
331
 
332
  def unified_search(bs, bv, bc, cs, cv, cc):
333
+ try:
334
+ if bs and bv and bc and not (cs and cv and cc):
335
+ df = display_data(bs, bv, bc)
336
+ return df.rename(columns={"section": "Section", "description": "Description"})
337
+
338
+ if bs and bv and bc and cs and cv and cc:
339
+ df_base = display_data(bs, bv, bc)
340
+ df_comp = display_data(cs, cv, cc)
341
+
342
+ print("=== BASE ===")
343
+ print(df_base.head())
344
+ print("=== COMP ===")
345
+ print(df_comp.head())
346
+
347
+ if 'section' not in df_base.columns or 'section' not in df_comp.columns:
348
+ return pd.DataFrame({"Error": ["section μ—†μŒ"]})
349
+
350
+ df_base = df_base.rename(columns={
351
+ "section": f"Section_{bv}",
352
+ "description": f"Description_{bv}"
353
+ })
354
+
355
+ df_comp = df_comp.rename(columns={
356
+ "section": f"Section_{cv}",
357
+ "description": f"Description_{cv}"
358
+ })
359
+
360
+ base_sec = f"Section_{bv}"
361
+ comp_sec = f"Section_{cv}"
362
+ base_col = f"Description_{bv}"
363
+ comp_col = f"Description_{cv}"
364
+
365
+ merged = pd.merge(
366
+ df_base,
367
+ df_comp,
368
+ left_on=base_sec,
369
+ right_on=comp_sec,
370
+ how="outer"
371
+ ).fillna("")
372
+
373
+ # πŸ”₯ μ—¬κΈ°μ„œ μ—λŸ¬ 많이 남
374
+ merged[base_sec] = merged[base_sec].astype(str)
375
+ merged[comp_sec] = merged[comp_sec].astype(str)
376
+
377
+ merged[[base_col, comp_col]] = merged.apply(
378
+ lambda row: apply_diff_row(row, base_col, comp_col),
379
+ axis=1
380
+ )
381
+
382
+ merged["Section"] = merged[base_sec].where(
383
+ merged[base_sec] != "", merged[comp_sec]
384
+ )
385
+
386
+ merged = merged.sort_values(
387
+ by="Section",
388
+ key=lambda col: col.map(natural_sort_key)
389
+ )
390
+
391
+ return merged[["Section", base_col, comp_col]]
 
 
 
 
 
392
 
393
+ return pd.DataFrame({"Info": ["선택 ν•„μš”"]})
394
 
395
+ except Exception as e:
396
+ traceback.print_exc()
397
+ return pd.DataFrame({"Error": [str(e)]})
398
 
399
  # --------------------------
400
  # UI