QIDNLF commited on
Commit
4d27c35
Β·
verified Β·
1 Parent(s): 8571ae0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -35
app.py CHANGED
@@ -124,11 +124,6 @@ def fetch_database_records(std, ver, cat, table_type):
124
 
125
  real_anchors = [c for c in df.columns if any(a.lower() == c.lower() for a in anchors)]
126
 
127
- # πŸ’‘ [핡심 둜직] Status 열은 UI 상단에 ν‘œκΈ°λ˜λ―€λ‘œ, μ•„λž˜ ν‘œμ—μ„œλŠ” κΉ”λ”ν•˜κ²Œ μ‚­μ œν•©λ‹ˆλ‹€!
128
- status_cols = [c for c in df.columns if c.lower() == 'status']
129
- if status_cols:
130
- df = df.drop(columns=status_cols)
131
-
132
  final_cols = []
133
  for d in displays:
134
  for c in df.columns:
@@ -415,6 +410,12 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
415
  if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
416
  df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
417
  if "Error" in df.columns: return df
 
 
 
 
 
 
418
  return apply_visual_merge(df, df.columns)
419
 
420
  if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
@@ -437,14 +438,9 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
437
  s = s[:-2]
438
  return s.replace(" ", "")
439
 
440
- # πŸ’‘ [핡심 둜직] λ‚΄λΆ€ 처리용 μž„μ‹œ κΌ¬λ¦¬ν‘œλ₯Ό 달아 KeyErrorλ₯Ό μ›μ²œ μ°¨λ‹¨ν•©λ‹ˆλ‹€!
441
- internal_rename_b = {c: f"{c}_INTERNAL_BASE" for c in df_base.columns if c != 'merge_key'}
442
- internal_rename_c = {c: f"{c}_INTERNAL_COMP" for c in df_comp.columns if c != 'merge_key'}
443
-
444
  df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
445
  df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
446
 
447
- # πŸ’‘ [핡심 둜직] λ§€ν•‘ μž₯λΆ€(Mapping_registry)λ₯Ό 무쑰건 μ΅œμš°μ„ μœΌλ‘œ κ²€μ‚¬ν•©λ‹ˆλ‹€.
448
  conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
449
  registry_query = """
450
  SELECT Target_Table FROM Mapping_registry
@@ -512,14 +508,18 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
512
  else:
513
  bridge = pd.DataFrame(columns=['Base_section', 'Comp_section'])
514
 
515
- # πŸ’‘ [핡심 둜직] λ§€ν•‘ μž₯λΆ€κ°€ μ™„λ²½ν•˜κ²Œ λΉ„μ–΄μžˆμ„ λ•Œλ§Œ(즉, 아무것도 μ•ˆ 썼을 λ•Œλ§Œ) μ΅œν›„μ˜ μˆ˜λ‹¨μœΌλ‘œ 1:1 병합
516
- is_same_std = (base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper())
517
- if bridge.empty and is_same_std:
 
518
  all_keys = list(set(df_base['merge_key']).union(set(df_comp['merge_key'])))
519
  bridge = pd.DataFrame({'Base_section': all_keys, 'Comp_section': all_keys})
520
 
521
- df_base = df_base.rename(columns=internal_rename_b)
522
- df_comp = df_comp.rename(columns=internal_rename_c)
 
 
 
523
 
524
  df_base['base_idx'], df_comp['comp_idx'] = range(len(df_base)), range(len(df_comp))
525
  merged = pd.merge(bridge, df_base, left_on='Base_section', right_on='merge_key', how='outer')
@@ -535,21 +535,22 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
535
  has_b = not pd.isna(row.get('base_idx')) and row.get('base_idx') != float('inf')
536
  has_c = not pd.isna(row.get('comp_idx')) and row.get('comp_idx') != float('inf')
537
 
538
- for c in internal_rename_b.values(): row_dict[c] = str(row[c]) if has_b and not pd.isna(row[c]) else ""
539
- for c in internal_rename_c.values(): row_dict[c] = str(row[c]) if has_c and not pd.isna(row[c]) else ""
540
 
541
  if mapped_only:
542
- b_has_val = any(str(row_dict[c]).strip() not in ["", "nan", "None", " "] for c in internal_rename_b.values())
543
- c_has_val = any(str(row_dict[c]).strip() not in ["", "nan", "None", " "] for c in internal_rename_c.values())
 
544
  if not (b_has_val and c_has_val):
545
  continue
546
 
547
  if has_b and has_c:
548
- for orig_col in internal_rename_b.keys():
549
- if ('description' in orig_col.lower() or 'λ‚΄μš©' in orig_col) and internal_rename_c.get(orig_col) in row_dict:
550
- b_v, c_v = row_dict[internal_rename_b[orig_col]], row_dict[internal_rename_c[orig_col]]
551
  if b_v and c_v and "<img" not in b_v and "<img" not in c_v and b_v != c_v:
552
- row_dict[internal_rename_b[orig_col]], row_dict[internal_rename_c[orig_col]] = generate_html_diff(b_v, c_v)
553
  result_rows.append(row_dict)
554
 
555
  final_df = combine_code_desc(pd.DataFrame(result_rows))
@@ -563,16 +564,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
563
  if final_df.empty:
564
  return pd.DataFrame({"Info": ["πŸ’‘ μ„ νƒν•˜μ‹  쑰건 간에 λ³€κ²½λœ λ‚΄μš©μ΄ μ—†μŠ΅λ‹ˆλ‹€. (100% 동일)"]})
565
 
566
- # πŸ’‘ [핡심 둜직] ν™”λ©΄ 좜λ ₯ 직전에 μ§€μ €λΆ„ν•œ μž„μ‹œ κΌ¬λ¦¬ν‘œλ₯Ό κΉ”λ”ν•˜κ²Œ λ–Όμ–΄λ²„λ¦½λ‹ˆλ‹€.
567
- final_rename_map = {}
568
- for col in final_df.columns:
569
- if col.endswith("_INTERNAL_BASE"):
570
- final_rename_map[col] = f"{col.replace('_INTERNAL_BASE', '')}_{base_ver}"
571
- elif col.endswith("_INTERNAL_COMP"):
572
- final_rename_map[col] = f"{col.replace('_INTERNAL_COMP', '')}_{comp_ver}"
573
-
574
- final_df = final_df.rename(columns=final_rename_map)
575
-
576
  b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]
577
  c_cols_final = [c for c in final_df.columns if c.endswith(f"_{comp_ver}")]
578
 
@@ -583,8 +574,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
583
 
584
  return pd.DataFrame({"Info": ["쑰건을 μ„ νƒν•˜μ„Έμš”."]})
585
  except Exception as e:
586
- import traceback
587
- traceback.print_exc()
588
  error_msg = str(e)
589
  if "database is locked" in error_msg.lower():
590
  return pd.DataFrame({"Error": ["🚨 DBκ°€ μž κ²¨μžˆμŠ΅λ‹ˆλ‹€! μΌœλ†“μœΌμ‹  'DB Browser' ν”„λ‘œκ·Έλž¨μ„ μ™„μ „νžˆ μ’…λ£Œν•œ λ’€ λ‹€μ‹œ μ‘°νšŒν•΄ μ£Όμ„Έμš”."]})
 
124
 
125
  real_anchors = [c for c in df.columns if any(a.lower() == c.lower() for a in anchors)]
126
 
 
 
 
 
 
127
  final_cols = []
128
  for d in displays:
129
  for c in df.columns:
 
410
  if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
411
  df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
412
  if "Error" in df.columns: return df
413
+
414
+ # πŸ’‘ [μš”μ²­ 반영] 단일 쑰회 μ‹œ ν™”λ©΄ ν•˜λ‹¨ ν‘œμ— Status 열이 λ‚˜μ˜€μ§€ μ•Šλ„λ‘ μ²˜λ¦¬ν•©λ‹ˆλ‹€.
415
+ status_cols = [c for c in df.columns if c.lower() == 'status']
416
+ if status_cols:
417
+ df = df.drop(columns=status_cols)
418
+
419
  return apply_visual_merge(df, df.columns)
420
 
421
  if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
 
438
  s = s[:-2]
439
  return s.replace(" ", "")
440
 
 
 
 
 
441
  df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
442
  df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
443
 
 
444
  conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
445
  registry_query = """
446
  SELECT Target_Table FROM Mapping_registry
 
508
  else:
509
  bridge = pd.DataFrame(columns=['Base_section', 'Comp_section'])
510
 
511
+ # πŸ’‘ [μš”μ²­ν•˜μ‹  λ”± κ·Έ λΆ€λΆ„ μˆ˜μ •!]
512
+ # 1μˆœμœ„: μž₯뢀에 적힌 λ§€ν•‘(bridge)을 κ·ΈλŒ€λ‘œ μ”λ‹ˆλ‹€.
513
+ # 2μˆœμœ„: μž₯λΆ€κ°€ λΉ„μ–΄μžˆκ³  μ–‘μͺ½ λ²•κ·œ/μΉ΄ν…Œκ³ λ¦¬κ°€ μ™„λ²½νžˆ 같을 λ•Œλ§Œ μ–‘μͺ½ μ‘°ν•­ 전체(ν•©μ§‘ν•©)λ₯Ό 1:1둜 λ¬ΆμŠ΅λ‹ˆλ‹€.
514
+ if bridge.empty and base_std.strip().upper() == comp_std.strip().upper() and type_b.strip().upper() == type_c.strip().upper():
515
  all_keys = list(set(df_base['merge_key']).union(set(df_comp['merge_key'])))
516
  bridge = pd.DataFrame({'Base_section': all_keys, 'Comp_section': all_keys})
517
 
518
+ rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
519
+ df_base = df_base.rename(columns=rename_b)
520
+
521
+ rename_c = {c: f"{c}_{comp_ver}" for c in df_comp.columns if c != 'merge_key'}
522
+ df_comp = df_comp.rename(columns=rename_c)
523
 
524
  df_base['base_idx'], df_comp['comp_idx'] = range(len(df_base)), range(len(df_comp))
525
  merged = pd.merge(bridge, df_base, left_on='Base_section', right_on='merge_key', how='outer')
 
535
  has_b = not pd.isna(row.get('base_idx')) and row.get('base_idx') != float('inf')
536
  has_c = not pd.isna(row.get('comp_idx')) and row.get('comp_idx') != float('inf')
537
 
538
+ for c in rename_b.values(): row_dict[c] = str(row[c]) if has_b and not pd.isna(row[c]) else ""
539
+ for c in rename_c.values(): row_dict[c] = str(row[c]) if has_c and not pd.isna(row[c]) else ""
540
 
541
  if mapped_only:
542
+ b_has_val = any(str(row_dict[c]).strip() not in ["", "nan", "None", "&nbsp;"] for c in rename_b.values())
543
+ c_has_val = any(str(row_dict[c]).strip() not in ["", "nan", "None", "&nbsp;"] for c in rename_c.values())
544
+
545
  if not (b_has_val and c_has_val):
546
  continue
547
 
548
  if has_b and has_c:
549
+ for orig_col in rename_b.keys():
550
+ if ('description' in orig_col.lower() or 'λ‚΄μš©' in orig_col) and rename_c.get(orig_col) in row_dict:
551
+ b_v, c_v = row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]]
552
  if b_v and c_v and "<img" not in b_v and "<img" not in c_v and b_v != c_v:
553
+ row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
554
  result_rows.append(row_dict)
555
 
556
  final_df = combine_code_desc(pd.DataFrame(result_rows))
 
564
  if final_df.empty:
565
  return pd.DataFrame({"Info": ["πŸ’‘ μ„ νƒν•˜μ‹  쑰건 간에 λ³€κ²½λœ λ‚΄μš©μ΄ μ—†μŠ΅λ‹ˆλ‹€. (100% 동일)"]})
566
 
 
 
 
 
 
 
 
 
 
 
567
  b_cols_final = [c for c in final_df.columns if c.endswith(f"_{base_ver}")]
568
  c_cols_final = [c for c in final_df.columns if c.endswith(f"_{comp_ver}")]
569
 
 
574
 
575
  return pd.DataFrame({"Info": ["쑰건을 μ„ νƒν•˜μ„Έμš”."]})
576
  except Exception as e:
 
 
577
  error_msg = str(e)
578
  if "database is locked" in error_msg.lower():
579
  return pd.DataFrame({"Error": ["🚨 DBκ°€ μž κ²¨μžˆμŠ΅λ‹ˆλ‹€! μΌœλ†“μœΌμ‹  'DB Browser' ν”„λ‘œκ·Έλž¨μ„ μ™„μ „νžˆ μ’…λ£Œν•œ λ’€ λ‹€μ‹œ μ‘°νšŒν•΄ μ£Όμ„Έμš”."]})