Spaces:
Running
Running
File size: 6,942 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 193 194 195 196 197 198 199 200 201 |
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 24 15:24:06 2023
@author: BorowyP
"""
import pandas as pd
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
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", ]
ACCENT_BASE_COLOR = PALETTE[0]
#import time
#start = time.time()
#print('load data')
import numpy as np
from math import pi
from bokeh.palettes import Category20c, Category20
from bokeh.plotting import figure
from bokeh.transform import cumsum
from bokeh.layouts import row
from bokeh.models.formatters import DatetimeTickFormatter
formatter = DatetimeTickFormatter(months='%b %Y') # wird in .hvplot benötigt für x-achse!
air_temp = pd.read_csv(r'df_air_temp.csv', sep=',',
header=0,
#skiprows=[1],
decimal=',',
#dtype={'temp': np.float64},
na_values=('#-INF', '#NAN'))
air_temp.index = pd.to_datetime(air_temp['Date'], format='%Y.%m.%d %H:%M:%S')
air_temp = air_temp.drop(['Date'], axis=1)
air_temp['temp'] = air_temp['temp'].astype(np.float64, copy=True, errors='ignore')
air_temp = air_temp.round(1)
air_date_slider = pn.widgets.DateRangeSlider(name='Date', start=air_temp.index.min(), end=air_temp.index.max())
Stndrt = pn.widgets.RadioButtonGroup(name='Standort', options=['Glienig', 'Groß Liebitz', 'Krausnick', 'Halbe', 'Spreeau', 'Hangelsberg'],button_type='success')
air_temp_inter = air_temp.interactive()
air_temp_inter = (
air_temp_inter[
(air_temp_inter.Standort == Stndrt) &
(air_temp_inter.index >= air_date_slider.param.value_start) &
(air_temp_inter.index <= air_date_slider.param.value_end)
])
def lin_reg(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,
'Temperatur' : 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=['Temperatur', 'Lineare Regression'],
ylabel='Lufttemperatur [°C]',
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(air_temp_inter):
y = air_temp_inter.temp
x = air_temp_inter['Unnamed: 0']
return pn.Column(lin_reg(x,y, air_temp_inter.index))
airtempplot = air_temp_inter.pipe(callback)
temp_glienig = pd.DataFrame({'Glienig': air_temp.loc[air_temp['Standort'] == 'Glienig']['temp']},
index = air_temp.loc[air_temp['Standort'] == 'Glienig'].index)
temp_grlieb = pd.DataFrame({'Groß Liebitz': air_temp.loc[air_temp['Standort'] == 'Groß Liebitz']['temp']},
index = air_temp.loc[air_temp['Standort'] == 'Groß Liebitz'].index)
temp_halbe = pd.DataFrame({'Halbe' : air_temp.loc[air_temp['Standort'] == 'Halbe']['temp']},
index= air_temp.loc[air_temp['Standort'] == 'Halbe'].index)
temp_hberg = pd.DataFrame({'Hangelsberg' : air_temp.loc[air_temp['Standort'] == 'Hangelsberg']['temp']},
index= air_temp.loc[air_temp['Standort'] == 'Hangelsberg'].index)
temp_krausnick = pd.DataFrame({'Krausnick' : air_temp.loc[air_temp['Standort'] == 'Krausnick']['temp']},
index= air_temp.loc[air_temp['Standort'] == 'Krausnick'].index)
temp_spreeau = pd.DataFrame({'Spreeau' : air_temp.loc[air_temp['Standort'] == 'Spreeau']['temp']},
index= air_temp.loc[air_temp['Standort'] == 'Spreeau'].index)
air_temp_hist = pd.concat([temp_glienig,temp_grlieb,temp_halbe,temp_hberg,temp_krausnick,temp_spreeau])
dfi_temp = air_temp_hist.interactive()
filtered = dfi_temp[
(dfi_temp.index >= air_date_slider.param.value_start) &
(dfi_temp.index <= air_date_slider.param.value_end)]
plot_air_temphist = filtered.hvplot(y=['Glienig',
'Groß Liebitz',
'Halbe',
'Hangelsberg',
'Krausnick',
'Spreeau'], kind='hist', responsive=True, min_height=300, xlabel='Lufttemperatur', alpha=0.5)
import os
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("## Luft Temperaturdaten"),
air_date_slider,
airtempplot.panel(),
plot_air_temphist,
#accent_base_color="#88d8b0",
#header_background="#88d8b0",
])
template.servable();
|