Update app.py
Browse files
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 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
merged[
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
merged = merged[[
|
| 393 |
-
"Section",
|
| 394 |
-
base_col,
|
| 395 |
-
comp_col
|
| 396 |
-
]]
|
| 397 |
|
| 398 |
-
return
|
| 399 |
|
| 400 |
-
|
|
|
|
|
|
|
| 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
|