Commit f581c9d7 authored by tills's avatar tills
Browse files

more data in collection df

parent 06908c38
70b3d500700016dE
70b3d500700016dF
70b3d500700016E6
70b3d500700016EB
70b3d500700016F2
70b3d500700016F4
70b3d500700016F7
70b3d500700016FC
70b3d50070001700
70b3d50070001701
70b3d50070001708
70b3d5007000170F
70b3d50070001712
70b3d50070001713
70b3d50070001714
70b3d50070001715
70b3d5007000171A
70b3d5007000171E
70b3d5007000171F
70b3d50070001722
70b3d50070001727
70b3d5007000172B
70b3d5007000172C
70b3d5007000172D
70b3d50070001731
70b3d50070001733
70b3d50070001736
70b3d5007000173A
70b3d50070001740
70b3d50070001743
70b3d5007000174D
70b3d50070001750
70b3d50070001759
70b3d5007000175A
70b3d5007000175E
70b3d50070001764
70b3d50070001766
70b3d50070001770
70b3d50070001774
70b3d50070001779
70b3d5007000177C
70b3d50070001780
70b3d50070001782
70b3d50070001786
70b3d50070001789
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
%% Cell type:code id:cd589004 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
```
%% Cell type:code id:4d82190b tags:
%% Cell type:code id: tags:
``` python
```
file=os.getcwd()
file_m=file[0:(len(file)-9)]
file_dz='data\\raw'
file_data=file_m+file_dz
file_data
data_name=os.listdir(file_data)
```
%% Cell type:code id:6e8c589f tags:
%% Cell type:code id: tags:
``` python
```
def load_data(container: str,start,end):
file_number=file_m+file_dz+'\\'+container+'.txt'
df = pd.read_json(file_number, lines=True)
raw_data = pd.DataFrame(df[1][0])
raw_data["time"]=pd.to_datetime(list(map(lambda st: str(st)[0:10],raw_data["created_at"])))
raw_data_z1=raw_data[raw_data["time"]>=pd.to_datetime(start)]
raw_data_z2=raw_data_z1[raw_data_z1["time"]<=pd.to_datetime(end)]
return raw_data_z2
```
%% Cell type:code id:733b95fb tags:
%% Cell type:code id: tags:
``` python
```
def dec_data(data,sensor: str):
df_decoded_data = pd.json_normalize(data.decoded_data)
if sensor=='Height 1 (cm)':
df_decoded_data["Height 1 (cm)"] = df_decoded_data["sensor_data.Height 1"].str.replace("cm","").astype(int)
elif sensor=='Height 2 (cm)':
df_decoded_data["Height 2 (cm)"] = df_decoded_data["sensor_data.Height 2"].str.replace("cm","").astype(int)
elif sensor=='Height 3 (cm)':
df_decoded_data["Height 3 (cm)"] = df_decoded_data["sensor_data.Height 3"].str.replace("cm","").astype(int)
elif sensor=='Height 4 (cm)':
df_decoded_data["Height 4 (cm)"] = df_decoded_data["sensor_data.Height 4"].str.replace("cm","").astype(int)
elif sensor=='Voltage (mV)':
df_decoded_data["Voltage (mV)"] = df_decoded_data["sensor_data.Voltage"].str.replace("mV","").astype(int)
elif sensor=='Temperature (C)':
df_decoded_data["Temperature (C)"] = df_decoded_data["sensor_data.Temperature"].str.replace("C","").astype(int)
elif sensor=='Tilt (Degree)':
df_decoded_data["Tilt (Degree)"] = df_decoded_data["sensor_data.Tilt"].str.replace("Degree","").astype(int)
return df_decoded_data
```
%% Cell type:code id:d9cd2aab 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)']
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-08')),
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-08'),
Mittelwert=False,Median=False,Erwartungswert_plus_minus_Standardabweichung=False,
Quantil_75=False,Quantil_25=False,Varianz=False):
raw_data=load_data(Container,Start_date,End_date)
decoded_data=dec_data(raw_data,Sensor)
with fig.batch_update():
fig.data[0].x=raw_data.created_at.tolist()
fig.data[0].y=decoded_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=raw_data.created_at.tolist()
fig.data[1].y=np.ones(len(raw_data.created_at.tolist()))*np.mean(decoded_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=raw_data.created_at.tolist()
fig.data[2].y=np.ones(len(raw_data.created_at.tolist()))*np.median(decoded_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=raw_data.created_at.tolist()
fig.data[3].y=np.ones(len(raw_data.created_at.tolist()))*np.quantile(decoded_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=raw_data.created_at.tolist()
fig.data[4].y=np.ones(len(raw_data.created_at.tolist()))*np.quantile(decoded_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=raw_data.created_at.tolist()
fig.data[5].y=np.ones(len(raw_data.created_at.tolist()))*np.mean(decoded_data[Sensor].tolist())+np.ones(len(raw_data.created_at.tolist()))*np.sqrt(np.var(decoded_data[Sensor].tolist()))
fig.data[5].name="E+stdev"
fig.add_scatter()
fig.data[6].x=raw_data.created_at.tolist()
fig.data[6].y=np.ones(len(raw_data.created_at.tolist()))*np.mean(decoded_data[Sensor].tolist())-np.ones(len(raw_data.created_at.tolist()))*np.sqrt(np.var(decoded_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=raw_data.created_at.tolist()
fig.data[7].y=np.ones(len(raw_data.created_at.tolist()))*np.var(decoded_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:4f8b1bcf tags:
%% Cell type:code id: tags:
``` python
```
raw_data
```
%%%% Output: error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-17-6b6e5e7f1078> in <module>
<ipython-input-6-6b6e5e7f1078> in <module>
----> 1 raw_data
NameError: name 'raw_data' is not defined
%% Cell type:code id:5e5d7e8c tags:
%% Cell type:code id: tags:
``` python
```
```
......
This diff is collapsed.
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