Spaces:
Running
Running
File size: 6,836 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 |
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 3 12:12:35 2023
@author: BorowyP
"""
import pandas as pd
import numpy as np
import hvplot.pandas # Adds .hvplot and .interactive methods to Pandas dataframes
import panel as pn # Panel is a simple, flexible and enterprise-ready data app framework
import holoviews as hv
pn.extension(sizing_mode="stretch_width")
PALETTE = ["#ff6f69", "#ffcc5c", "#88d8b0", ]
from bokeh.models.formatters import DatetimeTickFormatter
formatter = DatetimeTickFormatter(months='%b %Y') # wird in .hvplot benötigt für x-achse!
air_hum = pd.read_csv(r'df_air_hum.csv', sep=',',
header=0,
#skiprows=[1],
decimal=',',
na_values=('#-INF', '#NAN'))
air_hum.index = pd.to_datetime(air_hum['Date'], format='%Y.%m.%d %H:%M:%S')
#air_hum.index.names = ['Date']
air_hum = air_hum.drop(['Date'], axis=1)
air_hum['hum'] = air_hum['hum'].astype(np.float64, copy=True, errors='ignore')
air_hum = air_hum.round(1)
air_date_slider = pn.widgets.DateRangeSlider(name='Date', start=air_hum.index.min(), end=air_hum.index.max())
Stndrt = pn.widgets.RadioButtonGroup(name='Standort', options=['Glienig', 'Groß Liebitz', 'Krausnick', 'Halbe', 'Spreeau', 'Hangelsberg'],button_type='success')
air_date_slider
air_hum_inter = air_hum.interactive()
air_hum_inter = (
air_hum_inter[
(air_hum_inter.Standort == Stndrt) &
(air_hum_inter.index >= air_date_slider.param.value_start) &
(air_hum_inter.index <= air_date_slider.param.value_end)
])
def lin_reg_hum(dfx,dfy, date):
# Formel für regres-gerade: y= alpha + b * x
# https://www.crashkurs-statistik.de/einfache-lineare-regression/
lin_df = pd.DataFrame({'Date' : date,
'Luftfeuchte' : dfy,
'x-x.mean' : dfx-dfx.mean(),
'y-y.mean' : dfy-dfy.mean(),
'(x-x.mean) * (y-y.mean)': (dfx-dfx.mean()) * (dfy-dfy.mean()),
'(x-x.mean)²' : (dfx-dfx.mean()) * (dfx-dfx.mean())
})
b = lin_df['(x-x.mean) * (y-y.mean)'].sum()/ lin_df['(x-x.mean)²'].sum()
alpha = dfy.mean() - b * dfx.mean()
lin_df['Lineare Regression'] = round(alpha + b * dfx,2)
lin_plot = lin_df.hvplot(x='Date',
xlabel='Datum',
title=Stndrt,
y=['Luftfeuchte', 'Lineare Regression'],
ylabel='rel Luftfeuchte [%]',
color=PALETTE,
line_width=0.5,
xformatter=formatter)
SQE = ((lin_df['Lineare Regression']-dfy.mean())*(lin_df['Lineare Regression']-dfy.mean())).sum()
SQT = (lin_df['y-y.mean'] * lin_df['y-y.mean']).sum()
R_Wert = round(SQE/SQT,2)
mean = round(dfy.mean(),2)
median = dfy.median()
maxm = dfy.max()
minm = dfy.min()
anz = dfy.count()
monitor_df = pd.DataFrame({'Standort' : [Stndrt.value],
'von' : [air_date_slider.value[0]],
'bis' : [air_date_slider.value[1]],
'Mittelwert' : [mean],
'Median' : [median],
'Maximum' : [maxm],
'Minimum' : [minm],
'Anzahl' : [anz],
'R²' : [R_Wert]
})
return pn.Column(lin_plot, monitor_df)
def callback_hum(air_hum_inter):
y = air_hum_inter.hum
x = air_hum_inter['Unnamed: 0']
return pn.Column(lin_reg_hum(x,y, air_hum_inter.index))
airhumplot = air_hum_inter.pipe(callback_hum)
airhumplot
hum_glienig = pd.DataFrame({'Glienig': air_hum.loc[air_hum['Standort'] == 'Glienig']['hum']},
index = air_hum.loc[air_hum['Standort'] == 'Glienig'].index)
hum_grlieb = pd.DataFrame({'Groß Liebitz': air_hum.loc[air_hum['Standort'] == 'Groß Liebitz']['hum']},
index = air_hum.loc[air_hum['Standort'] == 'Groß Liebitz'].index)
hum_halbe = pd.DataFrame({'Halbe' : air_hum.loc[air_hum['Standort'] == 'Halbe']['hum']},
index= air_hum.loc[air_hum['Standort'] == 'Halbe'].index)
hum_hberg = pd.DataFrame({'Hangelsberg' : air_hum.loc[air_hum['Standort'] == 'Hangelsberg']['hum']},
index= air_hum.loc[air_hum['Standort'] == 'Hangelsberg'].index)
hum_kraunick = pd.DataFrame({'Krausnick' : air_hum.loc[air_hum['Standort'] == 'Krausnick']['hum']},
index= air_hum.loc[air_hum['Standort'] == 'Krausnick'].index)
hum_spreeau = pd.DataFrame({'Spreeau' : air_hum.loc[air_hum['Standort'] == 'Spreeau']['hum']},
index= air_hum.loc[air_hum['Standort'] == 'Spreeau'].index)
air_hum_hist = pd.concat([hum_glienig,hum_grlieb,hum_halbe,hum_hberg,hum_kraunick,hum_spreeau])
dfi_hum = air_hum_hist.interactive()
filtered = dfi_hum[
(dfi_hum.index >= air_date_slider.param.value_start) &
(dfi_hum.index <= air_date_slider.param.value_end)]
plot_air_humhist = filtered.hvplot(y=['Glienig',
'Groß Liebitz',
'Halbe',
'Hangelsberg',
'Krausnick',
'Spreeau'],
kind='hist',
responsive=True,
min_height=300,
xlabel='rel Luftfeuchte[%]',
alpha=0.5)
plot_air_humhist
hd_logo = pn.pane.PNG('HD_Logo.png', width=100)
hd_logo
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("## Relative Luftfeuchte"),
air_date_slider,
airhumplot.panel(),
plot_air_humhist # LUFT
#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 20230303_air_hum_docker.ipynb --autoreload |