Update app.py
Browse files
app.py
CHANGED
|
@@ -184,20 +184,24 @@ def display_data(standard, version, selection):
|
|
| 184 |
if main_t not in tables:
|
| 185 |
main_t = tables[0]
|
| 186 |
|
| 187 |
-
#
|
|
|
|
|
|
|
| 188 |
full_table_name = None
|
| 189 |
pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
|
| 190 |
-
|
| 191 |
for t in tables:
|
| 192 |
-
if t == selection:
|
| 193 |
full_table_name = t
|
| 194 |
break
|
| 195 |
short = pattern.sub("", t).strip(" _")
|
| 196 |
-
if short == selection:
|
| 197 |
full_table_name = t
|
| 198 |
break
|
| 199 |
|
| 200 |
-
#
|
|
|
|
|
|
|
| 201 |
if full_table_name:
|
| 202 |
df = pd.read_sql(f"SELECT * FROM [{full_table_name}]", conn)
|
| 203 |
df.columns = [c.strip() for c in df.columns]
|
|
@@ -210,7 +214,9 @@ def display_data(standard, version, selection):
|
|
| 210 |
conn.close()
|
| 211 |
return df
|
| 212 |
|
| 213 |
-
#
|
|
|
|
|
|
|
| 214 |
cols = pd.read_sql(f"PRAGMA table_info([{main_t}])", conn)['name'].tolist()
|
| 215 |
lower = [c.lower().strip() for c in cols]
|
| 216 |
|
|
@@ -221,18 +227,44 @@ def display_data(standard, version, selection):
|
|
| 221 |
elif lc == "category":
|
| 222 |
real_cat = c
|
| 223 |
|
|
|
|
|
|
|
|
|
|
| 224 |
if selection == "ALL":
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
df.columns = [c.lower().strip() for c in df.columns]
|
| 237 |
|
| 238 |
if 'section' in df.columns and 'description' in df.columns:
|
|
|
|
| 184 |
if main_t not in tables:
|
| 185 |
main_t = tables[0]
|
| 186 |
|
| 187 |
+
# --------------------------
|
| 188 |
+
# ํ
์ด๋ธ reverse lookup
|
| 189 |
+
# --------------------------
|
| 190 |
full_table_name = None
|
| 191 |
pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
|
| 192 |
+
|
| 193 |
for t in tables:
|
| 194 |
+
if t == selection:
|
| 195 |
full_table_name = t
|
| 196 |
break
|
| 197 |
short = pattern.sub("", t).strip(" _")
|
| 198 |
+
if short == selection:
|
| 199 |
full_table_name = t
|
| 200 |
break
|
| 201 |
|
| 202 |
+
# --------------------------
|
| 203 |
+
# ๐น TableA/B ์ ํ๋ ๊ฒฝ์ฐ
|
| 204 |
+
# --------------------------
|
| 205 |
if full_table_name:
|
| 206 |
df = pd.read_sql(f"SELECT * FROM [{full_table_name}]", conn)
|
| 207 |
df.columns = [c.strip() for c in df.columns]
|
|
|
|
| 214 |
conn.close()
|
| 215 |
return df
|
| 216 |
|
| 217 |
+
# --------------------------
|
| 218 |
+
# ๋ฉ์ธ ํ
์ด๋ธ ๊ตฌ์กฐ ํ์
|
| 219 |
+
# --------------------------
|
| 220 |
cols = pd.read_sql(f"PRAGMA table_info([{main_t}])", conn)['name'].tolist()
|
| 221 |
lower = [c.lower().strip() for c in cols]
|
| 222 |
|
|
|
|
| 227 |
elif lc == "category":
|
| 228 |
real_cat = c
|
| 229 |
|
| 230 |
+
# --------------------------
|
| 231 |
+
# ๐น ALL ์ ํ
|
| 232 |
+
# --------------------------
|
| 233 |
if selection == "ALL":
|
| 234 |
+
query = f"SELECT * FROM [{main_t}]"
|
| 235 |
+
|
| 236 |
+
if real_cat:
|
| 237 |
+
query += f"""
|
| 238 |
+
WHERE IFNULL(UPPER(TRIM(CAST([{real_cat}] AS TEXT))), '') != 'TABLE'
|
| 239 |
+
"""
|
| 240 |
+
|
| 241 |
+
df = pd.read_sql(query, conn)
|
| 242 |
+
|
| 243 |
+
# --------------------------
|
| 244 |
+
# ๐น chapter.category ์ ํ
|
| 245 |
+
# --------------------------
|
| 246 |
+
elif "." in selection and real_ch and real_cat:
|
| 247 |
+
ch, ca = selection.split(".", 1)
|
| 248 |
+
|
| 249 |
+
df = pd.read_sql(
|
| 250 |
+
f"""
|
| 251 |
+
SELECT * FROM [{main_t}]
|
| 252 |
+
WHERE REPLACE(TRIM(CAST([{real_ch}] AS TEXT)), ' ', '') = ?
|
| 253 |
+
AND REPLACE(TRIM(CAST([{real_cat}] AS TEXT)), ' ', '') = ?
|
| 254 |
+
""",
|
| 255 |
+
conn,
|
| 256 |
+
params=[ch.replace(" ", ""), ca.replace(" ", "")]
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
# --------------------------
|
| 260 |
+
# fallback
|
| 261 |
+
# --------------------------
|
| 262 |
+
else:
|
| 263 |
+
df = pd.read_sql(f"SELECT * FROM [{main_t}]", conn)
|
| 264 |
+
|
| 265 |
+
# --------------------------
|
| 266 |
+
# ํ์ฒ๋ฆฌ
|
| 267 |
+
# --------------------------
|
| 268 |
df.columns = [c.lower().strip() for c in df.columns]
|
| 269 |
|
| 270 |
if 'section' in df.columns and 'description' in df.columns:
|