Beispiel #1
0
 def fill_missing_periods(self, start_date, end_date, collect=None):
     default = {"_count": 0}
     if collect:
         default.update((collect_key(k, v), None) for k, v in collect)
     for i, _ in enumerate(self._data):
         self._data[i]["values"] = timeseries(
             start=start_date, end=end_date, period=self._period, data=self._data[i]["values"], default=default
         )
Beispiel #2
0
 def fill_missing_months(self, start_date, end_date):
     for i, _ in enumerate(self._data):
         self._data[i]['values'] = timeseries(
             start=start_date,
             end=end_date,
             period=MONTH,
             data=self._data[i]['values'],
             default={"_count": 0}
         )
 def fill_missing_periods(self, start_date, end_date, collect=None):
     default = {"_count": 0}
     if collect:
         default.update((collect_key(k, v), None) for k, v in collect)
     self._data = timeseries(start=start_date,
                             end=end_date,
                             period=self.period,
                             data=self._data,
                             default=default)
Beispiel #4
0
 def fill_missing_periods(self, start_date, end_date, collect=None):
     default = {"_count": 0}
     if collect:
         default.update((collect_key(k, v), None) for k, v in collect)
     self._data = timeseries(start=start_date,
                             end=end_date,
                             period=self.period,
                             data=self._data,
                             default=default)
Beispiel #5
0
 def fill_missing_periods(self, start, end):
     periods = {
         "week": WEEK,
         "month": MONTH
     }
     self._data = timeseries(start=start,
                             end=end,
                             period=periods[self.period],
                             data=self._data,
                             default={"_count": 0})
Beispiel #6
0
    def test_returns_a_full_timeseries(self):
        ts = timeseries(start=d_tz(2013, 4, 1),
                        end=d_tz(2013, 4, 15),
                        period=WEEK,
                        data=[],
                        default={"value": 0})

        assert_that(ts, contains(
            {"_start_at": d_tz(2013, 4, 1), "_end_at": d_tz(2013, 4, 8), "value": 0},
            {"_start_at": d_tz(2013, 4, 8), "_end_at": d_tz(2013, 4, 15), "value": 0},
        ))
Beispiel #7
0
    def test_returns_a_full_timeseries(self):
        ts = timeseries(start=d_tz(2013, 4, 1),
                        end=d_tz(2013, 4, 15),
                        period=WEEK,
                        data=[],
                        default={"value": 0})

        assert_that(ts, contains(
            {"_start_at": d_tz(2013, 4, 1), "_end_at": d_tz(2013, 4, 8), "value": 0},
            {"_start_at": d_tz(2013, 4, 8), "_end_at": d_tz(2013, 4, 15), "value": 0},
        ))
 def fill_missing_periods(self,
                          start_date,
                          end_date,
                          collect=None,
                          group_by=[]):
     default = {"_count": 0}
     if collect:
         default.update((collect_key(k, v), None) for k, v in collect)
     for i, _ in enumerate(self._data):
         self._data[i]['values'] = timeseries(start=start_date,
                                              end=end_date,
                                              period=self._period,
                                              data=self._data[i]['values'],
                                              default=default)
Beispiel #9
0
    def test_adds_data_at_appropriate_places(self):
        data = [
            {"_start_at": d_tz(2013, 4, 1), "_end_at": d_tz(2013, 4, 8), "value": 12}
        ]

        ts = timeseries(start=d_tz(2013, 4, 1),
                        end=d_tz(2013, 4, 15),
                        period=WEEK,
                        data=data,
                        default={"value": 0})

        assert_that(ts, contains(
            {"_start_at": d_tz(2013, 4, 1), "_end_at": d_tz(2013, 4, 8), "value": 12},
            {"_start_at": d_tz(2013, 4, 8), "_end_at": d_tz(2013, 4, 15), "value": 0},
        ))
Beispiel #10
0
    def test_adds_data_at_appropriate_places(self):
        data = [
            {"_start_at": d_tz(2013, 4, 1), "_end_at": d_tz(2013, 4, 8), "value": 12}
        ]

        ts = timeseries(start=d_tz(2013, 4, 1),
                        end=d_tz(2013, 4, 15),
                        period=WEEK,
                        data=data,
                        default={"value": 0})

        assert_that(ts, contains(
            {"_start_at": d_tz(2013, 4, 1), "_end_at": d_tz(2013, 4, 8), "value": 12},
            {"_start_at": d_tz(2013, 4, 8), "_end_at": d_tz(2013, 4, 15), "value": 0},
        ))
Beispiel #11
0
    def test_start_and_end_are_expanded_to_week_limits(self):
        data = [
            {"_start_at": d_tz(2013, 4, 8), "_end_at": d_tz(2013, 4, 15), "value": 12},
            {"_start_at": d_tz(2013, 4, 15), "_end_at": d_tz(2013, 4, 22), "value": 23}
        ]

        ts = timeseries(start=d_tz(2013, 4, 5),
                        end=d_tz(2013, 4, 25),
                        period=WEEK,
                        data=data,
                        default={"value": 0})

        assert_that(ts, contains(
            {"_start_at": d_tz(2013, 4, 1), "_end_at": d_tz(2013, 4, 8), "value": 0},
            {"_start_at": d_tz(2013, 4, 8), "_end_at": d_tz(2013, 4, 15), "value": 12},
            {"_start_at": d_tz(2013, 4, 15), "_end_at": d_tz(2013, 4, 22), "value": 23},
            {"_start_at": d_tz(2013, 4, 22), "_end_at": d_tz(2013, 4, 29), "value": 0},
        ))
Beispiel #12
0
    def test_start_and_end_are_expanded_to_week_limits(self):
        data = [
            {"_start_at": d_tz(2013, 4, 8), "_end_at": d_tz(2013, 4, 15), "value": 12},
            {"_start_at": d_tz(2013, 4, 15), "_end_at": d_tz(2013, 4, 22), "value": 23}
        ]

        ts = timeseries(start=d_tz(2013, 4, 5),
                        end=d_tz(2013, 4, 25),
                        period=WEEK,
                        data=data,
                        default={"value": 0})

        assert_that(ts, contains(
            {"_start_at": d_tz(2013, 4, 1), "_end_at": d_tz(2013, 4, 8), "value": 0},
            {"_start_at": d_tz(2013, 4, 8), "_end_at": d_tz(2013, 4, 15), "value": 12},
            {"_start_at": d_tz(2013, 4, 15), "_end_at": d_tz(2013, 4, 22), "value": 23},
            {"_start_at": d_tz(2013, 4, 22), "_end_at": d_tz(2013, 4, 29), "value": 0},
        ))
Beispiel #13
0
 def fill_missing_weeks(self, start_date, end_date):
     for i, _ in enumerate(self._data):
         self._data[i]["values"] = timeseries(
             start=start_date, end=end_date, period=WEEK, data=self._data[i]["values"], default={"_count": 0}
         )