Spaces:
Build error
Build error
| # -*- coding: utf-8 -*- | |
| """ | |
| Created on Tue Mar 21 11:06:37 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) | |
| sidebar_link_list = pn.pane.HTML( | |
| ''' | |
| <div class="bk" style="position: relative; display: block; left: 0px; top: 0px; width: 314px; height: 522px; margin: 0px;"><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 5px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://paulborowy-20230303-multiple-panel.hf.space" target="_blank">Startseite</a></p></div></div><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 63px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://holzdeko-lufttemperatur.hf.space" target="_blank">Lufttemperatur</a></p></div></div><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 121px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://holzdeko-luftfeuchte.hf.space" target="_blank">Luftfeuchte</a></p></div></div><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 179px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://holzdeko-niederschlag.hf.space" target="_blank">Niederschlag</a></p></div></div><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 237px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://holzdeko-bodentemperatur.hf.space" target="_blank">Bodentemperatur</a></p></div></div><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 295px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://holzdeko-bodenfeuchte.hf.space" target="_blank">Bodenfeuchte</a></p></div></div><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 353px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://holzdeko-hemisfere.hf.space" target="_blank">Hemisfere</a></p></div></div><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 411px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://paulborowy-holzdeko.hf.space/Stahlrahmen" target="_blank">Streufall</a></p></div></div><div class="bk markdown" style="position: absolute; display: block; left: 5px; top: 469px; width: 304px; height: 48px;"><div class="bk bk-clearfix" style="display: inline-block; width: 100%;"><p><a href="https://holzdeko-masseverlust.hf.space" target="_blank">Masseverlust</a></p></div></div></div> | |
| ''') | |
| sidebar_menu = pn.Column(hd_logo, | |
| pn.pane.Markdown("## Menu"), | |
| sidebar_link_list, | |
| lfe_logo, | |
| fnr_logo ) | |
| standort_label = pn.pane.Markdown('### Standort') | |
| standort_col = pn.Column(standort_label, Stndrt) | |
| template = pn.template.FastListTemplate( | |
| title='Holzdeko Luftfeuchte', | |
| sidebar=[sidebar_menu | |
| ], | |
| main=[pn.pane.Markdown("## Relative Luftfeuchte"), | |
| standort_col, | |
| air_date_slider, | |
| airhumplot.panel(), | |
| plot_air_humhist # LUFT | |
| ] | |
| ,accent_base_color="#00613a", | |
| header_background="#00613a", | |
| ) | |
| 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 | |