QIDNLF commited on
Commit
342f4f1
ยท
verified ยท
1 Parent(s): 490c1aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -21
app.py CHANGED
@@ -219,6 +219,20 @@ def generate_html_diff(base_text, comp_text):
219
 
220
  return " ".join(b_result), " ".join(c_result)
221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  def fetch_database_records(standard, version, selection):
223
  if not all([standard, version, selection]):
224
  return pd.DataFrame({"Info": ["์„ ํƒ ํ•„์š”"]})
@@ -282,8 +296,11 @@ def fetch_database_records(standard, version, selection):
282
  df = pd.DataFrame(cursor.fetchall(), columns=cols)
283
  df.columns = [c.lower().strip() for c in df.columns]
284
 
285
- if 'section' in df.columns and 'description' in df.columns:
286
- df = df[['section', 'description']]
 
 
 
287
 
288
  for col in df.columns:
289
  df[col] = df[col].apply(convert_blob_to_html_img)
@@ -295,25 +312,27 @@ def fetch_database_records(standard, version, selection):
295
  return pd.DataFrame({"Error": [str(e)]})
296
 
297
  def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat):
298
- try:
299
- # ๋‹จ์ผ ์กฐํšŒ
300
- if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
301
- df = fetch_database_records(base_std, base_ver, base_cat)
302
- if "Error" in df.columns or "Info" in df.columns:
303
- return df
304
-
305
- rename_dict = {col: col.title() for col in df.columns if col.lower() in ['section', 'description']}
306
- df = df.rename(columns=rename_dict)
307
-
308
- if not df.empty and len(df.columns) > 1:
309
- is_duplicate = pd.Series([True] * len(df), index=df.index)
310
- for col in df.columns[:-1]:
311
- current_col_str = df[col].astype(str).str.strip()
312
- current_match = (current_col_str == current_col_str.shift(1)) & (~current_col_str.isin(["", "nan", "None", " "]))
313
- is_duplicate = is_duplicate & current_match
314
- df.loc[is_duplicate, col] = " "
315
-
316
- return df
 
 
317
 
318
  # ๋น„๊ต ์กฐํšŒ
319
  if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
 
219
 
220
  return " ".join(b_result), " ".join(c_result)
221
 
222
+ def get_table_config(table_type):
223
+ try:
224
+ conn = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
225
+ query = "SELECT Anchor_Column, Display_Columns FROM Table_Config WHERE Table_Type=?"
226
+ df = pd.read_sql(query, conn, params=[table_type])
227
+ conn.close()
228
+
229
+ if not df.empty:
230
+ return df.iloc[0]['Anchor_Column'], df.iloc[0]['Display_Columns']
231
+ except Exception:
232
+ pass
233
+
234
+ return "Section", "Description"
235
+
236
  def fetch_database_records(standard, version, selection):
237
  if not all([standard, version, selection]):
238
  return pd.DataFrame({"Info": ["์„ ํƒ ํ•„์š”"]})
 
296
  df = pd.DataFrame(cursor.fetchall(), columns=cols)
297
  df.columns = [c.lower().strip() for c in df.columns]
298
 
299
+ if display_setting:
300
+ cols_to_show = [c.strip() for c in display_setting.split(',')]
301
+ if anchor_col not in cols_to_show:
302
+ cols_to_show.insert(0, anchor_col)
303
+ df = df[cols_to_show]
304
 
305
  for col in df.columns:
306
  df[col] = df[col].apply(convert_blob_to_html_img)
 
312
  return pd.DataFrame({"Error": [str(e)]})
313
 
314
  def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat):
315
+ # 1. ํ…Œ์ด๋ธ” ํƒ€์ž… ํŒ๋ณ„ (์„ ํƒ๋œ ์นดํ…Œ๊ณ ๋ฆฌ ๋ช…์นญ ๋“ฑ์œผ๋กœ ํŒ๋ณ„)
316
+ table_type = "Main" if base_cat == "ALL" or "." in base_cat else base_cat
317
+ anchor_col, _ = get_table_config(table_type)
318
+
319
+ # 2. ์–‘์ธก ๋ฐ์ดํ„ฐ ๋กœ๋“œ (์ด์ œ 6์—ด์”ฉ ๊ฐ€๋“ ์ฐจ์„œ ์˜ต๋‹ˆ๋‹ค)
320
+ df_base = fetch_database_records(base_std, base_ver, base_cat, table_type)
321
+ df_comp = fetch_database_records(comp_std, comp_ver, comp_cat, table_type)
322
+
323
+ # 3. ์ปฌ๋Ÿผ๋ช…์— ๋ฒ„์ „ ์ ‘๋ฏธ์‚ฌ ๋ถ™์—ฌ์„œ 12์—ด ์ค€๋น„
324
+ df_base = df_base.add_suffix(f'_{base_ver}')
325
+ df_comp = df_comp.add_suffix(f'_{comp_ver}')
326
+
327
+ # 4. Anchor Column์„ ๊ธฐ์ค€์œผ๋กœ JOIN (์ด๊ฒŒ 6+6 ํ•ต์‹ฌ)
328
+ final_df = pd.merge(
329
+ df_base, df_comp,
330
+ left_on=f"{anchor_col}_{base_ver}",
331
+ right_on=f"{anchor_col}_{comp_ver}",
332
+ how='outer'
333
+ )
334
+
335
+ return final_df
336
 
337
  # ๋น„๊ต ์กฐํšŒ
338
  if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):