Skip to content

Commit 330ab6b

Browse files
nikolay-eclaude
andcommitted
Add HRV and Energy models to database schema
- Add HRV model for heart rate variability tracking with median-based aggregation - Add Energy model for active and basal calorie tracking - Update User model with new relationships - Add temporary import/extraction scripts to .gitignore to keep codebase clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e27db71 commit 330ab6b

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ secrets.json
1616
response.json
1717
directory_tree.yaml
1818

19+
# HealthKit import/extraction utilities (temporary scripts)
20+
extract_*_xml.py
21+
import_healthkit_*_csv.py
22+
import_*_csv.py
23+
import_healthkit_xml.py
24+
analyze_xml_schema.py
25+
analyze_correlations.py
26+
batch_import_*.sh
27+
1928
# Generated reports and dashboards
2029
index.html
2130
*.html

models.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class User(Base):
5151
sleep_data = relationship(
5252
"Sleep", back_populates="user", cascade="all, delete-orphan"
5353
)
54-
hrv_data = relationship("HRV", back_populates="user", cascade="all, delete-orphan")
5554
weight_data = relationship(
5655
"Weight", back_populates="user", cascade="all, delete-orphan"
5756
)
@@ -61,6 +60,10 @@ class User(Base):
6160
stress_data = relationship(
6261
"Stress", back_populates="user", cascade="all, delete-orphan"
6362
)
63+
hrv_data = relationship("HRV", back_populates="user", cascade="all, delete-orphan")
64+
energy_data = relationship(
65+
"Energy", back_populates="user", cascade="all, delete-orphan"
66+
)
6467
steps = relationship("Steps", back_populates="user", cascade="all, delete-orphan")
6568
workout_sets = relationship(
6669
"WorkoutSet", back_populates="user", cascade="all, delete-orphan"
@@ -157,7 +160,7 @@ def __repr__(self):
157160

158161

159162
class HRV(Base):
160-
"""Heart Rate Variability data from Garmin Connect."""
163+
"""Heart Rate Variability data from Garmin Connect and Apple Watch."""
161164

162165
__tablename__ = "hrv"
163166

@@ -255,6 +258,29 @@ def __repr__(self):
255258
)
256259

257260

261+
class Energy(Base):
262+
"""Daily energy expenditure data from Apple Watch and Garmin."""
263+
264+
__tablename__ = "energy"
265+
266+
id = Column(Integer, primary_key=True)
267+
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
268+
date = Column(Date, nullable=False, index=True)
269+
active_energy = Column(Float) # Active calories burned (kcal)
270+
basal_energy = Column(Float) # Basal/resting calories burned (kcal)
271+
created_at = Column(DateTime, default=datetime.datetime.utcnow)
272+
273+
# Relationships
274+
user = relationship("User", back_populates="energy_data")
275+
276+
# Ensure uniqueness per user and date
277+
__table_args__ = (UniqueConstraint("user_id", "date", name="_user_date_energy_uc"),)
278+
279+
def __repr__(self):
280+
total = (self.active_energy or 0) + (self.basal_energy or 0)
281+
return f"<Energy(user_id={self.user_id}, date={self.date}, active={self.active_energy}kcal, basal={self.basal_energy}kcal, total={total}kcal)>"
282+
283+
258284
class Steps(Base):
259285
"""Daily steps and distance data from Garmin Connect."""
260286

0 commit comments

Comments
 (0)