|
20 | 20 | import glob |
21 | 21 |
|
22 | 22 | from garmindb import python_version_check, log_version, format_version |
23 | | -from garmindb.garmindb import GarminDb, Attributes, Sleep, Weight, RestingHeartRate, MonitoringDb, MonitoringHeartRate, ActivitiesDb, GarminSummaryDb |
| 23 | +from garmindb.garmindb import GarminDb, Attributes, Sleep, Weight, RestingHeartRate, Hrv, MonitoringDb, MonitoringHeartRate, ActivitiesDb, GarminSummaryDb |
24 | 24 | from garmindb.summarydb import SummaryDb |
25 | 25 |
|
26 | 26 | from garmindb import Download, Copy, Analyze |
@@ -50,6 +50,7 @@ class GarminDbMain(): |
50 | 50 | Statistics.sleep : GarminDb, |
51 | 51 | Statistics.rhr : GarminDb, |
52 | 52 | Statistics.weight : GarminDb, |
| 53 | + Statistics.hrv : GarminDb, |
53 | 54 | Statistics.activities : ActivitiesDb |
54 | 55 | } |
55 | 56 |
|
@@ -159,6 +160,14 @@ def download_data(self, overwrite, latest, stats): |
159 | 160 | download.get_rhr(rhr_dir, date, days, overwrite) |
160 | 161 | root_logger.info("Saved rhr files for %s (%d) to %s for processing", date, days, rhr_dir) |
161 | 162 |
|
| 163 | + if Statistics.hrv in stats: |
| 164 | + date, days = self.__get_date_and_days(GarminDb(self.gc_config.get_db_params()), latest, Hrv, Hrv.day, 'hrv') |
| 165 | + if days > 0: |
| 166 | + hrv_dir = self.gc_config.get_rhr_dir() # HRV tends to be in the same place as RHR or monitoring |
| 167 | + root_logger.info("Date range to update: %s (%d) to %s", date, days, hrv_dir) |
| 168 | + download.get_hrv(hrv_dir, date, days, overwrite) |
| 169 | + root_logger.info("Saved hrv files for %s (%d) to %s for processing", date, days, hrv_dir) |
| 170 | + |
162 | 171 |
|
163 | 172 | def import_data(self, debug, latest, stats): |
164 | 173 | """Import previously downloaded Garmin data into the database.""" |
@@ -221,6 +230,13 @@ def import_data(self, debug, latest, stats): |
221 | 230 | if grhrd.file_count() > 0: |
222 | 231 | grhrd.process() |
223 | 232 |
|
| 233 | + if Statistics.hrv in stats: |
| 234 | + from garmindb import GarminHrvData |
| 235 | + hrv_dir = self.gc_config.get_rhr_dir() |
| 236 | + ghrvd = GarminHrvData(self.gc_config.get_db_params(), hrv_dir, latest, debug) |
| 237 | + if ghrvd.file_count() > 0: |
| 238 | + ghrvd.process() |
| 239 | + |
224 | 240 | if Statistics.activities in stats: |
225 | 241 | activities_dir = self.gc_config.get_activities_dir() |
226 | 242 | # Tcx fields are less precise than the JSON files, so load Tcx first and overwrite with better JSON values. |
@@ -313,6 +329,7 @@ def main(argv): |
313 | 329 | stats_group.add_argument("-a", "--activities", help="Download and/or import activities data.", dest='stats', action='append_const', const=Statistics.activities) |
314 | 330 | stats_group.add_argument("-m", "--monitoring", help="Download and/or import monitoring data.", dest='stats', action='append_const', const=Statistics.monitoring) |
315 | 331 | stats_group.add_argument("-r", "--rhr", help="Download and/or import resting heart rate data.", dest='stats', action='append_const', const=Statistics.rhr) |
| 332 | + stats_group.add_argument("--hrv", help="Download and/or import heart rate variability data.", dest='stats', action='append_const', const=Statistics.hrv) |
316 | 333 | stats_group.add_argument("-s", "--sleep", help="Download and/or import sleep data.", dest='stats', action='append_const', const=Statistics.sleep) |
317 | 334 | stats_group.add_argument("-w", "--weight", help="Download and/or import weight data.", dest='stats', action='append_const', const=Statistics.weight) |
318 | 335 | modifiers_group = parser.add_argument_group('Modifiers') |
|
0 commit comments