diff --git a/Program/Webserver.py b/Program/Webserver.py index 57d9b57..47dfac8 100644 --- a/Program/Webserver.py +++ b/Program/Webserver.py @@ -49,9 +49,9 @@ def dashboard(): data = fetch_all_data()[:5] # Convert figure to JSON for rendering in template - graph_json = history_graph('Home') - - return render_template('index.html', data=data, temperature=None, graph_json=graph_json) + temp_graph_json = history_graph_temp() + HR_graph_json = history_graph_HR() + return render_template('index.html', data=data, temperature=None, temp_graph_json=temp_graph_json, HR_graph_json=HR_graph_json) #Route to display the sensor history @app.route('/history') diff --git a/Program/__pycache__/database.cpython-311.pyc b/Program/__pycache__/database.cpython-311.pyc index 6213e20..d1a0e1e 100644 Binary files a/Program/__pycache__/database.cpython-311.pyc and b/Program/__pycache__/database.cpython-311.pyc differ diff --git a/Program/__pycache__/mail.cpython-311.pyc b/Program/__pycache__/mail.cpython-311.pyc index 6187601..173d674 100644 Binary files a/Program/__pycache__/mail.cpython-311.pyc and b/Program/__pycache__/mail.cpython-311.pyc differ diff --git a/Program/database.py b/Program/database.py index 13e5cc2..5fb05f8 100644 --- a/Program/database.py +++ b/Program/database.py @@ -27,7 +27,7 @@ def create_database(db_name): Sensor TEXT, Timestamp TEXT, Temp INT, - HR INTEGER, + HR INT, Bat INT, FOREIGN KEY (Sensor) REFERENCES Sensors(Name))''') @@ -145,21 +145,62 @@ def print_email_settings(): # Close the connection conn.close() -def history_graph(sensor): +def history_graph_temp(): # Fetch sensor data - data = fetch_data_by_sensor(sensor) - df = pd.DataFrame(data, columns=['ID', 'Sensor', 'Timestamp', 'Temp', 'HR', 'Bat']) - # Create traces for temperature and HR - trace_temp = go.Scatter(x=df['Timestamp'], y=df['Temp'], mode='lines', name='Temperature') - trace_hr = go.Scatter(x=df['Timestamp'], y=df['HR'], mode='lines', name='Humidity Rate') + sensorList = fetch_all_sensor() + Trace = ['','' ,'' ] + i =0 + for mac, name in sensorList: + data = fetch_data_by_sensor(name) + #print(data) + df = pd.DataFrame(data, columns=['ID', 'Sensor', 'Timestamp', 'Temp', 'HR', 'Bat']) + # Create traces for temperature + Trace[i] = go.Scatter(x=df['Timestamp'], y=df['Temp'], mode='lines', name=name) + #print(Trace[i]) + i+=1 + #print(trace_temp) # Create layout - layout = go.Layout(title='Last Hour of History', + layout = go.Layout(title='Graph Temp history', xaxis=dict(title='Time'), - yaxis=dict(title='Value')) + yaxis=dict(title='Temperature in °C')) # Create figure - fig = go.Figure(data=[trace_temp, trace_hr], layout=layout) + fig = go.Figure(data=[Trace[0], Trace[1], Trace[2] ], layout=layout ) # Convert figure to JSON for rendering in template - graph_json = fig.to_json() \ No newline at end of file + graph_json = fig.to_json() + #print(graph_json) + return graph_json + + +def history_graph_HR(): + # Fetch sensor data + sensorList = fetch_all_sensor() + Trace = ['','',''] + i = 0 + + + for mac, name in sensorList: + + data = fetch_data_by_sensor(name) + df = pd.DataFrame(data, columns=['ID', 'Sensor', 'Timestamp', 'Temp', 'HR', 'Bat']) + # Create traces for temperature + Trace[i] = go.Scatter(x=df['Timestamp'], y=df['HR'], mode='lines', name=name) + #print(Trace[i]) + i+=1 + + + #print(trace_temp) + # Create layout + layout = go.Layout(title='Graph HR history', + xaxis=dict(title='Time'), + yaxis=dict(title='Humidity Rate in % ')) + + # Create figure + fig = go.Figure(data=[Trace[0], Trace[1], Trace[2] ], layout=layout ) + + # Convert figure to JSON for rendering in template + graph_json = fig.to_json() + #print(graph_json) + return graph_json \ No newline at end of file diff --git a/Program/templates/index.html b/Program/templates/index.html index 1e5bac1..0d6374e 100644 --- a/Program/templates/index.html +++ b/Program/templates/index.html @@ -3,6 +3,7 @@
+