Commit 10f21c74 authored by uouzl's avatar uouzl
Browse files

Replace Interactive Exploration.ipynb

parent b6f3bbea
%% Cell type:code id:de2f5927 tags:
%% Cell type:code id: tags:
``` python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import json
from pandas.io.json import json_normalize
import plotly.graph_objects as go
import os
from ipywidgets import interact, interact_manual
import ipywidgets as widgets
import datetime
from scipy.signal import savgol_filter
```
%% Cell type:code id:047d7eec tags:
%% Cell type:code id: tags:
``` python
file=os.getcwd()
file_m=file[0:(len(file)-9)]
file_dz='data\\preprocessed'#
file_data=file_m+file_dz
file_data
data_name=os.listdir(file_data)
path_preprocessed = r'..\..\data\preprocessed'
data_name=os.listdir(path_preprocessed)
```
%% Cell type:code id:e79fd35b tags:
%% Cell type:code id: tags:
``` python
def load_data(container: str,start,end):
file_number=file_m+file_dz+'\\'+container+'.txt'
file_number=path_preprocessed+'\\'+container+'.txt'
df = pd.read_csv(file_number)
df["time"]=pd.to_datetime(list(map(lambda st: str(st)[0:19],df["created_at"])))
data=df[df["time"]>=pd.to_datetime(start)]
data=data[data["time"]<=pd.to_datetime(end)]
data=data.reset_index()
data=data.set_index('time')
return data
```
%% Cell type:code id:75698570 tags:
%% Cell type:code id: tags:
``` python
def data_arith_mean(data_g, auflösung: str):
data_g=data_g.reset_index()
data=data_g.resample(auflösung,on='time').mean()
return data
```
%% Cell type:code id:9755dbcc tags:
%% Cell type:code id: tags:
``` python
def data_filter(data_g,sensor:str, intervallgröße: int, polynom: int):
data_g[sensor]=savgol_filter(data_g[sensor],intervallgröße,polynom)
return data_g
```
%% Cell type:code id:8c41551e tags:
%% Cell type:code id: tags:
``` python
sensor_list=['Height 1 (cm)', 'Height 2 (cm)','Height 3 (cm)','Height 4 (cm)','Voltage (mV)','Temperature (C)','Tilt (Degree)']
sensor_list=['Height (cm)','Voltage (mV)','Temperature (C)','Tilt (Degree)']
resolution=['1H','6H','12H','1D','7D','14D','1M','3M']
fig = go.FigureWidget()
fig.add_scatter()
@interact(Container=list(map(lambda st: str.replace(st, '.txt', ''), data_name)),Sensor=list(sensor_list),
Start_date=widgets.DatePicker(value=pd.to_datetime('2020-05-09')),
End_date=widgets.DatePicker(value=pd.to_datetime('2021-05-09')),
Auflösung_Ein_Aus=False, Auflösung=list(resolution),Filter=False,Intervallgröße=widgets.IntSlider(value=25,min=1,max=201,step=2,continuous_update=False),
Polynom=widgets.IntSlider(value=1,min=1,max=5,step=1,continuous_update=False),
Mittelwert=False,Median=False,Erwartungswert_plus_minus_Standardabweichung=False,Quantil_75=False,Quantil_25=False,
Varianz=False)
def update(Container='70b3d50070001704',Sensor='Height 1',Start_date=pd.to_datetime('2020-05-09'),End_date=pd.to_datetime('2021-05-09'),
Auflösung_Ein_Aus=False, Auflösung='1D',Filter=False,Intervallgröße=25,Polynom=1, Mittelwert=False,Median=False,Erwartungswert_plus_minus_Standardabweichung=False,
Quantil_75=False,Quantil_25=False,Varianz=False):
data=load_data(Container,Start_date,End_date)
if Auflösung_Ein_Aus == True:
data=data_arith_mean(data,Auflösung)
if Filter == True:
data=data_filter(data,Sensor,Intervallgröße,Polynom)
with fig.batch_update():
fig.data[0].x=data.index.tolist()
fig.data[0].y=data[Sensor].tolist()
fig.data[0].name=Sensor
fig.update_layout(title=str('Data Vizualisation Container:'+str(Container)),xaxis_title="Time",yaxis_title=Sensor)
if Mittelwert==True:
fig.add_scatter()
fig.data[1].x=data.index.tolist()
fig.data[1].y=np.ones(len(data.index.tolist()))*np.mean(data[Sensor].tolist())
fig.data[1].name="Arith. Mittel"
if Mittelwert==False:
fig.add_scatter()
fig.data[1].x=[]
fig.data[1].y=[]
if Median==True:
fig.add_scatter()
fig.data[2].x=data.index.tolist()
fig.data[2].y=np.ones(len(data.index.tolist()))*np.median(data[Sensor].tolist())
fig.data[2].name="Median"
if Median==False:
fig.add_scatter()
fig.data[2].x=[]
fig.data[2].y=[]
if Quantil_75==True:
fig.add_scatter()
fig.data[3].x=data.index.tolist()
fig.data[3].y=np.ones(len(data.index.tolist()))*np.quantile(data[Sensor].tolist(),0.75)
fig.data[3].name="75%-Quantil"
if Quantil_75==False:
fig.add_scatter()
fig.data[3].x=[]
fig.data[3].y=[]
if Quantil_25==True:
fig.add_scatter()
fig.data[4].x=data.index.tolist()
fig.data[4].y=np.ones(len(data.index.tolist()))*np.quantile(data[Sensor].tolist(),0.25)
fig.data[4].name="25%-Quantil"
if Quantil_25==False:
fig.add_scatter()
fig.data[4].x=[]
fig.data[4].y=[]
if Erwartungswert_plus_minus_Standardabweichung==True:
fig.add_scatter()
fig.data[5].x=data.index.tolist()
fig.data[5].y=np.ones(len(data.index.tolist()))*np.mean(data[Sensor].tolist())+np.ones(len(data.index.tolist()))*np.sqrt(np.var(data[Sensor].tolist()))
fig.data[5].name="E+stdev"
fig.add_scatter()
fig.data[6].x=data.created_at.tolist()
fig.data[6].y=np.ones(len(data.index.tolist()))*np.mean(data[Sensor].tolist())-np.ones(len(data.index.tolist()))*np.sqrt(np.var(data[Sensor].tolist()))
fig.data[6].name="E-stdev"
if Erwartungswert_plus_minus_Standardabweichung==False:
fig.add_scatter()
fig.data[5].x=[]
fig.data[5].y=[]
fig.add_scatter()
fig.data[6].x=[]
fig.data[6].y=[]
if Varianz==True:
fig.add_scatter()
fig.data[7].x=data.index.tolist()
fig.data[7].y=np.ones(len(data.index.tolist()))*np.var(data["Sensor"].tolist())
fig.data[7].name="Variance"
if Varianz==False:
fig.add_scatter()
fig.data[7].x=[]
fig.data[7].y=[]
fig
```
%%%% Output: display_data
%%%% Output: display_data
%% Cell type:code id:73e1b6b5 tags:
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id:58a9607d tags:
%% Cell type:code id: tags:
``` python
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment