QIDNLF commited on
Commit
72cded0
ยท
verified ยท
1 Parent(s): 1b5d97e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -17
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
- # ๐Ÿš€ ์ž˜๋ฆฐ short_name์œผ๋กœ ์›๋ž˜ ํ’€๋„ค์ž„ ํ…Œ์ด๋ธ” ์ฐพ๊ธฐ (Reverse Lookup)
 
 
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: # ๋“œ๋กญ๋‹ค์šด์˜ ์งง์€ ์ด๋ฆ„๊ณผ ๋งค์นญ๋˜๋Š” ์‹ค์ œ DB ํ…Œ์ด๋ธ” ์ฐพ๊ธฐ
197
  full_table_name = t
198
  break
199
 
200
- # ํ…Œ์ด๋ธ”(A4/1 ๋“ฑ)์„ ์„ ํƒํ•œ ๊ฒฝ์šฐ
 
 
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
- # ALL ๋˜๋Š” ์ฑ•ํ„ฐ.์นดํ…Œ๊ณ ๋ฆฌ ์„ ํƒํ•œ ๊ฒฝ์šฐ
 
 
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
- # ๐Ÿš€ ๋ฌด์กฐ๊ฑด ๋ฉ”์ธ ํ…Œ์ด๋ธ”๋งŒ ์‚ฌ์šฉ (TableA/B ์™„์ „ ์ฐจ๋‹จ)
226
- query = f"SELECT * FROM [{main_t}]"
227
-
228
- # category ์ปฌ๋Ÿผ ์žˆ์œผ๋ฉด 'Table' ์ œ์™ธ
229
- if real_cat:
230
- query += f"""
231
- WHERE IFNULL(UPPER(TRIM(CAST([{real_cat}] AS TEXT))), '') != 'TABLE'
232
- """
233
-
234
- df = pd.read_sql(query, conn)
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: