QIDNLF commited on
Commit
32fae78
·
verified ·
1 Parent(s): b4cc81b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -423,18 +423,27 @@ 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).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:
433
- q = "SELECT Base_section, Comp_section FROM Mapping_table WHERE TRIM(Base_std)=? AND TRIM(Base_ver)=? AND TRIM(Base_Type)=? AND TRIM(Comp_std)=? AND TRIM(Comp_ver)=? AND TRIM(Comp_Type)=?"
434
- df_fw = pd.read_sql(q, conn_map, params=[base_std.strip(), base_ver.strip(), type_b, comp_std.strip(), comp_ver.strip(), type_c])
 
 
 
435
 
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()])
@@ -447,7 +456,9 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
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'])
 
423
  if ra not in df_comp.columns:
424
  return pd.DataFrame({"Error": [f"비교 열(Anchor) '{ra}'이(가) 비교 데이터에 존재하지 않습니다. Table_Config를 확인하세요."]})
425
 
426
+ def clean_key_val(v):
427
+ s = str(v).strip()
428
+ if s.endswith('.0'): s = s[:-2]
429
+ return s.replace(" ", "")
430
+
431
+ df_base['merge_key'] = df_base[real_anchors_b].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
432
+ df_comp['merge_key'] = df_comp[real_anchors_c].apply(lambda row: '-'.join([clean_key_val(x) for x in row]), axis=1)
433
 
434
  conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
435
  map_cols = pd.read_sql("PRAGMA table_info(Mapping_table)", conn_map)['name'].tolist()
436
+ map_cols_lower = [c.lower() for c in map_cols]
437
 
438
+ if 'base_type' in map_cols_lower and 'comp_type' in map_cols_lower:
439
+ b_col = map_cols[map_cols_lower.index('base_type')]
440
+ c_col = map_cols[map_cols_lower.index('comp_type')]
441
+
442
+ q = f"SELECT Base_section, Comp_section FROM Mapping_table WHERE TRIM(Base_std)=? AND TRIM(Base_ver)=? AND UPPER(TRIM(IFNULL([{b_col}], 'Main')))=UPPER(?) AND TRIM(Comp_std)=? AND TRIM(Comp_ver)=? AND UPPER(TRIM(IFNULL([{c_col}], 'Main')))=UPPER(?)"
443
+ df_fw = pd.read_sql(q, conn_map, params=[base_std.strip(), base_ver.strip(), type_b.strip(), comp_std.strip(), comp_ver.strip(), type_c.strip()])
444
 
445
+ q_rv = f"SELECT Comp_section AS Base_section, Base_section AS Comp_section FROM Mapping_table WHERE TRIM(Comp_std)=? AND TRIM(Comp_ver)=? AND UPPER(TRIM(IFNULL([{c_col}], 'Main')))=UPPER(?) AND TRIM(Base_std)=? AND TRIM(Base_ver)=? AND UPPER(TRIM(IFNULL([{b_col}], 'Main')))=UPPER(?)"
446
+ df_rv = pd.read_sql(q_rv, conn_map, params=[base_std.strip(), base_ver.strip(), type_b.strip(), comp_std.strip(), comp_ver.strip(), type_c.strip()])
447
  else:
448
  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)=?"
449
  df_fw = pd.read_sql(q, conn_map, params=[base_std.strip(), base_ver.strip(), comp_std.strip(), comp_ver.strip()])
 
456
  df_mapping['Base_section'] = df_mapping['Base_section'].astype(str).str.replace('\n', ',').str.split(',')
457
  df_mapping['Comp_section'] = df_mapping['Comp_section'].astype(str).str.replace('\n', ',').str.split(',')
458
  df_mapping = df_mapping.explode('Base_section').explode('Comp_section')
459
+
460
+ df_mapping['Base_section'] = df_mapping['Base_section'].apply(clean_key_val)
461
+ df_mapping['Comp_section'] = df_mapping['Comp_section'].apply(clean_key_val)
462
  df_mapping = df_mapping.dropna().drop_duplicates()
463
  else:
464
  df_mapping = pd.DataFrame(columns=['Base_section', 'Comp_section'])