-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #150: add config variable sleep_from_fit which if set to true c…
…auses sleep_events to be populated from FIT files rather than Garmin Connect JSON data
- Loading branch information
Tom Goetz
committed
Mar 7, 2022
1 parent
eadf9df
commit 1ae4064
Showing
13 changed files
with
116 additions
and
24 deletions.
There are no files selected for viewing
Submodule Fit
updated
6 files
+3 −2 | fitfile/definition_message_data.py | |
+8 −1 | fitfile/enum_fields.py | |
+2 −1 | fitfile/field_enums/__init__.py | |
+12 −0 | fitfile/field_enums/field_enums.py | |
+20 −5 | fitfile/file.py | |
+1 −1 | fitfile/version_info.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Class that takes a parsed monitoring FIT file object and imports it into a database.""" | ||
|
||
__author__ = "Tom Goetz" | ||
__copyright__ = "Copyright Tom Goetz" | ||
__license__ = "GPL" | ||
|
||
import logging | ||
import sys | ||
|
||
import fitfile | ||
|
||
from .garmindb import SleepEvents | ||
from .fit_file_processor import FitFileProcessor | ||
|
||
|
||
logger = logging.getLogger(__file__) | ||
logger.addHandler(logging.StreamHandler(stream=sys.stdout)) | ||
root_logger = logging.getLogger() | ||
|
||
|
||
class SleepFitFileProcessor(FitFileProcessor): | ||
"""Class that takes a parsed sleep FIT file object and imports it into a database.""" | ||
|
||
def write_file(self, fit_file): | ||
"""Given a Fit File object, write all of its messages to the DB.""" | ||
self.last_sleep_event = None | ||
self.last_sleep_level = None | ||
with self.garmin_db.managed_session() as self.garmin_db_session: | ||
self._write_message_types(fit_file, fit_file.message_types) | ||
|
||
def _write_sleep_level_entry(self, fit_file, message_fields): | ||
logger.debug("sleep level message: %r", message_fields) | ||
timestamp = fit_file.utc_datetime_to_local(message_fields.timestamp) | ||
sleep_level = message_fields.get('sleep_level') | ||
if sleep_level.value > fitfile.field_enums.SleepActivityLevel.unknown.value and self.last_sleep_event is not None and \ | ||
(sleep_level is not fitfile.field_enums.SleepActivityLevel.awake or self.last_sleep_level is not fitfile.field_enums.SleepActivityLevel.awake): | ||
sleep_event = { | ||
'timestamp' : fit_file.utc_datetime_to_local(self.last_sleep_event), | ||
'event' : sleep_level.name, | ||
'duration' : fitfile.conversions.timedelta_to_time(timestamp - self.last_sleep_event) | ||
} | ||
logger.debug("sleep level event: %r", sleep_event) | ||
SleepEvents.s_insert_or_update(self.garmin_db_session, sleep_event) | ||
self.last_sleep_event = timestamp | ||
self.last_sleep_level = sleep_level |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ matplotlib | |
cloudscraper | ||
ipykernel | ||
ipyleaflet | ||
fitfile>=1.1.2 | ||
fitfile>=1.1.3 | ||
tcxfile>=1.0.4 | ||
idbutils>=1.0.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule utilities
updated
6 files
+2 −2 | idbutils/db.py | |
+1 −1 | idbutils/file_processor.py | |
+1 −1 | idbutils/json_config.py | |
+1 −1 | idbutils/json_file_processor.py | |
+1 −1 | idbutils/rest_client.py | |
+1 −1 | idbutils/version_info.py |