How to use the choochoo.fit.profile.AliasInteger function in choochoo

To help you get started, we’ve selected a few choochoo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andrewcooke / choochoo / choochoo / fit / profile.py View on Github external
def __add_known_types(self, to_datetime):
        # these cannot be inferred from name
        self.__add_type(String(self.__log, 'string'))
        self.__add_type(AliasInteger(self.__log, 'enum', 'uint8'))
        self.__add_type(AliasInteger(self.__log, 'byte', 'uint8'))
        # these can be inferred
        for name in BASE_TYPE_NAMES:
            self.profile_to_type(name, auto_create=True)
            self.base_types.append(self.profile_to_type(name))
        # this is in the spreadsheet, but not in the doc
        self.__add_type(Boolean(self.__log, 'bool'))
        # these are defined in the spreadsheet, but the interpretation is in comments
        self.__add_type(Date(self.__log, 'date_time', True, to_datetime=to_datetime))
        self.__add_type(Date(self.__log, 'local_date_time', False, to_datetime=to_datetime))
github andrewcooke / choochoo / choochoo / fit / profile.py View on Github external
def __add_known_types(self, to_datetime):
        # these cannot be inferred from name
        self.__add_type(String(self.__log, 'string'))
        self.__add_type(AliasInteger(self.__log, 'enum', 'uint8'))
        self.__add_type(AliasInteger(self.__log, 'byte', 'uint8'))
        # these can be inferred
        for name in BASE_TYPE_NAMES:
            self.profile_to_type(name, auto_create=True)
            self.base_types.append(self.profile_to_type(name))
        # this is in the spreadsheet, but not in the doc
        self.__add_type(Boolean(self.__log, 'bool'))
        # these are defined in the spreadsheet, but the interpretation is in comments
        self.__add_type(Date(self.__log, 'date_time', True, to_datetime=to_datetime))
        self.__add_type(Date(self.__log, 'local_date_time', False, to_datetime=to_datetime))
github andrewcooke / choochoo / choochoo / fit / profile.py View on Github external
def parse(self, data, count, endian):
        result = self._unpack(data, self.formats, self.bad, count, endian)
        if result is not None and self.size == 1:
            result = bytes(result)
        return result


class AliasInteger(AutoInteger):

    def __init__(self, log, name, spec):
        super().__init__(log, spec)
        self.name = name


class Date(AliasInteger):

    def __init__(self, log, name, utc, to_datetime=True):
        super().__init__(log, name, 'uint32')
        self.__tzinfo = dt.timezone.utc if utc else None
        self.__to_datetime = to_datetime

    @staticmethod
    def convert(time, tzinfo=dt.timezone.utc):
        if time >= 0x10000000 :
            return dt.datetime(1989, 12, 31, tzinfo=tzinfo) + dt.timedelta(seconds=time)
        else:
            return time

    def parse(self, data, count, endian):
        times = super().parse(data, count, endian)
        if self.__to_datetime: