Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -390,93 +390,55 @@ def process_dataframe(df):
|
|
| 390 |
|
| 391 |
@app.route("/report")
|
| 392 |
def report_view():
|
| 393 |
-
|
| 394 |
report_type = request.args.get('report_type', 'pred')
|
| 395 |
try:
|
| 396 |
page = int(request.args.get('page', 1))
|
| 397 |
except ValueError:
|
| 398 |
page = 1
|
| 399 |
-
per_page = 15
|
| 400 |
|
| 401 |
-
#
|
| 402 |
if report_type == 'pred':
|
| 403 |
df = pd.read_csv(PRED_OUTPUT_FILE)
|
| 404 |
else:
|
| 405 |
df = pd.read_csv(CLASS_OUTPUT_FILE)
|
| 406 |
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
df_page = df.iloc[start_idx:end_idx]
|
| 412 |
-
|
| 413 |
-
# 3. build df & html
|
| 414 |
-
df = pd.DataFrame({
|
| 415 |
-
"EngCts": df["EngCts"],
|
| 416 |
-
"Makable_Predicted": labels,
|
| 417 |
-
"Makable_Diff": df["EngCts"].astype(float) - label_enc.transform(labels)
|
| 418 |
-
})
|
| 419 |
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
return render_template(
|
| 423 |
-
"output.html",
|
| 424 |
-
report_type="pred",
|
| 425 |
-
page=1,
|
| 426 |
-
has_prev=False,
|
| 427 |
-
has_next=False,
|
| 428 |
-
table_html=table_html
|
| 429 |
-
)
|
| 430 |
-
|
| 431 |
-
# -------------------------------------V Colored CHnages --------------------------------------
|
| 432 |
-
'''
|
| 433 |
def add_colored_arrow(row):
|
| 434 |
try:
|
| 435 |
pred = float(row['Makable_Predicted'])
|
| 436 |
diff = float(row['Makable_Diff'])
|
| 437 |
-
if
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
return f'{pred:.3f} <span style="color:green;">↑</span>'
|
| 441 |
-
else:
|
| 442 |
-
return f'{pred:.3f} <span style="color:red;">↓</span>'
|
| 443 |
except:
|
| 444 |
-
return row
|
| 445 |
|
| 446 |
df_page['Makable_Predicted'] = df_page.apply(add_colored_arrow, axis=1)
|
| 447 |
-
|
| 448 |
-
#
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
# if diff > 0:
|
| 456 |
-
# return f'{pred:.3f} <i class="fas fa-arrow-up" style="color:green;"></i>'
|
| 457 |
-
# else:
|
| 458 |
-
# return f'{pred:.3f} <i class="fas fa-arrow-down" style="color:red;"></i>'
|
| 459 |
-
# except:
|
| 460 |
-
# return row['Makable_Predicted']
|
| 461 |
-
|
| 462 |
-
# df_page['Makable_Predicted'] = df_page.apply(add_fa_icon, axis=1)
|
| 463 |
-
# # -------------------------------------V Icon CHnages --------------------------------------
|
| 464 |
-
|
| 465 |
-
table_html = df_page.to_html(classes="data-table", index=False, escape=False)
|
| 466 |
-
|
| 467 |
has_prev = page > 1
|
| 468 |
-
has_next =
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
print("------------------------------------------------------------------------------------------------")
|
| 479 |
-
'''
|
| 480 |
|
| 481 |
# ------------------------------
|
| 482 |
# Download Routes
|
|
|
|
| 390 |
|
| 391 |
@app.route("/report")
|
| 392 |
def report_view():
|
|
|
|
| 393 |
report_type = request.args.get('report_type', 'pred')
|
| 394 |
try:
|
| 395 |
page = int(request.args.get('page', 1))
|
| 396 |
except ValueError:
|
| 397 |
page = 1
|
| 398 |
+
per_page = 15
|
| 399 |
|
| 400 |
+
# load CSV
|
| 401 |
if report_type == 'pred':
|
| 402 |
df = pd.read_csv(PRED_OUTPUT_FILE)
|
| 403 |
else:
|
| 404 |
df = pd.read_csv(CLASS_OUTPUT_FILE)
|
| 405 |
|
| 406 |
+
# page slice
|
| 407 |
+
start = (page - 1) * per_page
|
| 408 |
+
end = start + per_page
|
| 409 |
+
df_page = df.iloc[start:end].copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
+
# optional: colored arrow in Makable_Predicted
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
def add_colored_arrow(row):
|
| 413 |
try:
|
| 414 |
pred = float(row['Makable_Predicted'])
|
| 415 |
diff = float(row['Makable_Diff'])
|
| 416 |
+
arrow = '↑' if diff > 0 else '↓'
|
| 417 |
+
color = 'green' if diff > 0 else 'red'
|
| 418 |
+
return f"{pred:.3f} <span style='color:{color};'>{arrow}</span>"
|
|
|
|
|
|
|
|
|
|
| 419 |
except:
|
| 420 |
+
return row.get('Makable_Predicted', '')
|
| 421 |
|
| 422 |
df_page['Makable_Predicted'] = df_page.apply(add_colored_arrow, axis=1)
|
| 423 |
+
|
| 424 |
+
# render to HTML (allow our <span> tags)
|
| 425 |
+
table_html = df_page.to_html(
|
| 426 |
+
classes="report-table",
|
| 427 |
+
index=False,
|
| 428 |
+
escape=False
|
| 429 |
+
)
|
| 430 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
has_prev = page > 1
|
| 432 |
+
has_next = end < len(df)
|
| 433 |
+
|
| 434 |
+
return render_template(
|
| 435 |
+
"output.html",
|
| 436 |
+
report_type=report_type,
|
| 437 |
+
page=page,
|
| 438 |
+
has_prev=has_prev,
|
| 439 |
+
has_next=has_next,
|
| 440 |
+
table_html=table_html
|
| 441 |
+
)
|
|
|
|
|
|
|
| 442 |
|
| 443 |
# ------------------------------
|
| 444 |
# Download Routes
|