Dateien nach "Code" hochladen
commit
89cffee401
|
@ -0,0 +1,113 @@
|
|||
import pandas as pd
|
||||
from dash import Dash, html, dash_table, dcc, callback
|
||||
from dash.dependencies import Input, Output
|
||||
import plotly.express as px
|
||||
from datetime import datetime
|
||||
import plotly.graph_objects as go
|
||||
|
||||
df = pd.read_csv('Data.csv')
|
||||
df_reversed = df.iloc[::-1]
|
||||
|
||||
pressure = df['Barometric Pressure'].iloc[-1]
|
||||
humidity = df['Humidity'].iloc[-1]
|
||||
|
||||
|
||||
app = Dash(__name__)
|
||||
|
||||
app.layout = html.Div([
|
||||
html.H1('Wetter', style={'textAlign': 'center'}),
|
||||
|
||||
html.Div([
|
||||
dcc.Graph(id='temperature-indicator'),
|
||||
dcc.Graph(id='pressure-indicator'),
|
||||
dcc.Graph(id='humidity-indicator')
|
||||
], style={'display': 'flex'}),
|
||||
dcc.RadioItems([{'label': 'Temperature', 'value': 'Temperature'},
|
||||
{'label': 'Barometric Pressure', 'value': 'Barometric Pressure'},
|
||||
{'label': 'Humidity', 'value': 'Humidity'}],
|
||||
inline=True,
|
||||
id='radioitem',
|
||||
value='Barometric Pressure'),
|
||||
dcc.Graph(id='Pressure'),
|
||||
dash_table.DataTable(
|
||||
id='wetter',
|
||||
data=df_reversed.to_dict('records'),
|
||||
columns=[{'name': i, 'id': i} for i in df.columns],
|
||||
sort_mode='single',
|
||||
sort_action='native',
|
||||
style_cell={'textAlign': 'center'}),
|
||||
dcc.Interval(
|
||||
id='update',
|
||||
interval=10000,
|
||||
n_intervals=0)
|
||||
])
|
||||
|
||||
|
||||
@callback(Output('temperature-indicator', 'figure'),
|
||||
Input('update', 'n_intervals'))
|
||||
def temp_update(n):
|
||||
df = pd.read_csv('Data.csv')
|
||||
temperature = df['Temperature'].iloc[-1]
|
||||
figure = go.Figure(
|
||||
go.Indicator(
|
||||
mode="gauge+number",
|
||||
value=temperature,
|
||||
title={'text': "Temperature (°C)"},
|
||||
gauge={'axis': {'range': [-20, 40]},
|
||||
'bar': {'color': 'red'}}))
|
||||
return figure
|
||||
|
||||
|
||||
@callback(Output('pressure-indicator', 'figure'),
|
||||
Input('update', 'n_intervals'))
|
||||
def pressure_update(n):
|
||||
df = pd.read_csv('Data.csv')
|
||||
pressure = df['Barometric Pressure'].iloc[-1]
|
||||
figure = go.Figure(
|
||||
go.Indicator(
|
||||
mode="gauge+number",
|
||||
value=pressure,
|
||||
number={'valueformat': '.2f'},
|
||||
title={'text': "Barometric Pressure"},
|
||||
gauge={'axis': {'range': [500, 1300]}}))
|
||||
return figure
|
||||
|
||||
|
||||
@callback(Output('humidity-indicator', 'figure'),
|
||||
Input('update', 'n_intervals'))
|
||||
def temp_update(n):
|
||||
df = pd.read_csv('Data.csv')
|
||||
humidity = df['Humidity'].iloc[-1]
|
||||
figure = go.Figure(
|
||||
go.Indicator(
|
||||
mode="gauge+number",
|
||||
value=humidity,
|
||||
title={'text': "Humidity"},
|
||||
gauge={'axis': {'range': [0, 100]},
|
||||
'bar': {'color': 'blue'}}))
|
||||
return figure
|
||||
|
||||
|
||||
@callback(Output('wetter', 'data'),
|
||||
Input('update', 'n_intervals'))
|
||||
def get_update(n):
|
||||
df = pd.read_csv('Data.csv')
|
||||
df_reversed = df.iloc[::-1]
|
||||
return df_reversed.to_dict('records')
|
||||
|
||||
|
||||
@callback(Output('Pressure', 'figure'),
|
||||
Input('update', 'n_intervals'),
|
||||
Input('radioitem', 'value'))
|
||||
def update_graph(n, x):
|
||||
df = pd.read_csv('Data.csv')
|
||||
today = datetime.today().date()
|
||||
df_filtered = df.tail(60).copy()
|
||||
df_filtered['Date'] = pd.to_datetime(df_filtered['Date'], dayfirst=True)
|
||||
df_filtered = df_filtered[df_filtered['Date'].dt.date == today]
|
||||
fig = px.line(df_filtered, x='Time', y=x)
|
||||
return fig
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run_server(debug=True)
|
|
@ -0,0 +1,109 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "initial_id",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2024-01-15T16:21:32.634426800Z",
|
||||
"start_time": "2024-01-15T15:30:44.375000700Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": " Date Time Temperature Barometric Pressure Humidity\n0 23-12-2023 10:31:44 9.14 962.54 61.900\n1 23-12-2023 10:33:26 9.19 962.56 62.583\n2 23-12-2023 10:34:26 9.14 962.59 61.835\n3 23-12-2023 10:35:26 8.95 962.61 62.270\n4 23-12-2023 10:36:26 8.91 962.67 61.414\n.. ... ... ... ... ...\n0 15-01-2024 17:16:34 1.18 951.71 79.291\n0 15-01-2024 17:17:34 1.19 951.74 78.544\n0 15-01-2024 17:18:34 1.22 951.72 78.812\n0 15-01-2024 17:19:33 1.23 951.74 79.127\n0 15-01-2024 17:20:33 1.23 951.65 78.431\n\n[530 rows x 5 columns]",
|
||||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Date</th>\n <th>Time</th>\n <th>Temperature</th>\n <th>Barometric Pressure</th>\n <th>Humidity</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>23-12-2023</td>\n <td>10:31:44</td>\n <td>9.14</td>\n <td>962.54</td>\n <td>61.900</td>\n </tr>\n <tr>\n <th>1</th>\n <td>23-12-2023</td>\n <td>10:33:26</td>\n <td>9.19</td>\n <td>962.56</td>\n <td>62.583</td>\n </tr>\n <tr>\n <th>2</th>\n <td>23-12-2023</td>\n <td>10:34:26</td>\n <td>9.14</td>\n <td>962.59</td>\n <td>61.835</td>\n </tr>\n <tr>\n <th>3</th>\n <td>23-12-2023</td>\n <td>10:35:26</td>\n <td>8.95</td>\n <td>962.61</td>\n <td>62.270</td>\n </tr>\n <tr>\n <th>4</th>\n <td>23-12-2023</td>\n <td>10:36:26</td>\n <td>8.91</td>\n <td>962.67</td>\n <td>61.414</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>0</th>\n <td>15-01-2024</td>\n <td>17:16:34</td>\n <td>1.18</td>\n <td>951.71</td>\n <td>79.291</td>\n </tr>\n <tr>\n <th>0</th>\n <td>15-01-2024</td>\n <td>17:17:34</td>\n <td>1.19</td>\n <td>951.74</td>\n <td>78.544</td>\n </tr>\n <tr>\n <th>0</th>\n <td>15-01-2024</td>\n <td>17:18:34</td>\n <td>1.22</td>\n <td>951.72</td>\n <td>78.812</td>\n </tr>\n <tr>\n <th>0</th>\n <td>15-01-2024</td>\n <td>17:19:33</td>\n <td>1.23</td>\n <td>951.74</td>\n <td>79.127</td>\n </tr>\n <tr>\n <th>0</th>\n <td>15-01-2024</td>\n <td>17:20:33</td>\n <td>1.23</td>\n <td>951.65</td>\n <td>78.431</td>\n </tr>\n </tbody>\n</table>\n<p>530 rows × 5 columns</p>\n</div>"
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import paramiko\n",
|
||||
"import pandas as pd\n",
|
||||
"from datetime import datetime\n",
|
||||
"import time\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def get_data(hostname, port, username, password, script_path):\n",
|
||||
" try:\n",
|
||||
" client = paramiko.SSHClient()\n",
|
||||
" client.set_missing_host_key_policy(paramiko.AutoAddPolicy())\n",
|
||||
" client.connect(hostname, port, username, password)\n",
|
||||
"\n",
|
||||
" stdin, stdout, stderr = client.exec_command(f'python3 {script_path}')\n",
|
||||
" output = stdout.read().decode('utf-8').strip()\n",
|
||||
"\n",
|
||||
" client.close()\n",
|
||||
"\n",
|
||||
" output_pairs = output.split(',')\n",
|
||||
"\n",
|
||||
" variable_values = [float(pair.split('=')[1]) for pair in output_pairs]\n",
|
||||
"\n",
|
||||
" variable1, variable2, variable3 = variable_values\n",
|
||||
"\n",
|
||||
" return variable1, variable2, variable3\n",
|
||||
"\n",
|
||||
" except Exception as e:\n",
|
||||
" print(f\"An error occurred: {e}\")\n",
|
||||
" return None, None, None\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"df = pd.read_csv('Data.csv')\n",
|
||||
"while True:\n",
|
||||
" try:\n",
|
||||
" temp, pressure, humidity = get_data('192.168.1.123', 22, 'hoehenmichae', 'pi',\n",
|
||||
" '/home/hoehenmichae/Documents/project/code.py')\n",
|
||||
" time_1 = datetime.now().time().replace(microsecond=0)\n",
|
||||
" date_1 = datetime.today().date().strftime('%d-%m-%Y')\n",
|
||||
" df_temp = pd.DataFrame(\n",
|
||||
" {'Date': [date_1], 'Time': [time_1], 'Temperature': [temp], 'Barometric Pressure': [pressure],\n",
|
||||
" 'Humidity': [humidity]})\n",
|
||||
" df = pd.concat([df, df_temp])\n",
|
||||
" df.to_csv('Data.csv', index=False)\n",
|
||||
" time.sleep(59)\n",
|
||||
"\n",
|
||||
" except KeyboardInterrupt:\n",
|
||||
" break\n",
|
||||
"\n",
|
||||
"df.to_csv('Data.csv', index=False)\n",
|
||||
"df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"outputs": [],
|
||||
"source": [],
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"id": "33ba79e654b7b277"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
Loading…
Reference in New Issue