QIDNLF commited on
Commit
97f2ee5
ยท
verified ยท
1 Parent(s): 168385d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -13
app.py CHANGED
@@ -36,7 +36,6 @@ def blob_to_base64_html(blob_data):
36
  except Exception as e:
37
  return str(blob_data)
38
 
39
- # ๐Ÿš€ [ํ•ต์‹ฌ ์ถ”๊ฐ€] ํ…์ŠคํŠธ ๋””์ฝ”๋”ฉ ์—๋Ÿฌ ๋ฐฉ์ง€์šฉ ํŒฉํ† ๋ฆฌ ํ•จ์ˆ˜
40
  def safe_text_factory(x):
41
  """ํ…์ŠคํŠธ ๋””์ฝ”๋”ฉ์„ ์‹œ๋„ํ•˜๊ณ , ์‹คํŒจํ•˜๋ฉด(PNG ๋“ฑ ์ด๋ฏธ์ง€์ผ ๊ฒฝ์šฐ) ์›๋ณธ ๋ฐ”์ดํŠธ๋ฅผ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜"""
42
  try:
@@ -90,8 +89,7 @@ def update_category_dd(standard, version):
90
  try:
91
  target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
92
  conn = sqlite3.connect(target["path"])
93
-
94
- # ๐Ÿš€ [ํ•ต์‹ฌ ์ถ”๊ฐ€] ์นดํ…Œ๊ณ ๋ฆฌ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ๋„ ์ด๋ฏธ์ง€ ์—๋Ÿฌ ์ฐจ๋‹จ
95
  conn.text_factory = safe_text_factory
96
 
97
  tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
@@ -102,7 +100,6 @@ def update_category_dd(standard, version):
102
  cols = pd.read_sql(f"PRAGMA table_info([{main_t}])", conn)['name'].tolist()
103
  lower = [c.lower() for c in cols]
104
 
105
- # 1. ์ฑ•ํ„ฐ/์นดํ…Œ๊ณ ๋ฆฌ ๊ธฐ์ค€ ๋กœ์ง (๊ธฐ์กด ์œ ์ง€)
106
  if 'chapter' in lower and 'category' in lower:
107
  ch = cols[lower.index('chapter')]
108
  ca = cols[lower.index('category')]
@@ -112,14 +109,12 @@ def update_category_dd(standard, version):
112
  for _, r in df.iterrows():
113
  choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
114
 
115
- # 2. ํ…Œ์ด๋ธ” ์ด๋ฆ„ ๊น”๋”ํ•˜๊ฒŒ ์ž๋ฅด๊ธฐ (๊ฐ•๋ ฅํ•œ ์ •๊ทœ์‹ ์ ์šฉ)
116
  pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
117
 
118
  for t in tables:
119
  if t == main_t:
120
  continue
121
 
122
- # ๋Œ€์†Œ๋ฌธ์ž, ์–ธ๋”๋ฐ”, ๊ณต๋ฐฑ์„ ์ฐฐ๋–ก๊ฐ™์ด ๋ฌด์‹œํ•˜๊ณ  ๊ธฐ์ค€ ์ ‘๋‘์‚ฌ๋ฅผ ๋‚ ๋ ค๋ฒ„๋ฆผ
123
  short_name = pattern.sub("", t).strip(" _")
124
  choices.append(short_name)
125
 
@@ -190,7 +185,6 @@ def display_data(standard, version, selection):
190
  target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
191
  conn = sqlite3.connect(target["path"])
192
 
193
- # ๐Ÿš€ [ํ•ต์‹ฌ ์ถ”๊ฐ€] ๋ฐ์ดํ„ฐ ์กฐํšŒ ์‹œ ์ด๋ฏธ์ง€ ์—๋Ÿฌ ์™„๋ฒฝ ์ฐจ๋‹จ!
194
  conn.text_factory = safe_text_factory
195
 
196
  tables = pd.read_sql(
@@ -259,7 +253,6 @@ def display_data(standard, version, selection):
259
  # ๐Ÿ”น ALL ์„ ํƒ
260
  # --------------------------
261
  if selection == "ALL":
262
- # ๐Ÿš€ [์ˆ˜์ •] ํ…์ŠคํŠธ ํŒฉํ† ๋ฆฌ๋กœ ์—๋Ÿฌ๋ฅผ ์žก์•˜์œผ๋ฏ€๋กœ, ๋ถˆํ•„์š”ํ•œ ํ•„ํ„ฐ ์กฐ๊ฑด ์‚ญ์ œ
263
  cursor.execute(f"SELECT * FROM [{main_t}]")
264
 
265
  # --------------------------
@@ -293,7 +286,6 @@ def display_data(standard, version, selection):
293
  if 'section' in df.columns and 'description' in df.columns:
294
  df = df[['section', 'description']]
295
 
296
- # ๐Ÿ”ฅ ํ•ต์‹ฌ: blob โ†’ ์ด๋ฏธ์ง€ ๋ณ€ํ™˜ (์‚ญ์ œ X)
297
  for col in df.columns:
298
  df[col] = df[col].apply(blob_to_base64_html)
299
 
@@ -317,7 +309,7 @@ def apply_diff_row(row, base_col, comp_col):
317
  if "<img" in base_val or "<img" in comp_val:
318
  return pd.Series([base_val, comp_val])
319
 
320
- # 2. [ํ•ต์‹ฌ] ๋‘ ํ…์ŠคํŠธ๊ฐ€ ์™„์ „ํžˆ ๋˜‘๊ฐ™์œผ๋ฉด ๋ฌด๊ฑฐ์šด diff ์—ฐ์‚ฐ ์ƒ๋žต (Fast-path)
321
  if base_val == comp_val:
322
  return pd.Series([base_val, comp_val])
323
 
@@ -328,9 +320,6 @@ def apply_diff_row(row, base_col, comp_col):
328
 
329
  return pd.Series([base_val, comp_val])
330
 
331
-
332
- # (์œ„ ์ฝ”๋“œ๋Š” ๋™์ผ โ€” ์ƒ๋žต ์—†์ด ๊ทธ๋Œ€๋กœ ์œ ์ง€)
333
-
334
  def unified_search(bs, bv, bc, cs, cv, cc):
335
  try:
336
  # --------------------------
 
36
  except Exception as e:
37
  return str(blob_data)
38
 
 
39
  def safe_text_factory(x):
40
  """ํ…์ŠคํŠธ ๋””์ฝ”๋”ฉ์„ ์‹œ๋„ํ•˜๊ณ , ์‹คํŒจํ•˜๋ฉด(PNG ๋“ฑ ์ด๋ฏธ์ง€์ผ ๊ฒฝ์šฐ) ์›๋ณธ ๋ฐ”์ดํŠธ๋ฅผ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜"""
41
  try:
 
89
  try:
90
  target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
91
  conn = sqlite3.connect(target["path"])
92
+
 
93
  conn.text_factory = safe_text_factory
94
 
95
  tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
 
100
  cols = pd.read_sql(f"PRAGMA table_info([{main_t}])", conn)['name'].tolist()
101
  lower = [c.lower() for c in cols]
102
 
 
103
  if 'chapter' in lower and 'category' in lower:
104
  ch = cols[lower.index('chapter')]
105
  ca = cols[lower.index('category')]
 
109
  for _, r in df.iterrows():
110
  choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
111
 
 
112
  pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
113
 
114
  for t in tables:
115
  if t == main_t:
116
  continue
117
 
 
118
  short_name = pattern.sub("", t).strip(" _")
119
  choices.append(short_name)
120
 
 
185
  target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
186
  conn = sqlite3.connect(target["path"])
187
 
 
188
  conn.text_factory = safe_text_factory
189
 
190
  tables = pd.read_sql(
 
253
  # ๐Ÿ”น ALL ์„ ํƒ
254
  # --------------------------
255
  if selection == "ALL":
 
256
  cursor.execute(f"SELECT * FROM [{main_t}]")
257
 
258
  # --------------------------
 
286
  if 'section' in df.columns and 'description' in df.columns:
287
  df = df[['section', 'description']]
288
 
 
289
  for col in df.columns:
290
  df[col] = df[col].apply(blob_to_base64_html)
291
 
 
309
  if "<img" in base_val or "<img" in comp_val:
310
  return pd.Series([base_val, comp_val])
311
 
312
+ # 2. ๋‘ ํ…์ŠคํŠธ๊ฐ€ ์™„์ „ํžˆ ๋˜‘๊ฐ™์œผ๋ฉด ๋ฌด๊ฑฐ์šด diff ์—ฐ์‚ฐ ์ƒ๋žต (Fast-path)
313
  if base_val == comp_val:
314
  return pd.Series([base_val, comp_val])
315
 
 
320
 
321
  return pd.Series([base_val, comp_val])
322
 
 
 
 
323
  def unified_search(bs, bv, bc, cs, cv, cc):
324
  try:
325
  # --------------------------