Skip to content

Commit

Permalink
wip add config for report fields
Browse files Browse the repository at this point in the history
TODO:
* Also apply to daily reports
* Add/adjust tests for this
  • Loading branch information
caarmen committed Dec 14, 2024
1 parent fbf06fb commit f9e5180
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
11 changes: 11 additions & 0 deletions config/app-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ fitbit:
default_report:
daily: false
realtime: true
fields:
- activity_count
- distance
- calories
- duration
- fat_burn_minutes
- cardio_minutes
- peak_minutes
- out_of_zone_minutes

activity_types:
# Configuration specific to activity types.
Expand All @@ -44,6 +53,8 @@ fitbit:
report:
daily: true
realtime: false
fields:
- distance

- name: Spinning
id: 55001
Expand Down
29 changes: 26 additions & 3 deletions slackhealthbot/domain/usecases/slack/usecase_post_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
get_activity_minutes_change_icon,
get_ranking_text,
)
from slackhealthbot.settings import ReportField, settings


async def do(
Expand Down Expand Up @@ -116,12 +117,33 @@ def create_message(
recent_top_value,
record_history_days=record_history_days,
)
activity_type_settings = next(
x
for x in settings.app_settings.fitbit.activities.activity_types
if x.name == activity_name
)
report_settings = (
activity_type_settings.report
if (
activity_type_settings.report
and activity_type_settings.report.fields is not None
)
else settings.app_settings.fitbit.activities.default_report
)

message = f"""
New {activity_name} activity from <@{slack_alias}>:
• Duration: {activity.total_minutes} minutes {duration_icon} {duration_record_text}
New {activity_name} activity from <@{slack_alias}>:"""

if ReportField.duration in report_settings.fields:
message += f"""
• Duration: {activity.total_minutes} minutes {duration_icon} {duration_record_text}"""

if ReportField.calories in report_settings.fields:
message += f"""
• Calories: {activity.calories} {calories_icon} {calories_record_text}
"""
if activity.distance_km:

if ReportField.distance in report_settings.fields and activity.distance_km:
message += f""" • Distance: {activity.distance_km:.3f} km {distance_km_icon} {distance_km_record_text}
"""
message += "\n".join(
Expand All @@ -131,6 +153,7 @@ def create_message(
+ zone_icons.get(zone_minutes.zone, "")
+ f" {zone_record_texts.get(zone_minutes.zone, '')}"
for zone_minutes in activity.zone_minutes
if f"{zone_minutes.zone}_minutes" in report_settings.fields
]
)
return message
15 changes: 15 additions & 0 deletions slackhealthbot/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import dataclasses
import datetime as dt
import enum
import os
from pathlib import Path
from typing import Optional

import yaml
from pydantic import AnyHttpUrl, BaseModel, HttpUrl
Expand Down Expand Up @@ -36,9 +38,21 @@ class Poll(BaseModel):
interval_seconds: int = 3600


class ReportField(enum.StrEnum):
activity_count = enum.auto()
distance = enum.auto()
calories = enum.auto()
duration = enum.auto()
fat_burn_minutes = enum.auto()
cardio_minutes = enum.auto()
peak_minutes = enum.auto()
out_of_zone_minutes = enum.auto()


class Report(BaseModel):
daily: bool
realtime: bool
fields: Optional[list[ReportField]] = None


class ActivityType(BaseModel):
Expand All @@ -54,6 +68,7 @@ class Activities(BaseModel):
default_report: Report = Report(
daily=False,
realtime=True,
fields=[x for x in ReportField],
)


Expand Down

0 comments on commit f9e5180

Please sign in to comment.