Diego Marroquin commited on
Commit ·
60ef6dd
1
Parent(s): aa1e369
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import json
|
| 5 |
+
import io
|
| 6 |
+
import datetime
|
| 7 |
+
|
| 8 |
+
st.title("Nucmonitor App")
|
| 9 |
+
|
| 10 |
+
# Get user input (e.g., dates)
|
| 11 |
+
start_date = st.date_input("Start Date")
|
| 12 |
+
end_date = st.date_input("End Date")
|
| 13 |
+
photo_date = st.checkbox("Photodate")
|
| 14 |
+
|
| 15 |
+
if photo_date == True:
|
| 16 |
+
past_date = st.date_input("Cutoff Date")
|
| 17 |
+
else:
|
| 18 |
+
past_date = None
|
| 19 |
+
|
| 20 |
+
@st.cache_data
|
| 21 |
+
def get_nucmonitor_data(start_date, end_date, photo_date, past_date):
|
| 22 |
+
response_nucmonitor = requests.get(f"http://127.0.0.1:5000/nucpy/v1/nucmonitor?start_date={start_date}&end_date={end_date}&photo_date={photo_date}&past_date={past_date}")
|
| 23 |
+
nucmonitor_data = response_nucmonitor.json()
|
| 24 |
+
nucmonitor_json = json.loads(nucmonitor_data)
|
| 25 |
+
df = pd.DataFrame(nucmonitor_json)
|
| 26 |
+
return df
|
| 27 |
+
|
| 28 |
+
with st.form("nucmonitor_form"):
|
| 29 |
+
submitted = st.form_submit_button("Get Nucmonitor")
|
| 30 |
+
|
| 31 |
+
if submitted:
|
| 32 |
+
df = get_nucmonitor_data(start_date, end_date, photo_date, past_date)
|
| 33 |
+
st.sidebar.write("FILTERS")
|
| 34 |
+
st.write("Data received from Flask:")
|
| 35 |
+
|
| 36 |
+
st.write(df) # Display DataFrame
|
| 37 |
+
|
| 38 |
+
# Create a line chart using Streamlit
|
| 39 |
+
st.title("Power Plant Data Visualization")
|
| 40 |
+
df1 = df.iloc[:-1, :-1]
|
| 41 |
+
# Create a line chart using Streamlit
|
| 42 |
+
st.line_chart(df1)
|
| 43 |
+
|
| 44 |
+
if df is not None:
|
| 45 |
+
st.title("Data Filters")
|
| 46 |
+
df_columns_lst = df.columns.tolist()
|
| 47 |
+
print(df_columns_lst)
|
| 48 |
+
# Select columns for display
|
| 49 |
+
|
| 50 |
+
selected_columns = st.sidebar.multiselect("Select Columns to Display",
|
| 51 |
+
options=df_columns_lst,
|
| 52 |
+
default=df_columns_lst,
|
| 53 |
+
key=None
|
| 54 |
+
)
|
| 55 |
+
st.sidebar.write('Selected plants:', selected_columns)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# Filter rows by checking column 0
|
| 60 |
+
# filter_row_contains_value = st.sidebar.checkbox("Filter Rows by Date", False)
|
| 61 |
+
|
| 62 |
+
filtered_df = df.copy()
|
| 63 |
+
print("filtered_df = df.copy()")
|
| 64 |
+
filtered_df = filtered_df[selected_columns]
|
| 65 |
+
print("filtered_df = filtered_df[selected_columns]")
|
| 66 |
+
# if filter_row_contains_value:
|
| 67 |
+
# filtered_df = filtered_df[filtered_df.iloc[:, 0].astype(str).str.contains('0', case=False, na=False)]
|
| 68 |
+
|
| 69 |
+
st.write("Filtered Data:")
|
| 70 |
+
st.write(filtered_df)
|
| 71 |
+
print("st.write(filtered_df)")
|
| 72 |
+
|
| 73 |
+
# Add a download button
|
| 74 |
+
current_datetime = datetime.datetime.now()
|
| 75 |
+
current_year = current_datetime.strftime('%Y')
|
| 76 |
+
current_month = current_datetime.strftime('%m')
|
| 77 |
+
current_day = current_datetime.strftime('%d')
|
| 78 |
+
current_hour = current_datetime.strftime('%H')
|
| 79 |
+
current_minute = current_datetime.strftime('%M')
|
| 80 |
+
current_second = current_datetime.strftime('%S')
|
| 81 |
+
|
| 82 |
+
# Create a BytesIO object to hold the Excel data
|
| 83 |
+
excel_buffer = io.BytesIO()
|
| 84 |
+
|
| 85 |
+
# Save the DataFrame to the BytesIO object as an Excel file
|
| 86 |
+
filtered_df.to_excel(excel_buffer, index=True)
|
| 87 |
+
|
| 88 |
+
# Set the cursor position to the beginning of the BytesIO object
|
| 89 |
+
excel_buffer.seek(0)
|
| 90 |
+
|
| 91 |
+
# Provide the BytesIO object to the download button
|
| 92 |
+
download_button = st.download_button(
|
| 93 |
+
label="Download Excel",
|
| 94 |
+
data=excel_buffer,
|
| 95 |
+
file_name=f"nucmonitor_data_{current_year}-{current_month}-{current_day}-h{current_hour}m{current_minute}s{current_second}.xlsx",
|
| 96 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 97 |
+
)
|