File size: 7,450 Bytes
fd0472a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  3 12:57:34 2023

@author: BorowyP
"""

import pandas as pd
import hvplot.pandas # Adds .hvplot and .interactive methods to Pandas dataframes

from hvplot.plotting import scatter_matrix

import panel as pn # Panel is a simple, flexible and enterprise-ready data app framework
import holoviews as hv
from holoviews.operation.timeseries import rolling, rolling_outlier_std


hv.extension('bokeh')
#pn.extension('tabulator')

pn.extension(sizing_mode="stretch_width")
#pd.set_option("precision", 0)

PALETTE = ["#ff6f69", "#ffcc5c", "#88d8b0", ]
import numpy as np
from bokeh.models.formatters import DatetimeTickFormatter
formatter = DatetimeTickFormatter(months='%b %Y') # wird in .hvplot benötigt für x-achse!



soil_temp = pd.read_csv('df_soil_temp.csv',header=0,sep=',')

soil_temp.index = pd.to_datetime(soil_temp['Date'], format='%Y.%m.%d %H:%M:%S')
soil_temp.index.names = ['Date']
soil_temp = soil_temp.drop(['Date'], axis=1)
soil_temp = soil_temp.drop(['Unnamed: 0'], axis=1)
soil_temp[soil_temp.columns[list(range(6))]] = soil_temp[soil_temp.columns[list(range(6))]].round(1) #RUNDEN auf 1 Kommastelle fuer bessere Perfomance!!!

soil_temp = soil_temp.rename(columns={'Temp05' : '50', 
                             'Temp10' : '100', 
                             'Temp20' : '200', 
                             'Temp30' : '300', 
                             'Temp50' : '500' , 
                             'Temp100' : '1000', 
                             'Standort' : 'Standort'})



Stndrt = pn.widgets.RadioButtonGroup(name='Standort', options=['Glienig', 'Groß Liebitz', 'Krausnick', 'Halbe', 'Spreeau', 'Hangelsberg'],button_type='success')

soiltempbtn = pn.widgets.ToggleGroup(
    name='soiltemperature',
    options=['50', '100', '200', '300', '500', '1000'], 
    value=['50'],
    button_type='success')

soil_date_slider = pn.widgets.DateRangeSlider(name='Date', start=soil_temp.index.min(), end=soil_temp.index.max())



soil_temp_i= soil_temp.interactive()

soil_temp_i = ( 
    soil_temp_i[
        (soil_temp_i.Standort == Stndrt) &
    (soil_temp_i.index >= soil_date_slider.param.value_start) &
    (soil_temp_i.index <= soil_date_slider.param.value_end)
                      ]
           )

soiltempplot = soil_temp_i.hvplot(x='Date',xlabel='Datum',title=Stndrt, y=soiltempbtn, color=PALETTE, line_width=1, xformatter=formatter, ylabel='Bodentemperatur [°C]')



def callback_temp(soil_temp_i):
    
    df = soil_temp_i
    
    monitor = pd.DataFrame({#'Standort' :  [Stndrt.value, Stndrt.value],
                           #'von' : soil_temp_i.index.min(),
                           #'bis' : soil_temp_i.index.max(),
                            'Mittelwert' : [df['50'].mean(), 
                                            df['100'].mean(), 
                                            df['200'].mean(),
                                            df['300'].mean(),
                                            df['500'].mean(),
                                            df['1000'].mean(),
                                           ] ,
                            'Median' : [df['50'].median(), 
                                            df['100'].median(), 
                                            df['200'].median(),
                                            df['300'].median(),
                                            df['500'].median(),
                                            df['1000'].median(),
                                       ] , 
        'Maximum' : [df['50'].max(), 
                                            df['100'].max(), 
                                            df['200'].max(),
                                            df['300'].max(),
                                            df['500'].max(),
                                            df['1000'].max()], 
        'Minimum' : [df['50'].min(), 
                                            df['100'].min(), 
                                            df['200'].min(),
                                            df['300'].min(),
                                            df['500'].min(),
                                            df['1000'].min()], 
        'Anzahl' : [df['50'].count(), 
                                            df['100'].count(), 
                                            df['200'].count(),
                                            df['300'].count(),
                                            df['500'].count(),
                                            df['1000'].count()]
                           
                           }, index=['50', 
                                     '100', 
                                     '200', 
                                     '300', 
                                     '500', 
                                     '1000', 
                                     
                                    ])
    monitor.index.name='Profiltiefe'
    
    #soiltemp_scatter = scatter_matrix(soil_temp, alpha=0.2) #Scattermatrix zum Vergleich der einzelnen Profiltiefen???
    
    soiltemp_scatter_df = soil_temp[soil_temp['Standort'] == Stndrt.value]#.iloc[df.index.min(): df.index.max()]
    
    soiltemp_scatter = scatter_matrix(soiltemp_scatter_df, alpha=0.2)
    
    scatter_headline = pn.pane.Markdown(f"## Scattermatrix **{Stndrt.value}**")
    
    scatter_discription = pn.pane.Markdown('scatter_matrix shows all the pairwise relationships between the columns of your data. Each non-diagonal entry plots the corresponding columns against another, while the diagonal plot shows the distribution of the data within each individual column.'
                                )
    
    monitor_gesamt = pd.DataFrame({'Standort' : [Stndrt.value],
                                  'von' : df.index.min(), 
                                  'bis' : df.index.max(),
                                  'Mittelwert' : df.mean(numeric_only=True).mean(),
                                  'Median' : df.median(numeric_only=True).median(),
                                   'Maximum' : df.max(numeric_only=True).max(),
                                   'Minimum' : df.min(numeric_only=True).min()
                                  }, index=['Gesamt'])
    
    
    
    
    
    return pn.Column(monitor_gesamt, monitor,scatter_headline, soiltemp_scatter, scatter_discription)

callback = soil_temp_i.pipe(callback_temp)

callback

hd_logo = pn.pane.PNG('HD_Logo.png', width=100)
lfe_logo = pn.pane.PNG('LFE_Logo.png', width=100)
fnr_logo = pn.pane.PNG('fnr_logo.png', width=100)

template = pn.template.FastListTemplate(
    title='Holzdeko Dashboard', 
    sidebar=[hd_logo,
             pn.pane.Markdown("## Einstellungen"),
             'Standort',Stndrt,
             lfe_logo,
             fnr_logo
             
             
            ], 
    main=[pn.pane.Markdown("## Bodentemperatur"),
          soiltempbtn,
          soil_date_slider,
          soiltempplot.panel(),
          callback.panel(),
          
          
          
          
                
          
    #accent_base_color="#88d8b0",
    #header_background="#88d8b0",
         ])




template.servable();

#print('fertig!')
# To launch this dashboard as a web server, we can simply run 
# cd C:\Users\BorowyP\Desktop\Dashboard-Preasi\soil_air\
# panel serve 20230307_soil_temp_docker.ipynb --autoreload