Skip to content

Commit dbcfe3d

Browse files
feat: use UTC for storage and IST for display in history
1 parent cc0a010 commit dbcfe3d

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

backend/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def log_prediction(data, prediction_label, confidence):
6565
INSERT INTO predictions (timestamp, heart_rate, spo2, sys_bp, dia_bp, temp, fall_detection, prediction_label, confidence)
6666
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
6767
''', (
68-
datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
68+
datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"),
6969
data.Heart_Rate,
7070
data.SpO2_Level,
7171
data.Systolic_BP,

backend/patient_history.db

0 Bytes
Binary file not shown.

frontend/pages/4_Patient_History.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22
import requests
33
import pandas as pd
44
import os
5+
from datetime import datetime, timedelta
56

67
st.set_page_config(page_title="Patient History", page_icon="🗄️", layout="wide")
78
API_URL = os.getenv("API_URL", "http://localhost:8000")
89
if "hf.space" in os.getenv("SPACE_ID", ""):
910
API_URL = "http://localhost:8000"
1011

1112
st.title("🗄️ Patient Prediction History")
12-
st.markdown("Live database of all patient predictions and vitals logged by the system. Auto-refreshes every 5 seconds.")
13+
st.markdown("Live database of all patient predictions and vitals logged by the system. Times shown in **IST (UTC+5:30)**.")
14+
15+
def convert_to_ist(utc_time_str):
16+
try:
17+
utc_dt = datetime.strptime(utc_time_str, "%Y-%m-%d %H:%M:%S")
18+
ist_dt = utc_dt + timedelta(hours=5, minutes=30)
19+
return ist_dt.strftime("%Y-%m-%d %H:%M:%S")
20+
except:
21+
return utc_time_str
1322

1423
DISEASE_COLORS = {
1524
"Healthy": "background-color: rgba(0, 204, 150, 0.15); color: #00cc96;",
@@ -43,6 +52,9 @@ def live_history_table():
4352
return
4453

4554
df = pd.DataFrame(history_data)
55+
if "timestamp" in df.columns:
56+
df["timestamp"] = df["timestamp"].apply(convert_to_ist)
57+
4658
cols = ['id', 'timestamp', 'prediction_label', 'confidence', 'heart_rate', 'spo2', 'sys_bp', 'dia_bp', 'temp', 'fall_detection']
4759
df = df[[c for c in cols if c in df.columns]]
4860
df.rename(columns=COLUMN_RENAME, inplace=True)

seed_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def seed_data():
3333
labels = ["Healthy", "At Risk"]
3434
fall_options = ["No Fall", "Fall Detected"]
3535

36-
now = datetime.now()
36+
now = datetime.utcnow()
3737

38-
print("Seeding 30 sample predictions...")
38+
print("Seeding 30 sample predictions (UTC)...")
3939
for i in range(30):
4040
timestamp = (now - timedelta(minutes=i*15)).strftime("%Y-%m-%d %H:%M:%S")
4141
hr = round(random.uniform(60, 110), 1)

0 commit comments

Comments
 (0)