Skip to content

Commit

Permalink
Issue 221: add training load to activities; redo self eval as decoded…
Browse files Browse the repository at this point in the history
… strings
  • Loading branch information
tcgoetz committed Feb 18, 2024
1 parent 9171ee3 commit ec2afc5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
31 changes: 27 additions & 4 deletions garmindb/garmin_json_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,39 @@ def _process_fitness_equipment(self, sub_sport, activity_id, json_data):
root_logger.debug("fitness_equipment (%s) for %d: %r", sub_sport, activity_id, json_data)
self._call_process_func(sub_sport.name, None, activity_id, json_data)

@classmethod
def get_self_eval_feel(cls, value):
"""Return the Garmin Connect self evaluation 'How did you feel' label for the activity."""
levels = [(100, "Very Strong"), (75, "Strong"), (50, "Normal"), (25, "Weak"), (0, "Very Weak")]
for threshold, label in levels:
print(f"Threshold {threshold} label {label}")
if value >= threshold:
return label

@classmethod
def get_self_eval_effort(cls, value):
"""Return the Garmin Connect self evaluation perceived effort label for the activity."""
levels = [(100, "Maximum"), (90, "Extremely Hard"), (70, "Very Hard"), (50, "Hard"),
(40, "Somewhat Hard"), (30, "Moderate"), (20, "Light"), (10, "Very Light"), (0, "None")]
for threshold, label in levels:
print(f"Threshold {threshold} label {label}")
if value >= threshold:
return label

def _activities_process_json(self, json_data):
activity_id = json_data['activityId']
metadata_dto = json_data['metadataDTO']
summary_dto = json_data['summaryDTO']
sport, sub_sport = get_details_sport(json_data)
self_eval_feel = self._get_field(summary_dto, 'directWorkoutFeel', int)
self_eval_effort = self._get_field(summary_dto, 'directWorkoutRpe', int)
activity = {
'activity_id' : activity_id,
'course_id' : self._get_field(metadata_dto, 'associatedCourseId', int),
'self_eval_feel' : self._get_field(summary_dto, 'directWorkoutFeel', int),
'self_eval_effort' : self._get_field(summary_dto, 'directWorkoutRpe', int)
'activity_id' : activity_id,
'course_id' : self._get_field(metadata_dto, 'associatedCourseId', int),
'device_serial_number' : self._get_field(metadata_dto, 'deviceId', int),
'self_eval_feel' : self.get_self_eval_feel(self_eval_feel) if (self_eval_feel is not None) else None,
'self_eval_effort' : self.get_self_eval_effort(self_eval_effort) if (self_eval_effort is not None) else None,
'training_load' : self._get_field(summary_dto, 'activityTrainingLoad', float)
}
activity.update(self._process_common(summary_dto))
Activities.s_insert_or_update(self.garmin_act_db_session, activity, ignore_none=True)
Expand Down
25 changes: 6 additions & 19 deletions garmindb/garmindb/activities_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ class Activities(ActivitiesDb.Base, ActivitiesCommon):
sport = Column(String)
sub_sport = Column(String)

self_eval_feel = Column(Integer)
self_eval_effort = Column(Integer)
device_serial_number = Column(Integer)

self_eval_feel = Column(String)
self_eval_effort = Column(String)

training_load = Column(Float)

training_effect = Column(Float)
anaerobic_training_effect = Column(Float)
Expand All @@ -119,23 +123,6 @@ def is_steps_activity(self):
"""Return if the activity is a steps based activity."""
return self.sport in ['walking', 'running', 'hiking']

def get_self_eval_feel(self):
"""Return the Garmin Connect self evaluation 'How did you feel' label for the activity."""
levels = [(100, "Very Strong"), (75, "Strong"), (50, "Normal"), (25, "Weak"), (0, "Very Weak")]
for threshold, label in levels:
print(f"Threshold {threshold} label {label}")
if self.self_eval_feel >= threshold:
return label

def get_self_eval_effort(self):
"""Return the Garmin Connect self evaluation perceived effort label for the activity."""
levels = [(100, "Maximum"), (90, "Extremely Hard"), (70, "Very Hard"), (50, "Hard"),
(40, "Somewhat Hard"), (30, "Moderate"), (20, "Light"), (10, "Very Light"), (0, "None")]
for threshold, label in levels:
print(f"Threshold {threshold} label {label}")
if self.self_eval_effort >= threshold:
return label

@classmethod
def get_by_course_id(cls, db, course_id):
"""Return all activities items for activities with the matching course_id."""
Expand Down

0 comments on commit ec2afc5

Please sign in to comment.