Beispiel #1
0
    def run_test(self, filled_buckets, irregular_buckets, start, end, rollup, zerofilled_buckets):
        filled_buckets = [(start + (rollup * bucket), val) for bucket, val in filled_buckets]
        buckets = [(to_timestamp(date), val) for date, val in filled_buckets + irregular_buckets]
        sort_key = lambda row: row[0]
        buckets.sort(key=sort_key)
        zerofilled_buckets = [
            (to_timestamp(start + (rollup * bucket)), []) for bucket in zerofilled_buckets
        ]
        expected = buckets + zerofilled_buckets
        expected.sort(key=sort_key)

        assert zerofill(buckets, start, end, int(rollup.total_seconds())) == expected
Beispiel #2
0
 def test_last_bucket(self):
     # the start does NOT align the first bucket due to the zerofill
     start = timezone.now().replace(minute=5, second=0, microsecond=0)
     rollup = timedelta(minutes=10)
     buckets = [
         (to_timestamp(start + timedelta(minutes=1)), [9]),
         (to_timestamp(start + timedelta(minutes=16)), [3]),
     ]
     zerofilled_buckets = zerofill(buckets, start,
                                   start + timedelta(minutes=20),
                                   int(rollup.total_seconds()))
     assert zerofilled_buckets == [
         (to_timestamp(start - timedelta(minutes=5)), []),
         (to_timestamp(start + timedelta(minutes=1)), [9]),
         (to_timestamp(start + timedelta(minutes=5)), []),
         (to_timestamp(start + timedelta(minutes=16)), [3]),
     ]
Beispiel #3
0
 def zerofill_clean(data):
     return clean(zerofill(data, start, stop, rollup, fill_default=0))