Diego Marroquin commited on
Commit ·
6e2dd81
1
Parent(s): 6e2e1ce
Added run_app(), if name == main; moved get_data functions outside of main function
Browse files
app.py
CHANGED
|
@@ -502,18 +502,6 @@ def nuc_monitor(usr_start_date, usr_end_date, photo_date, past_date):
|
|
| 502 |
# -------------------------------------------------
|
| 503 |
return
|
| 504 |
|
| 505 |
-
st.title("Nucmonitor App")
|
| 506 |
-
|
| 507 |
-
# Get user input (e.g., dates)
|
| 508 |
-
start_date = st.date_input("Start Date")
|
| 509 |
-
end_date = st.date_input("End Date")
|
| 510 |
-
photo_date = st.checkbox("Photodate")
|
| 511 |
-
|
| 512 |
-
if photo_date == True:
|
| 513 |
-
past_date = st.date_input("Cutoff Date")
|
| 514 |
-
else:
|
| 515 |
-
past_date = None
|
| 516 |
-
|
| 517 |
@st.cache_data
|
| 518 |
def get_rte_data(start_date, end_date):
|
| 519 |
rte_data = get_unavailabilities(start_date, end_date)
|
|
@@ -533,49 +521,71 @@ def get_nucmonitor_data(start_date, end_date, photo_date, past_date):
|
|
| 533 |
df = pd.read_json(response_nucmonitor)
|
| 534 |
return df
|
| 535 |
|
| 536 |
-
|
| 537 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
|
| 539 |
-
if
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
|
| 552 |
-
if df is not None:
|
| 553 |
st.title("Data Filters")
|
| 554 |
df_columns_lst = df.columns.tolist()
|
| 555 |
print(df_columns_lst)
|
| 556 |
-
# Select columns for display
|
| 557 |
|
|
|
|
| 558 |
selected_columns = st.sidebar.multiselect("Select Columns to Display",
|
| 559 |
options=df_columns_lst,
|
| 560 |
default=df_columns_lst,
|
| 561 |
key=None
|
| 562 |
)
|
| 563 |
-
st.sidebar.write('Selected plants:', selected_columns)
|
| 564 |
-
|
| 565 |
|
|
|
|
| 566 |
|
| 567 |
# Filter rows by checking column 0
|
| 568 |
# filter_row_contains_value = st.sidebar.checkbox("Filter Rows by Date", False)
|
| 569 |
|
| 570 |
-
filtered_df = df.copy()
|
| 571 |
print("filtered_df = df.copy()")
|
| 572 |
-
|
| 573 |
print("filtered_df = filtered_df[selected_columns]")
|
|
|
|
| 574 |
# if filter_row_contains_value:
|
| 575 |
# filtered_df = filtered_df[filtered_df.iloc[:, 0].astype(str).str.contains('0', case=False, na=False)]
|
| 576 |
|
| 577 |
st.write("Filtered Data:")
|
| 578 |
-
st.write(
|
| 579 |
print("st.write(filtered_df)")
|
| 580 |
|
| 581 |
# Add a download button
|
|
@@ -602,4 +612,7 @@ if submitted:
|
|
| 602 |
data=excel_buffer,
|
| 603 |
file_name=f"nucmonitor_data_{current_year}-{current_month}-{current_day}-h{current_hour}m{current_minute}s{current_second}.xlsx",
|
| 604 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 605 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
# -------------------------------------------------
|
| 503 |
return
|
| 504 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
@st.cache_data
|
| 506 |
def get_rte_data(start_date, end_date):
|
| 507 |
rte_data = get_unavailabilities(start_date, end_date)
|
|
|
|
| 521 |
df = pd.read_json(response_nucmonitor)
|
| 522 |
return df
|
| 523 |
|
| 524 |
+
def run_app():
|
| 525 |
+
|
| 526 |
+
st.title("Nucmonitor App")
|
| 527 |
+
|
| 528 |
+
# Get user input (e.g., dates)
|
| 529 |
+
start_date = st.date_input("Start Date")
|
| 530 |
+
end_date = st.date_input("End Date")
|
| 531 |
+
photo_date = st.checkbox("Photodate")
|
| 532 |
|
| 533 |
+
if photo_date == True:
|
| 534 |
+
past_date = st.date_input("Cutoff Date")
|
| 535 |
+
else:
|
| 536 |
+
past_date = None
|
| 537 |
+
|
| 538 |
+
with st.form("nucmonitor_form"):
|
| 539 |
+
submitted = st.form_submit_button("Get Nucmonitor")
|
| 540 |
|
| 541 |
+
if not submitted:
|
| 542 |
+
pass
|
| 543 |
+
|
| 544 |
+
else:
|
| 545 |
+
st.write("Data received from Flask:")
|
| 546 |
+
df = get_nucmonitor_data(start_date, end_date, photo_date, past_date)
|
| 547 |
+
st.sidebar.write("FILTERS")
|
| 548 |
|
| 549 |
+
st.write(df) # Display DataFrame
|
| 550 |
+
|
| 551 |
+
# Create a line chart using Streamlit
|
| 552 |
+
st.title("Power Plant Data Visualization")
|
| 553 |
+
df1 = df.iloc[:-1, :-1]
|
| 554 |
+
# Create a line chart using Streamlit
|
| 555 |
+
st.line_chart(df1)
|
| 556 |
+
|
| 557 |
+
# ---------------------------------------------------
|
| 558 |
+
#######################################################
|
| 559 |
+
#################### FILTERS ##########################
|
| 560 |
+
#######################################################
|
| 561 |
+
# if df is not None:
|
| 562 |
|
|
|
|
| 563 |
st.title("Data Filters")
|
| 564 |
df_columns_lst = df.columns.tolist()
|
| 565 |
print(df_columns_lst)
|
|
|
|
| 566 |
|
| 567 |
+
# Select columns for display
|
| 568 |
selected_columns = st.sidebar.multiselect("Select Columns to Display",
|
| 569 |
options=df_columns_lst,
|
| 570 |
default=df_columns_lst,
|
| 571 |
key=None
|
| 572 |
)
|
|
|
|
|
|
|
| 573 |
|
| 574 |
+
st.sidebar.write('Selected plants:', selected_columns)
|
| 575 |
|
| 576 |
# Filter rows by checking column 0
|
| 577 |
# filter_row_contains_value = st.sidebar.checkbox("Filter Rows by Date", False)
|
| 578 |
|
| 579 |
+
# filtered_df = df.copy()
|
| 580 |
print("filtered_df = df.copy()")
|
| 581 |
+
filtered_by_plant = df.copy()[selected_columns]
|
| 582 |
print("filtered_df = filtered_df[selected_columns]")
|
| 583 |
+
|
| 584 |
# if filter_row_contains_value:
|
| 585 |
# filtered_df = filtered_df[filtered_df.iloc[:, 0].astype(str).str.contains('0', case=False, na=False)]
|
| 586 |
|
| 587 |
st.write("Filtered Data:")
|
| 588 |
+
st.write(filtered_by_plant)
|
| 589 |
print("st.write(filtered_df)")
|
| 590 |
|
| 591 |
# Add a download button
|
|
|
|
| 612 |
data=excel_buffer,
|
| 613 |
file_name=f"nucmonitor_data_{current_year}-{current_month}-{current_day}-h{current_hour}m{current_minute}s{current_second}.xlsx",
|
| 614 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 615 |
+
)
|
| 616 |
+
|
| 617 |
+
if __name__ == '__main__':
|
| 618 |
+
run_app()
|