Update app.py
Browse files
app.py
CHANGED
|
@@ -219,6 +219,20 @@ def generate_html_diff(base_text, comp_text):
|
|
| 219 |
|
| 220 |
return " ".join(b_result), " ".join(c_result)
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
def fetch_database_records(standard, version, selection):
|
| 223 |
if not all([standard, version, selection]):
|
| 224 |
return pd.DataFrame({"Info": ["์ ํ ํ์"]})
|
|
@@ -282,8 +296,11 @@ def fetch_database_records(standard, version, selection):
|
|
| 282 |
df = pd.DataFrame(cursor.fetchall(), columns=cols)
|
| 283 |
df.columns = [c.lower().strip() for c in df.columns]
|
| 284 |
|
| 285 |
-
if
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
for col in df.columns:
|
| 289 |
df[col] = df[col].apply(convert_blob_to_html_img)
|
|
@@ -295,25 +312,27 @@ def fetch_database_records(standard, version, selection):
|
|
| 295 |
return pd.DataFrame({"Error": [str(e)]})
|
| 296 |
|
| 297 |
def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat):
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
|
|
|
|
|
|
| 317 |
|
| 318 |
# ๋น๊ต ์กฐํ
|
| 319 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
|
|
|
| 219 |
|
| 220 |
return " ".join(b_result), " ".join(c_result)
|
| 221 |
|
| 222 |
+
def get_table_config(table_type):
|
| 223 |
+
try:
|
| 224 |
+
conn = sqlite3.connect(os.path.join(UPLOAD_DIR, "mapping.db"))
|
| 225 |
+
query = "SELECT Anchor_Column, Display_Columns FROM Table_Config WHERE Table_Type=?"
|
| 226 |
+
df = pd.read_sql(query, conn, params=[table_type])
|
| 227 |
+
conn.close()
|
| 228 |
+
|
| 229 |
+
if not df.empty:
|
| 230 |
+
return df.iloc[0]['Anchor_Column'], df.iloc[0]['Display_Columns']
|
| 231 |
+
except Exception:
|
| 232 |
+
pass
|
| 233 |
+
|
| 234 |
+
return "Section", "Description"
|
| 235 |
+
|
| 236 |
def fetch_database_records(standard, version, selection):
|
| 237 |
if not all([standard, version, selection]):
|
| 238 |
return pd.DataFrame({"Info": ["์ ํ ํ์"]})
|
|
|
|
| 296 |
df = pd.DataFrame(cursor.fetchall(), columns=cols)
|
| 297 |
df.columns = [c.lower().strip() for c in df.columns]
|
| 298 |
|
| 299 |
+
if display_setting:
|
| 300 |
+
cols_to_show = [c.strip() for c in display_setting.split(',')]
|
| 301 |
+
if anchor_col not in cols_to_show:
|
| 302 |
+
cols_to_show.insert(0, anchor_col)
|
| 303 |
+
df = df[cols_to_show]
|
| 304 |
|
| 305 |
for col in df.columns:
|
| 306 |
df[col] = df[col].apply(convert_blob_to_html_img)
|
|
|
|
| 312 |
return pd.DataFrame({"Error": [str(e)]})
|
| 313 |
|
| 314 |
def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat):
|
| 315 |
+
# 1. ํ
์ด๋ธ ํ์
ํ๋ณ (์ ํ๋ ์นดํ
๊ณ ๋ฆฌ ๋ช
์นญ ๋ฑ์ผ๋ก ํ๋ณ)
|
| 316 |
+
table_type = "Main" if base_cat == "ALL" or "." in base_cat else base_cat
|
| 317 |
+
anchor_col, _ = get_table_config(table_type)
|
| 318 |
+
|
| 319 |
+
# 2. ์์ธก ๋ฐ์ดํฐ ๋ก๋ (์ด์ 6์ด์ฉ ๊ฐ๋ ์ฐจ์ ์ต๋๋ค)
|
| 320 |
+
df_base = fetch_database_records(base_std, base_ver, base_cat, table_type)
|
| 321 |
+
df_comp = fetch_database_records(comp_std, comp_ver, comp_cat, table_type)
|
| 322 |
+
|
| 323 |
+
# 3. ์ปฌ๋ผ๋ช
์ ๋ฒ์ ์ ๋ฏธ์ฌ ๋ถ์ฌ์ 12์ด ์ค๋น
|
| 324 |
+
df_base = df_base.add_suffix(f'_{base_ver}')
|
| 325 |
+
df_comp = df_comp.add_suffix(f'_{comp_ver}')
|
| 326 |
+
|
| 327 |
+
# 4. Anchor Column์ ๊ธฐ์ค์ผ๋ก JOIN (์ด๊ฒ 6+6 ํต์ฌ)
|
| 328 |
+
final_df = pd.merge(
|
| 329 |
+
df_base, df_comp,
|
| 330 |
+
left_on=f"{anchor_col}_{base_ver}",
|
| 331 |
+
right_on=f"{anchor_col}_{comp_ver}",
|
| 332 |
+
how='outer'
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
return final_df
|
| 336 |
|
| 337 |
# ๋น๊ต ์กฐํ
|
| 338 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|