QIDNLF commited on
Commit
b4cc81b
·
verified ·
1 Parent(s): 69e74f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -423,11 +423,10 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
423
  if ra not in df_comp.columns:
424
  return pd.DataFrame({"Error": [f"비교 열(Anchor) '{ra}'이(가) 비교 데이터에 존재하지 않습니다. Table_Config를 확인하세요."]})
425
 
426
- df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join(row.values.astype(str)), axis=1).str.replace(" ", "")
427
- df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join(row.values.astype(str)), axis=1).str.replace(" ", "")
428
 
429
  conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
430
-
431
  map_cols = pd.read_sql("PRAGMA table_info(Mapping_table)", conn_map)['name'].tolist()
432
 
433
  if 'Base_Type' in map_cols and 'Comp_Type' in map_cols:
@@ -437,12 +436,10 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
437
  q_rv = "SELECT Comp_section AS Base_section, Base_section AS Comp_section FROM Mapping_table WHERE TRIM(Comp_std)=? AND TRIM(Comp_ver)=? AND TRIM(Comp_Type)=? AND TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Base_Type)=?"
438
  df_rv = pd.read_sql(q_rv, conn_map, params=[base_std.strip(), base_ver.strip(), type_b, comp_std.strip(), comp_ver.strip(), type_c])
439
  else:
440
-
441
  q = "SELECT Base_section, Comp_section FROM Mapping_table WHERE TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Comp_std)=? AND TRIM(Comp_ver)=?"
442
  df_fw = pd.read_sql(q, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
443
  q_rv = "SELECT Comp_section AS Base_section, Base_section AS Comp_section FROM Mapping_table WHERE TRIM(Comp_std)=? AND TRIM(Comp_ver)=? AND TRIM(Base_std)=? AND TRIM(Base_ver)=?"
444
  df_rv = pd.read_sql(q_rv, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
445
-
446
  conn_map.close()
447
 
448
  df_mapping = pd.concat([df_fw, df_rv], ignore_index=True)
@@ -450,7 +447,7 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
450
  df_mapping['Base_section'] = df_mapping['Base_section'].astype(str).str.replace('\n', ',').str.split(',')
451
  df_mapping['Comp_section'] = df_mapping['Comp_section'].astype(str).str.replace('\n', ',').str.split(',')
452
  df_mapping = df_mapping.explode('Base_section').explode('Comp_section')
453
- df_mapping[['Base_section', 'Comp_section']] = df_mapping[['Base_section', 'Comp_section']].apply(lambda x: x.str.strip().str.replace(" ", ""))
454
  df_mapping = df_mapping.dropna().drop_duplicates()
455
  else:
456
  df_mapping = pd.DataFrame(columns=['Base_section', 'Comp_section'])
@@ -460,7 +457,9 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
460
  'Comp_section': list(set(df_base['merge_key']) & set(df_comp['merge_key']))})
461
  bridge = pd.concat([df_mapping, implicit], ignore_index=True).drop_duplicates()
462
  else:
463
- bridge = df_mapping.copy()
 
 
464
 
465
  rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
466
  df_base = df_base.rename(columns=rename_b)
 
423
  if ra not in df_comp.columns:
424
  return pd.DataFrame({"Error": [f"비교 열(Anchor) '{ra}'이(가) 비교 데이터에 존재하지 않습니다. Table_Config를 확인하세요."]})
425
 
426
+ df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join(row.values.astype(str)), axis=1).astype(str).str.replace(" ", "")
427
+ df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join(row.values.astype(str)), axis=1).astype(str).str.replace(" ", "")
428
 
429
  conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
 
430
  map_cols = pd.read_sql("PRAGMA table_info(Mapping_table)", conn_map)['name'].tolist()
431
 
432
  if 'Base_Type' in map_cols and 'Comp_Type' in map_cols:
 
436
  q_rv = "SELECT Comp_section AS Base_section, Base_section AS Comp_section FROM Mapping_table WHERE TRIM(Comp_std)=? AND TRIM(Comp_ver)=? AND TRIM(Comp_Type)=? AND TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Base_Type)=?"
437
  df_rv = pd.read_sql(q_rv, conn_map, params=[base_std.strip(), base_ver.strip(), type_b, comp_std.strip(), comp_ver.strip(), type_c])
438
  else:
 
439
  q = "SELECT Base_section, Comp_section FROM Mapping_table WHERE TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Comp_std)=? AND TRIM(Comp_ver)=?"
440
  df_fw = pd.read_sql(q, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
441
  q_rv = "SELECT Comp_section AS Base_section, Base_section AS Comp_section FROM Mapping_table WHERE TRIM(Comp_std)=? AND TRIM(Comp_ver)=? AND TRIM(Base_std)=? AND TRIM(Base_ver)=?"
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
  df_mapping = pd.concat([df_fw, df_rv], ignore_index=True)
 
447
  df_mapping['Base_section'] = df_mapping['Base_section'].astype(str).str.replace('\n', ',').str.split(',')
448
  df_mapping['Comp_section'] = df_mapping['Comp_section'].astype(str).str.replace('\n', ',').str.split(',')
449
  df_mapping = df_mapping.explode('Base_section').explode('Comp_section')
450
+ df_mapping[['Base_section', 'Comp_section']] = df_mapping[['Base_section', 'Comp_section']].astype(str).apply(lambda x: x.str.strip().str.replace(" ", ""))
451
  df_mapping = df_mapping.dropna().drop_duplicates()
452
  else:
453
  df_mapping = pd.DataFrame(columns=['Base_section', 'Comp_section'])
 
457
  'Comp_section': list(set(df_base['merge_key']) & set(df_comp['merge_key']))})
458
  bridge = pd.concat([df_mapping, implicit], ignore_index=True).drop_duplicates()
459
  else:
460
+ bridge = df_mapping.copy()
461
+
462
+ rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
463
 
464
  rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
465
  df_base = df_base.rename(columns=rename_b)