-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_application.py
90 lines (79 loc) · 3.04 KB
/
web_application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# streamlit_app.py
import streamlit as st
from streamlit.runtime.uploaded_file_manager import UploadedFile
import pandas as pd
from typing import List
from datetime import timedelta
from lastganganalyse.data_loader import DataLoader
from lastganganalyse.statistics import MonthlyStatistics
from lastganganalyse.data_plot import plot_monthly_bar, plot_yearly
def process_files(
uploaded_files: List[UploadedFile],
year: int,
time_delta: timedelta,
threshold: float,
) -> tuple[pd.DataFrame, pd.DataFrame]:
dfs: List[pd.DataFrame] = []
for uploaded_file in uploaded_files:
# Use DataLoader to load each file, initializing it with the specified time delta
data_loader = DataLoader(uploaded_file, time_delta)
data_loader.load_excel()
dfs.append(data_loader.df)
if dfs:
# Process the loaded DataFrames with MonthlyStatistics
monthly_stats = MonthlyStatistics(dfs, year)
monthly_stats.calculate_monthly_sum()
monthly_stats.calculate_monthly_max()
monthly_stats.count_values_above_threshold(
threshold
) # Use the user-specified threshold
monthly_stats.count_values_below_threshold(threshold)
monthly_stats.calculate_percentage()
monthly_stats.calculate_ratio_of_sum_to_max()
return monthly_stats.get_stats_df(), monthly_stats.get_raw_df()
else:
return (
pd.DataFrame(),
pd.DataFrame(),
) # Return an empty DataFrame if no files were processed
def main():
st.set_page_config(
page_title="Lastganganalyse",
layout="wide",
page_icon=":chart_with_downwards_trend:",
)
st.title("EMV-Lastganganalyse")
# File uploader
uploaded_files: List[UploadedFile] = st.file_uploader(
"Excel Rohdaten Upload", accept_multiple_files=True, type=["xlsx"]
)
# User inputs for year, threshold, and time delta
year: int = st.number_input(
"Jahr des Lastgangs", min_value=1900, max_value=2100, value=2022
)
threshold: float = st.number_input(
"Lastspitzengrenzwert [kW]", value=501, min_value=0
)
# Time delta input
time_delta_minutes: int = st.number_input(
"Zeitdifferenz der Messwerte [min]", min_value=1, value=15
)
time_delta: timedelta = timedelta(minutes=time_delta_minutes)
if st.button("Berechnen"):
if uploaded_files and year and time_delta:
result_df, raw_df = process_files(
uploaded_files, year, time_delta, threshold
)
if not result_df.empty:
st.write("Analysis Result:")
st.dataframe(result_df)
st.plotly_chart(plot_yearly(raw_df))
st.plotly_chart(plot_monthly_bar(result_df))
else:
st.write("No data to display. Please upload valid Excel files.")
else:
st.write(
"Please upload at least one Excel file, enter the year of the dataset, and specify the time delta."
)
if __name__ == "__main__":
main()