Update app.py
Browse files
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.
|
| 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 |
# --------------------------
|