ifw-arz commited on
Commit
e93c297
1 Parent(s): 7bd0d5e
Files changed (2) hide show
  1. app.py +46 -0
  2. plot_data.py +58 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+
4
+ from plot_data import plotly_plot
5
+
6
+
7
+ def main():
8
+ st.markdown("<h2 style='text-align: left; color: black; font-family:Arial;font-size:2.25rem;'>Datenanalyse</h2>", unsafe_allow_html=True)
9
+
10
+ uploaded_file = st.file_uploader("CSV hochladen", type=["csv"])
11
+
12
+ if uploaded_file is not None:
13
+ try:
14
+ df = pd.read_csv(uploaded_file)
15
+ except pd.errors.EmptyDataError:
16
+ st.error("Fehler: Leere CSV Datei")
17
+ except Exception as e:
18
+ st.error(f"Error: {str(e)}")
19
+
20
+
21
+ tab1, tab2 = st.tabs(["Import", "Analyse"])
22
+
23
+ with tab1:
24
+
25
+ if uploaded_file is not None:
26
+
27
+ mittelwert = st.slider("Gleitender Mittelwert", 0, 1000, 0, 10)
28
+
29
+ time_column = st.selectbox("Zeit auswählen", df.columns, index=0)
30
+ data_column = st.selectbox("Daten auswählen", df.columns)
31
+
32
+ if time_column == data_column:
33
+ st.write("Zeit und Daten können nicht gleich sein")
34
+
35
+ try:
36
+ fig = plotly_plot(df, time_column, data_column, mittelwert)
37
+ fig.update_layout(width = 1200, height = 600)
38
+ st.plotly_chart(fig)
39
+ except:
40
+ pass
41
+
42
+ with tab2:
43
+ pass
44
+
45
+ if __name__ == "__main__":
46
+ main()
plot_data.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import plotly.graph_objects as go
3
+ from plotly_resampler import FigureResampler, FigureWidgetResampler
4
+
5
+
6
+
7
+ def plotly_plot(df, time_column, data_column, mittelwert):
8
+
9
+
10
+ if mittelwert > 0:
11
+ df[data_column] = df[data_column].rolling(mittelwert).mean()
12
+
13
+ fig = FigureWidgetResampler(go.Figure())
14
+
15
+ fig.add_trace(go.Scatter(x=df[time_column], y=df[data_column], mode='lines', name=data_column))
16
+
17
+ fig.update_layout(
18
+ xaxis=dict(
19
+ showline=True,
20
+ showgrid=True,
21
+ showticklabels=True,
22
+ linecolor='black',
23
+ linewidth=1.5,
24
+ ticks='outside',
25
+ tickfont=dict(
26
+ family='Arial',
27
+ size=14,
28
+ color='black'
29
+ ),
30
+ ),
31
+ yaxis=dict(
32
+ showgrid=True,
33
+ zeroline=True,
34
+ showline=True,
35
+ showticklabels=True,
36
+ linecolor='black',
37
+ linewidth=1.5,
38
+ ticks='outside',
39
+ tickfont=dict(
40
+ family='Arial',
41
+ size=14,
42
+ color='black'
43
+ ),
44
+ ),
45
+ autosize=True,
46
+ margin=dict(
47
+ autoexpand=True,
48
+ l=100,
49
+ r=20,
50
+ t=110,
51
+ ),
52
+ showlegend=True,
53
+ plot_bgcolor='white'
54
+ )
55
+
56
+ return fig
57
+
58
+