QIDNLF commited on
Commit
93269d0
Β·
verified Β·
1 Parent(s): 8c534a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -22
app.py CHANGED
@@ -252,19 +252,6 @@ def generate_html_diff(base_text, comp_text):
252
 
253
  return " ".join(b_result), " ".join(c_result)
254
 
255
- def get_table_config(table_type):
256
- try:
257
- conn = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
258
- query = "SELECT Anchor_Column, Display_Columns FROM Table_Config WHERE Table_Type=?"
259
- df = pd.read_sql(query, conn, params=[table_type])
260
- conn.close()
261
-
262
- if not df.empty:
263
- return df.iloc[0]['Anchor_Column'], df.iloc[0]['Display_Columns']
264
- except Exception:
265
- pass
266
- return "Section", "Description"
267
-
268
  def fetch_database_records(standard, version, selection, table_type):
269
  if not all([standard, version, selection]):
270
  return pd.DataFrame({"Info": ["선택 ν•„μš”"]}), []
@@ -277,11 +264,7 @@ def fetch_database_records(standard, version, selection, table_type):
277
  conn = sqlite3.connect(db_path)
278
  conn.text_factory = decode_sqlite_text
279
 
280
- anchor_col_config, display_setting = get_table_config(table_type)
281
- anchor_cols_config = [x.strip() for x in anchor_col_config.split(',')]
282
-
283
  tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
284
-
285
  valid_tables = [t for t in tables if t.lower() not in ['mapping_registry', 'mapping_table', 'table_config', 'sqlite_sequence']]
286
 
287
  main_table = f"{standard}_{version}"
@@ -325,6 +308,30 @@ def fetch_database_records(standard, version, selection, table_type):
325
 
326
  df = df.drop(columns=[c for c in df.columns if c.lower() == "version"], errors="ignore")
327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  real_anchors = []
329
  for ac in anchor_cols_config:
330
  real_ac = next((c for c in df.columns if c.lower() == ac.lower()), ac)
@@ -344,7 +351,6 @@ def fetch_database_records(standard, version, selection, table_type):
344
  for col in df.columns:
345
  df[col] = df[col].apply(convert_blob_to_html_img)
346
 
347
- conn.close()
348
  return df, real_anchors
349
 
350
  except Exception as e:
@@ -352,7 +358,6 @@ def fetch_database_records(standard, version, selection, table_type):
352
  traceback.print_exc()
353
  return pd.DataFrame({"Error": [str(e)]}), []
354
 
355
-
356
  def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat, diff_only):
357
  try:
358
  def get_type_by_cat(cat):
@@ -363,9 +368,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
363
  type_b = get_type_by_cat(base_cat)
364
  type_c = get_type_by_cat(comp_cat)
365
 
366
- anchor_col_b, _ = get_table_config(type_b)
367
- anchor_col_c, _ = get_table_config(type_c)
368
-
369
  def apply_visual_merge(df, cols):
370
  if not df.empty and len(cols) > 1:
371
  is_dup = pd.Series([True] * len(df), index=df.index)
 
252
 
253
  return " ".join(b_result), " ".join(c_result)
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  def fetch_database_records(standard, version, selection, table_type):
256
  if not all([standard, version, selection]):
257
  return pd.DataFrame({"Info": ["선택 ν•„μš”"]}), []
 
264
  conn = sqlite3.connect(db_path)
265
  conn.text_factory = decode_sqlite_text
266
 
 
 
 
267
  tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
 
268
  valid_tables = [t for t in tables if t.lower() not in ['mapping_registry', 'mapping_table', 'table_config', 'sqlite_sequence']]
269
 
270
  main_table = f"{standard}_{version}"
 
308
 
309
  df = df.drop(columns=[c for c in df.columns if c.lower() == "version"], errors="ignore")
310
 
311
+ # =========================================================
312
+ # πŸ’‘ [슀마트 μŠ€μΊ” 둜직] DB μ»¬λŸΌμ„ 보고 λ§žλŠ” Main 섀정을 μ•Œμ•„μ„œ μ°ΎμŠ΅λ‹ˆλ‹€.
313
+ # =========================================================
314
+ conn_map = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
315
+ config_df = pd.read_sql("SELECT Anchor_Column, Display_Columns FROM Table_Config WHERE Table_Type=?", conn_map, params=[table_type])
316
+ conn_map.close()
317
+
318
+ anchor_col_config = "Section"
319
+ display_setting = "Description"
320
+
321
+ if not config_df.empty:
322
+ df_cols_lower = [c.lower() for c in df.columns]
323
+ for _, row in config_df.iterrows():
324
+ # DB에 적힌 Anchor 열이 μ‹€μ œ λ°μ΄ν„°ν”„λ ˆμž„μ— μ‘΄μž¬ν•˜λŠ”μ§€ 확인
325
+ first_anchor = str(row['Anchor_Column']).split(',')[0].strip().lower()
326
+ if first_anchor in df_cols_lower:
327
+ anchor_col_config = str(row['Anchor_Column'])
328
+ raw_disp = row['Display_Columns']
329
+ display_setting = str(raw_disp) if pd.notna(raw_disp) and str(raw_disp).strip() != "" else None
330
+ break
331
+ # =========================================================
332
+
333
+ anchor_cols_config = [x.strip() for x in anchor_col_config.split(',')]
334
+
335
  real_anchors = []
336
  for ac in anchor_cols_config:
337
  real_ac = next((c for c in df.columns if c.lower() == ac.lower()), ac)
 
351
  for col in df.columns:
352
  df[col] = df[col].apply(convert_blob_to_html_img)
353
 
 
354
  return df, real_anchors
355
 
356
  except Exception as e:
 
358
  traceback.print_exc()
359
  return pd.DataFrame({"Error": [str(e)]}), []
360
 
 
361
  def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat, diff_only):
362
  try:
363
  def get_type_by_cat(cat):
 
368
  type_b = get_type_by_cat(base_cat)
369
  type_c = get_type_by_cat(comp_cat)
370
 
 
 
 
371
  def apply_visual_merge(df, cols):
372
  if not df.empty and len(cols) > 1:
373
  is_dup = pd.Series([True] * len(df), index=df.index)