Esempio n. 1
0
def test_get_dated_entries(setup_and_teardown):
    """
    Get multiple dated entries from corresponding dated reports.
    """

    datetimes = [
        datetime.datetime(1970, 1, 1, 0, 0, 0),
        datetime.datetime(1970, 1, 2, 0, 0, 0),
        datetime.datetime(1970, 1, 3, 0, 0, 0)
    ]

    formattedDatetimes = [lib.formatTime(d) for d in datetimes]

    dates = [d.date() for d in datetimes]

    values = [6.2, 6.0, 5.8]

    entries = dict(zip(datetimes, values))

    formattedEntries = dict(zip(formattedDatetimes, values))

    branch = ["A", "B"]

    # Add dated entries to corresponding reports (the latter will be created
    # if needed)
    reporter.setDatedEntries(DatedReport, branch, entries, path.TESTS)

    # Try and find entries in given dated reports
    # Search for entries strictly: none should be missing!
    storedEntries = reporter.getDatedEntries(DatedReport, dates, branch,
                                             path.TESTS, True)

    assert storedEntries == formattedEntries
Esempio n. 2
0
    def storeRecords(self):
        """
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            STORERECORDS
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        """

        # Info
        Logger.debug("Adding BG records to: " + repr(self.reportType))

        # Initialize values dict
        values = {}

        # Get number of decoded records
        n = len(self.records)

        # Filter them
        for i in range(n):

            # Get value and display time
            value = self.records[i].value
            displayTime = self.records[i].displayTime

            # Only keep normal (numeric) BG values
            if type(value) is float:
                values[displayTime] = value

        # Add entries
        reporter.setDatedEntries(self.reportType, [], values)
Esempio n. 3
0
def test_load(setup_and_teardown):
    """
    Create a profile and load its data.
    """

    profile = [(getTime("23:30:00", "1970.01.01"), 6.2),
               (getTime("00:00:00", "1970.01.02"), 6),
               (getTime("00:30:00", "1970.01.02"), 5.8),
               (getTime("01:00:00", "1970.01.02"), 5.6)]

    # Create dated entries
    reporter.setDatedEntries(test_reporter.DatedReport, [], dict(profile),
                             path.TESTS)

    # Create profile with no loading method implemented
    p = Profile()

    # Try loading
    with pytest.raises(NotImplementedError):
        p.load()

    # Create a past profile (for its existing load method) and define its time
    # references (exclude first and last datetimes)
    p = PastProfile()
    p.define(profile[1][0], profile[-1][0])

    # Load its data using previously generated test dated reports
    p.load()

    # One day before start of profile should have been added to its days
    assert p.data == dict([(lib.formatTime(d), y) for (d, y) in profile])
Esempio n. 4
0
    def store(self):
        """
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            STORE
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        """

        # Info
        Logger.debug("Adding carbs to: " + repr(self.reportType))

        # Add entries
        reporter.setDatedEntries(self.reportType, ["Carbs"],
                                 dict(zip(self.t, self.values)))
Esempio n. 5
0
    def store(self):
        """
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            STORE
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        """

        # Info
        Logger.debug("Adding resume time to: " + repr(self.reportType))

        # Add entries
        reporter.setDatedEntries(self.reportType, ["Suspend/Resume"],
                                 dict(zip(self.t, self.values)))
Esempio n. 6
0
    def storeRecords(self):
        """
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            STORERECORDS
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        """

        # Info
        Logger.debug("Adding sensor calibrations to: " + repr(self.reportType))

        # Add entries
        reporter.setDatedEntries(
            self.reportType, ["CGM", "Calibrations"],
            dict([(r.displayTime, r.value) for r in self.records]))
Esempio n. 7
0
    def storeRecords(self):
        """
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            STORERECORDS
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        """

        # Info
        Logger.debug("Adding sensor statuses to: " + repr(self.reportType))

        # Add entries
        reporter.setDatedEntries(
            self.reportType, ["CGM", "Sensor Statuses"],
            dict([(r.displayTime, r.status) for r in self.records]))
Esempio n. 8
0
    def store(self):
        """
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            STORE
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Note: only stores current IOB for later displaying purposes.
        """

        # Info
        Logger.debug("Adding current IOB to: " + repr(self.reportType))

        # Add entry
        reporter.setDatedEntries(self.reportType, self.branch,
                                 {self.T[0]: round(self.y[0], 2)})
Esempio n. 9
0
    def store(self):

        """
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            STORE
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        """

        # Info
        Logger.debug("Storing battery level to: " + repr(self.reportType))

        # Add entry
        reporter.setDatedEntries(self.reportType, ["CGM", "Battery Levels"],
            { self.t: self.level })
Esempio n. 10
0
def test_get_recent(setup_and_teardown):
    """
    Get entries in recent reports.
    """

    now = datetime.datetime.now()

    datetimes = [
        datetime.datetime(1975, 1, 1, 0, 0, 0),
        datetime.datetime(1980, 2, 2, 0, 0, 0),
        datetime.datetime(1985, 3, 3, 0, 0, 0)
    ]

    values = [6.2, 6.0, 5.8]

    entries = dict(zip(datetimes, values))

    branch = ["A", "B"]

    # Create reports
    reporter.setDatedEntries(DatedReport, branch, entries, path.TESTS)

    # Look for values in last 3 days (strict search)
    emptyResults = reporter.getRecentDatedEntries(DatedReport,
                                                  now,
                                                  branch,
                                                  3,
                                                  src=path.TESTS,
                                                  strict=True)

    # Results should be empty
    assert len(emptyResults) == 0

    # Look for values in 3 most recent available reports
    results = reporter.getRecentDatedEntries(DatedReport,
                                             now,
                                             branch,
                                             3,
                                             src=path.TESTS,
                                             strict=False)

    # There should be as many entries in merged results, as there were reports
    # instanciated. The values should also fit.
    assert (len(results) == len(datetimes) and all(
        [results[lib.formatTime(d)] == entries[d] for d in datetimes]))
Esempio n. 11
0
def test_set_dated_entries(setup_and_teardown):
    """
    Add multiple dated entries to corresponding dated reports.
    """

    datetimes = [
        datetime.datetime(1970, 1, 1, 0, 0, 0),
        datetime.datetime(1970, 1, 2, 0, 0, 0),
        datetime.datetime(1970, 1, 3, 0, 0, 0)
    ]

    values = [6.2, 6.0, 5.8]

    entries = dict(zip(datetimes, values))

    branch = ["A", "B"]

    # Add dated entries to corresponding reports (the latter will be created
    # if needed)
    reporter.setDatedEntries(DatedReport, branch, entries, path.TESTS)

    # Check for each datetime if report was created and value added
    for d in datetimes:

        # Instanciate and load corresponding report
        report = reporter.getReportByType(DatedReport, d.date())

        # Format datetime object to get key
        key = lib.formatTime(d)

        # Get corresponding value, as well as whole JSON
        value = report.get(branch + [key])
        json = report.get()

        # There should only be one key in JSON, and its value should be the
        # one listed in the entries above
        assert len(json.keys()) == 1 and value == entries[d]