def get_readings(self):
        for record in self._get_records_reader():
            if record[_RESULT_CSV_KEY] is None:
                continue

            yield common.GlucoseReading(self._extract_datetime(record),
                                        common.convert_glucose_unit(
                                            float(record[_RESULT_CSV_KEY]),
                                            _UNIT_MAP[record[_UNIT_CSV_KEY]],
                                            common.Unit.MG_DL),
                                        meal=self._extract_meal(record))
    def get_readings(self):
        for record in self._get_records_reader():
            if record[_RESULT_CSV_KEY] is None:
                continue

            yield common.GlucoseReading(
                self._extract_datetime(record),
                common.convert_glucose_unit(
                    float(record[_RESULT_CSV_KEY]),
                    _UNIT_MAP[record[_UNIT_CSV_KEY]],
                    common.Unit.MG_DL),
                meal=self._extract_meal(record))
    def test_glucose_conversion(self):
        self.assertEqual(
            5.56, common.convert_glucose_unit(
                100, common.UNIT_MGDL, common.UNIT_MMOLL))

        self.assertEqual(
            5.56, common.convert_glucose_unit(
                100, common.UNIT_MGDL))

        self.assertEqual(
            180, common.convert_glucose_unit(
                10, common.UNIT_MMOLL, common.UNIT_MGDL))

        self.assertEqual(
            180, common.convert_glucose_unit(
                10, common.UNIT_MMOLL))

        self.assertEqual(
            100, common.convert_glucose_unit(
                100, common.UNIT_MGDL, common.UNIT_MGDL))

        self.assertEqual(
            10, common.convert_glucose_unit(
                10, common.UNIT_MMOLL, common.UNIT_MMOLL))

        self.assertRaises(
            exceptions.InvalidGlucoseUnit,
            common.convert_glucose_unit, common.UNIT_MMOLL, 'foo')
Exemple #4
0
    def test_glucose_conversion(self):
        self.assertEqual(
            5.56,
            common.convert_glucose_unit(100, common.UNIT_MGDL,
                                        common.UNIT_MMOLL))

        self.assertEqual(5.56,
                         common.convert_glucose_unit(100, common.UNIT_MGDL))

        self.assertEqual(
            180,
            common.convert_glucose_unit(10, common.UNIT_MMOLL,
                                        common.UNIT_MGDL))

        self.assertEqual(180,
                         common.convert_glucose_unit(10, common.UNIT_MMOLL))

        self.assertEqual(
            100,
            common.convert_glucose_unit(100, common.UNIT_MGDL,
                                        common.UNIT_MGDL))

        self.assertEqual(
            10,
            common.convert_glucose_unit(10, common.UNIT_MMOLL,
                                        common.UNIT_MMOLL))

        self.assertRaises(exceptions.InvalidGlucoseUnit,
                          common.convert_glucose_unit, common.UNIT_MMOLL,
                          'foo')
    def get_readings(self) -> Generator[common.AnyReading, None, None]:
        for reading in self._get_raw_readings():
            if reading.reading_type != "Glu":
                logging.warning(
                    f"Unsupported reading type {reading.reading_type!r}. Please file an issue at https://github.com/glucometers-tech/glucometerutils/issues"
                )
                continue

            mgdl_value = common.convert_glucose_unit(
                reading.value,
                from_unit=reading.unit,
                to_unit=common.Unit.MG_DL,
            )

            yield common.GlucoseReading(
                reading.timestamp,
                mgdl_value,
                meal=reading.meal,
                comment=reading.comment,
            )
 def test_invalid_values(self, from_unit, to_unit):
     with self.assertRaises(Exception):
         common.convert_glucose_unit(100, from_unit, to_unit)
 def test_convert_identity_str(self, unit_str):
     self.assertEqual(100,
                      common.convert_glucose_unit(100, unit_str, unit_str))
 def test_convert_identity(self, unit):
     self.assertEqual(100, common.convert_glucose_unit(100, unit, unit))
 def test_convert_to_mgdl(self):
     self.assertEqual(
         180,
         common.convert_glucose_unit(10, common.Unit.MMOL_L,
                                     common.Unit.MG_DL))
 def test_convert_to_mmol(self):
     self.assertEqual(
         5.56,
         common.convert_glucose_unit(100, common.Unit.MG_DL,
                                     common.Unit.MMOL_L))
 def test_invalid_values(self, from_unit, to_unit):
     with self.assertRaises(Exception):
         common.convert_glucose_unit(100, from_unit, to_unit)
 def test_convert_identity_str(self, unit_str):
     self.assertEqual(
         100, common.convert_glucose_unit(
             100, unit_str, unit_str))
 def test_convert_identity(self, unit):
     self.assertEqual(
         100, common.convert_glucose_unit(
             100, unit, unit))
 def test_convert_to_mgdl(self):
     self.assertEqual(
         180, common.convert_glucose_unit(
             10, common.Unit.MMOL_L, common.Unit.MG_DL))
 def test_convert_to_mmol(self):
     self.assertEqual(
         5.56, common.convert_glucose_unit(
             100, common.Unit.MG_DL, common.Unit.MMOL_L))