Update app.py
Browse files
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 |
-
|
| 254 |
|
| 255 |
real_ch, real_cat = None, None
|
| 256 |
-
for c, lc in zip(cols,
|
| 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 |
-
|
| 281 |
-
|
| 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 |
|