-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefined_value.py
More file actions
41 lines (36 loc) · 1.28 KB
/
refined_value.py
File metadata and controls
41 lines (36 loc) · 1.28 KB
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
import mysql.connector
class RefinedUploader:
def __init__(self):
self.config = {
'host': 'localhost',
'user': 'root',
'password': 'iamrahul', # Update if needed
'database': 'health_project'
}
self.conn = mysql.connector.connect(**self.config)
self.cursor = self.conn.cursor()
def upload_to_db(self, bpm, spo2, metrics):
"""
Takes raw values and the dictionary from health_metrics.py
"""
try:
sql = """INSERT INTO refined_health_data
(bpm, spo2, glucose, hrv, pi, rr, status)
VALUES (%s, %s, %s, %s, %s, %s, %s)"""
values = (
bpm,
spo2,
metrics['glucose'],
metrics['hrv'],
metrics['pi'],
metrics['respiratory_rate'],
metrics['status']
)
self.cursor.execute(sql, values)
self.conn.commit()
print(">>> Successfully saved refined data to MySQL.")
except Exception as e:
print(f"Upload Error: {e}")
def close(self):
self.cursor.close()
self.conn.close()