def test_get_from_multiple_metric(self):
     """Test that we get all three measurement fields."""
     measurements = measurements_by_metric(self.database,
                                           *[METRIC_ID, METRIC_ID2])
     self.assertEqual(len(measurements), 6)
     for measurement in measurements:
         self.assertIn(measurement["metric_uuid"], [METRIC_ID, METRIC_ID2])
 def test_get_timestamp_restriction(self):
     """Test that we get all three measurement fields."""
     measurements = measurements_by_metric(self.database,
                                           METRIC_ID,
                                           min_iso_timestamp="0.5",
                                           max_iso_timestamp="4")
     self.assertEqual(len(measurements), 2)
     for measurement in measurements:
         self.assertEqual(measurement["metric_uuid"], METRIC_ID)
         self.assertIn(measurement["start"], ["0", "3"])
Exemple #3
0
def get_subject_measurements(subject_uuid: SubjectId, database: Database):
    """Return all measurements for the subjects within the last 28 weeks."""
    metric_uuids: List[MetricId] = metrics_of_subject(database, subject_uuid)

    report_timestamp = datetime.fromisoformat(
        report_date_time()) if report_date_time() != "" else datetime.now()
    min_datetime = report_timestamp - timedelta(weeks=28)
    min_iso_timestamp = min_datetime.isoformat()

    return dict(measurements=list(
        measurements_by_metric(database,
                               *metric_uuids,
                               min_iso_timestamp=min_iso_timestamp,
                               max_iso_timestamp=report_date_time())))
Exemple #4
0
def get_measurements(metric_uuid: MetricId, database: Database) -> dict:
    """Return the measurements for the metric."""
    metric_uuid = cast(MetricId, metric_uuid.split("&")[0])
    return dict(measurements=list(
        measurements_by_metric(
            database, metric_uuid, max_iso_timestamp=report_date_time())))
 def test_get_from_one_metric(self):
     """Test that we get all three measurement fields."""
     measurements = measurements_by_metric(self.database, METRIC_ID)
     self.assertEqual(len(measurements), 3)
     for measurement in measurements:
         self.assertEqual(measurement["metric_uuid"], METRIC_ID)