Skip to content

Commit ec2afc5

Browse files
committed
Issue 221: add training load to activities; redo self eval as decoded strings
1 parent 9171ee3 commit ec2afc5

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

garmindb/garmin_json_data.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,39 @@ def _process_fitness_equipment(self, sub_sport, activity_id, json_data):
288288
root_logger.debug("fitness_equipment (%s) for %d: %r", sub_sport, activity_id, json_data)
289289
self._call_process_func(sub_sport.name, None, activity_id, json_data)
290290

291+
@classmethod
292+
def get_self_eval_feel(cls, value):
293+
"""Return the Garmin Connect self evaluation 'How did you feel' label for the activity."""
294+
levels = [(100, "Very Strong"), (75, "Strong"), (50, "Normal"), (25, "Weak"), (0, "Very Weak")]
295+
for threshold, label in levels:
296+
print(f"Threshold {threshold} label {label}")
297+
if value >= threshold:
298+
return label
299+
300+
@classmethod
301+
def get_self_eval_effort(cls, value):
302+
"""Return the Garmin Connect self evaluation perceived effort label for the activity."""
303+
levels = [(100, "Maximum"), (90, "Extremely Hard"), (70, "Very Hard"), (50, "Hard"),
304+
(40, "Somewhat Hard"), (30, "Moderate"), (20, "Light"), (10, "Very Light"), (0, "None")]
305+
for threshold, label in levels:
306+
print(f"Threshold {threshold} label {label}")
307+
if value >= threshold:
308+
return label
309+
291310
def _activities_process_json(self, json_data):
292311
activity_id = json_data['activityId']
293312
metadata_dto = json_data['metadataDTO']
294313
summary_dto = json_data['summaryDTO']
295314
sport, sub_sport = get_details_sport(json_data)
315+
self_eval_feel = self._get_field(summary_dto, 'directWorkoutFeel', int)
316+
self_eval_effort = self._get_field(summary_dto, 'directWorkoutRpe', int)
296317
activity = {
297-
'activity_id' : activity_id,
298-
'course_id' : self._get_field(metadata_dto, 'associatedCourseId', int),
299-
'self_eval_feel' : self._get_field(summary_dto, 'directWorkoutFeel', int),
300-
'self_eval_effort' : self._get_field(summary_dto, 'directWorkoutRpe', int)
318+
'activity_id' : activity_id,
319+
'course_id' : self._get_field(metadata_dto, 'associatedCourseId', int),
320+
'device_serial_number' : self._get_field(metadata_dto, 'deviceId', int),
321+
'self_eval_feel' : self.get_self_eval_feel(self_eval_feel) if (self_eval_feel is not None) else None,
322+
'self_eval_effort' : self.get_self_eval_effort(self_eval_effort) if (self_eval_effort is not None) else None,
323+
'training_load' : self._get_field(summary_dto, 'activityTrainingLoad', float)
301324
}
302325
activity.update(self._process_common(summary_dto))
303326
Activities.s_insert_or_update(self.garmin_act_db_session, activity, ignore_none=True)

garmindb/garmindb/activities_db.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ class Activities(ActivitiesDb.Base, ActivitiesCommon):
109109
sport = Column(String)
110110
sub_sport = Column(String)
111111

112-
self_eval_feel = Column(Integer)
113-
self_eval_effort = Column(Integer)
112+
device_serial_number = Column(Integer)
113+
114+
self_eval_feel = Column(String)
115+
self_eval_effort = Column(String)
116+
117+
training_load = Column(Float)
114118

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

122-
def get_self_eval_feel(self):
123-
"""Return the Garmin Connect self evaluation 'How did you feel' label for the activity."""
124-
levels = [(100, "Very Strong"), (75, "Strong"), (50, "Normal"), (25, "Weak"), (0, "Very Weak")]
125-
for threshold, label in levels:
126-
print(f"Threshold {threshold} label {label}")
127-
if self.self_eval_feel >= threshold:
128-
return label
129-
130-
def get_self_eval_effort(self):
131-
"""Return the Garmin Connect self evaluation perceived effort label for the activity."""
132-
levels = [(100, "Maximum"), (90, "Extremely Hard"), (70, "Very Hard"), (50, "Hard"),
133-
(40, "Somewhat Hard"), (30, "Moderate"), (20, "Light"), (10, "Very Light"), (0, "None")]
134-
for threshold, label in levels:
135-
print(f"Threshold {threshold} label {label}")
136-
if self.self_eval_effort >= threshold:
137-
return label
138-
139126
@classmethod
140127
def get_by_course_id(cls, db, course_id):
141128
"""Return all activities items for activities with the matching course_id."""

0 commit comments

Comments
 (0)