QIDNLF commited on
Commit
e3453d8
ยท
verified ยท
1 Parent(s): c4ca859

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -201,7 +201,6 @@ def display_data(standard, version, selection):
201
  return pd.DataFrame({"Info": ["์„ ํƒ ํ•„์š”"]})
202
 
203
  try:
204
- # ์‹ค์‹œ๊ฐ„ ๊ฒฝ๋กœ ํ™•์ธ์„ ์œ„ํ•ด ์ง์ ‘ ๊ฒฝ๋กœ ์ƒ์„ฑ
205
  db_path = os.path.join(UPLOAD_DIR, f"{standard}_{version}.db")
206
  if not os.path.exists(db_path):
207
  return pd.DataFrame({"Error": [f"ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {db_path}"]})
@@ -218,7 +217,6 @@ def display_data(standard, version, selection):
218
  if main_t not in tables:
219
  main_t = tables[0]
220
 
221
-
222
  full_table_name = None
223
  pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
224
 
@@ -231,29 +229,27 @@ def display_data(standard, version, selection):
231
  full_table_name = t
232
  break
233
 
 
234
  if full_table_name and full_table_name != main_t:
235
  df = pd.read_sql(f"SELECT * FROM [{full_table_name}]", conn)
236
-
237
- # version ์—ด ์ œ์™ธ ๋ฐ ์ปฌ๋Ÿผ๋ช… ์ •๋ฆฌ
238
  df = df.drop(columns=[c for c in df.columns if c.lower() == "version"], errors="ignore")
239
  df.columns = [c.replace("_", " ").title() for c in df.columns]
240
 
241
- # ๋ชจ๋“  ์…€์— ๋Œ€ํ•ด ์ด๋ฏธ์ง€ ๋ Œ๋”๋ง(BLOB ๋ณ€ํ™˜) ์ ์šฉ
242
  for col in df.columns:
243
  df[col] = df[col].apply(blob_to_base64_html)
244
 
245
  conn.close()
246
  return df
247
 
248
-
249
  cursor = conn.cursor()
250
  cursor.execute(f"PRAGMA table_info([{main_t}])")
251
  cols_info = cursor.fetchall()
252
  cols = [c[1] for c in cols_info]
253
- lower = [c.lower().strip() for c in cols]
254
 
255
  real_ch, real_cat = None, None
256
- for c, lc in zip(cols, lower):
257
  if lc == "chapter": real_ch = c
258
  elif lc == "category": real_cat = c
259
 
@@ -273,14 +269,15 @@ def display_data(standard, version, selection):
273
  rows = cursor.fetchall()
274
  df = pd.DataFrame(rows, columns=cols)
275
 
 
 
276
  if 'section' in df.columns and 'description' in df.columns:
277
  df = df[['section', 'description']]
278
 
 
279
  for col in df.columns:
280
- if 'description' in col.lower() or 'desc' in col.lower():
281
- df[col] = df[col].apply(blob_to_base64_html)
282
- else:
283
- df[col] = df[col].fillna("").astype(str)
284
  conn.close()
285
  return df
286
 
 
201
  return pd.DataFrame({"Info": ["์„ ํƒ ํ•„์š”"]})
202
 
203
  try:
 
204
  db_path = os.path.join(UPLOAD_DIR, f"{standard}_{version}.db")
205
  if not os.path.exists(db_path):
206
  return pd.DataFrame({"Error": [f"ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {db_path}"]})
 
217
  if main_t not in tables:
218
  main_t = tables[0]
219
 
 
220
  full_table_name = None
221
  pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
222
 
 
229
  full_table_name = t
230
  break
231
 
232
+ # --- [1] ๋ณ„๋„ ํ…Œ์ด๋ธ” ์กฐํšŒ (Consolidated ๋“ฑ ๋ชจ๋“  ์—ด ์ถœ๋ ฅ) ---
233
  if full_table_name and full_table_name != main_t:
234
  df = pd.read_sql(f"SELECT * FROM [{full_table_name}]", conn)
 
 
235
  df = df.drop(columns=[c for c in df.columns if c.lower() == "version"], errors="ignore")
236
  df.columns = [c.replace("_", " ").title() for c in df.columns]
237
 
 
238
  for col in df.columns:
239
  df[col] = df[col].apply(blob_to_base64_html)
240
 
241
  conn.close()
242
  return df
243
 
244
+ # --- [2] ๋ฉ”์ธ ํ…Œ์ด๋ธ” ์กฐํšŒ (ALL/์นดํ…Œ๊ณ ๋ฆฌ - 2์—ด๋กœ ์ œํ•œ) ---
245
  cursor = conn.cursor()
246
  cursor.execute(f"PRAGMA table_info([{main_t}])")
247
  cols_info = cursor.fetchall()
248
  cols = [c[1] for c in cols_info]
249
+ lower_cols = [c.lower().strip() for c in cols]
250
 
251
  real_ch, real_cat = None, None
252
+ for c, lc in zip(cols, lower_cols):
253
  if lc == "chapter": real_ch = c
254
  elif lc == "category": real_cat = c
255
 
 
269
  rows = cursor.fetchall()
270
  df = pd.DataFrame(rows, columns=cols)
271
 
272
+ # ๐Ÿšจ [ํ•ต์‹ฌ ๋ณต๊ตฌ] ๋‹ค์‹œ section๊ณผ description๋งŒ ๋‚จ๊น๋‹ˆ๋‹ค.
273
+ df.columns = [c.lower().strip() for c in df.columns]
274
  if 'section' in df.columns and 'description' in df.columns:
275
  df = df[['section', 'description']]
276
 
277
+ # ์ด๋ฏธ์ง€ ๋ Œ๋”๋ง ์ ์šฉ
278
  for col in df.columns:
279
+ df[col] = df[col].apply(blob_to_base64_html)
280
+
 
 
281
  conn.close()
282
  return df
283