QIDNLF commited on
Commit
6237bd0
ยท
verified ยท
1 Parent(s): c22cfda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -403,12 +403,14 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
403
  else: new_cols.append(col)
404
  return df[new_cols]
405
 
 
406
  if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
407
  df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
408
  if "Error" in df.columns: return df
409
- df = combine_code_desc(df)
410
  return apply_visual_merge(df, df.columns)
411
 
 
412
  if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
413
  df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, type_b)
414
  df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, type_c)
@@ -433,7 +435,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
433
 
434
  conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
435
 
436
- # 1. ์˜ˆ์ „ ์ฝ”๋“œ๋กœ ๋กค๋ฐฑ: ์ผ๋‹จ ๋งคํ•‘ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋ถ€ ๋‹ค ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. (DB ์กฐ๊ฑด ์˜ค๋ฅ˜ ์›์ฒœ ์ฐจ๋‹จ)
437
  q_fw = "SELECT * FROM Mapping_table WHERE TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Comp_std)=? AND TRIM(Comp_ver)=?"
438
  df_fw = pd.read_sql(q_fw, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
439
 
@@ -441,25 +442,21 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
441
  df_rv = pd.read_sql(q_rv, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
442
  conn_map.close()
443
 
444
- # 2. ํŒŒ์ด์ฌ(Pandas)์—์„œ Type์„ ์ •ํ™•ํ•˜๊ณ  ์•ˆ์ „ํ•˜๊ฒŒ ํ•„ํ„ฐ๋งํ•ฉ๋‹ˆ๋‹ค.
445
  cols_fw_lower = {c.lower(): c for c in df_fw.columns}
446
 
447
  if 'base_type' in cols_fw_lower and 'comp_type' in cols_fw_lower:
448
  b_col = cols_fw_lower['base_type']
449
  c_col = cols_fw_lower['comp_type']
450
 
451
- # ์ •๋ฐฉํ–ฅ ํ•„ํ„ฐ
452
  df_fw[b_col] = df_fw[b_col].fillna('Main').astype(str).str.strip().str.upper()
453
  df_fw[c_col] = df_fw[c_col].fillna('Main').astype(str).str.strip().str.upper()
454
  df_fw = df_fw[(df_fw[b_col] == type_b.strip().upper()) & (df_fw[c_col] == type_c.strip().upper())]
455
 
456
- # ์—ญ๋ฐฉํ–ฅ ํ•„ํ„ฐ (DB์˜ Comp๊ฐ€ ๋‚ด Base, DB์˜ Base๊ฐ€ ๋‚ด Comp)
457
  if not df_rv.empty:
458
  df_rv[b_col] = df_rv[b_col].fillna('Main').astype(str).str.strip().str.upper()
459
  df_rv[c_col] = df_rv[c_col].fillna('Main').astype(str).str.strip().str.upper()
460
  df_rv = df_rv[(df_rv[c_col] == type_b.strip().upper()) & (df_rv[b_col] == type_c.strip().upper())]
461
 
462
- # 3. ํ•„์š”ํ•œ ์ปฌ๋Ÿผ๋งŒ ์ถ”์ถœํ•ด์„œ ๋ณ‘ํ•ฉ
463
  b_sec = cols_fw_lower.get('base_section', 'Base_section')
464
  c_sec = cols_fw_lower.get('comp_section', 'Comp_section')
465
 
@@ -482,7 +479,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
482
  else:
483
  df_mapping = pd.DataFrame(columns=['Base_section', 'Comp_section'])
484
 
485
- # 4. ๋‹ค๋ฅธ ๋ฒ•๊ทœ/๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์ผ ๋•Œ๋Š” ๊ฐ•์ œ ์ž๋™ ๋งคํ•‘ ๊ธˆ์ง€ (์ด ์›์น™์€ ์œ ์ง€)
486
  if base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper():
487
  implicit = pd.DataFrame({'Base_section': list(set(df_base['merge_key']) & set(df_comp['merge_key'])),
488
  'Comp_section': list(set(df_base['merge_key']) & set(df_comp['merge_key']))})
@@ -490,10 +486,10 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
490
  else:
491
  bridge = df_mapping.copy()
492
 
493
- rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
494
-
495
  rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
496
  df_base = df_base.rename(columns=rename_b)
 
497
  rename_c = {c: f"{c}_{comp_ver}" for c in df_comp.columns if c != 'merge_key'}
498
  df_comp = df_comp.rename(columns=rename_c)
499
 
@@ -522,6 +518,7 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
522
  row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
523
  result_rows.append(row_dict)
524
 
 
525
  final_df = combine_code_desc(pd.DataFrame(result_rows))
526
 
527
  b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]
 
403
  else: new_cols.append(col)
404
  return df[new_cols]
405
 
406
+ # 1. ๋‹จ์ผ ์กฐํšŒ (์—ฌ๊ธฐ์— ์žˆ๋˜ combine_code_desc๋ฅผ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค!)
407
  if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
408
  df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
409
  if "Error" in df.columns: return df
410
+ # ์—ด์„ ๋ถ„๋ฆฌ๋œ ์ƒํƒœ ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•˜๊ณ , ์ค‘๋ณต ๋นˆ์นธ ์ฒ˜๋ฆฌ๋งŒ ์ˆ˜ํ–‰
411
  return apply_visual_merge(df, df.columns)
412
 
413
+ # 2. ๋น„๊ต ์กฐํšŒ
414
  if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
415
  df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, type_b)
416
  df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, type_c)
 
435
 
436
  conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
437
 
 
438
  q_fw = "SELECT * FROM Mapping_table WHERE TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Comp_std)=? AND TRIM(Comp_ver)=?"
439
  df_fw = pd.read_sql(q_fw, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
440
 
 
442
  df_rv = pd.read_sql(q_rv, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
443
  conn_map.close()
444
 
 
445
  cols_fw_lower = {c.lower(): c for c in df_fw.columns}
446
 
447
  if 'base_type' in cols_fw_lower and 'comp_type' in cols_fw_lower:
448
  b_col = cols_fw_lower['base_type']
449
  c_col = cols_fw_lower['comp_type']
450
 
 
451
  df_fw[b_col] = df_fw[b_col].fillna('Main').astype(str).str.strip().str.upper()
452
  df_fw[c_col] = df_fw[c_col].fillna('Main').astype(str).str.strip().str.upper()
453
  df_fw = df_fw[(df_fw[b_col] == type_b.strip().upper()) & (df_fw[c_col] == type_c.strip().upper())]
454
 
 
455
  if not df_rv.empty:
456
  df_rv[b_col] = df_rv[b_col].fillna('Main').astype(str).str.strip().str.upper()
457
  df_rv[c_col] = df_rv[c_col].fillna('Main').astype(str).str.strip().str.upper()
458
  df_rv = df_rv[(df_rv[c_col] == type_b.strip().upper()) & (df_rv[b_col] == type_c.strip().upper())]
459
 
 
460
  b_sec = cols_fw_lower.get('base_section', 'Base_section')
461
  c_sec = cols_fw_lower.get('comp_section', 'Comp_section')
462
 
 
479
  else:
480
  df_mapping = pd.DataFrame(columns=['Base_section', 'Comp_section'])
481
 
 
482
  if base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper():
483
  implicit = pd.DataFrame({'Base_section': list(set(df_base['merge_key']) & set(df_comp['merge_key'])),
484
  'Comp_section': list(set(df_base['merge_key']) & set(df_comp['merge_key']))})
 
486
  else:
487
  bridge = df_mapping.copy()
488
 
489
+ # (์ค‘๋ณต ์ž‘์„ฑ๋œ rename_b ์‚ญ์ œ ์™„๋ฃŒ)
 
490
  rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
491
  df_base = df_base.rename(columns=rename_b)
492
+
493
  rename_c = {c: f"{c}_{comp_ver}" for c in df_comp.columns if c != 'merge_key'}
494
  df_comp = df_comp.rename(columns=rename_c)
495
 
 
518
  row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
519
  result_rows.append(row_dict)
520
 
521
+ # ๋น„๊ต ์กฐํšŒ ์‹œ์—๋Š” ๋ฒˆํ˜ธ์™€ ์„ค๋ช…์„ ํ•ฉ์นฉ๋‹ˆ๋‹ค
522
  final_df = combine_code_desc(pd.DataFrame(result_rows))
523
 
524
  b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]