Ejemplo n.º 1
0
def missing_intervals(minutes, end):
    last_cq_stats = CQStats.query().filter(
        CQStats.interval_minutes == minutes).order(-CQStats.end).get()
    if last_cq_stats:
        return intervals_in_range(minutes, last_cq_stats.end, end)
    earliest_record = Record.query().order(Record.timestamp).get()
    if earliest_record:
        begin = earliest_record.timestamp - timedelta(minutes=minutes)
        return intervals_in_range(minutes, begin, end)
    return []
Ejemplo n.º 2
0
def missing_intervals(minutes, end):
  last_cq_stats = CQStats.query().filter(
      CQStats.interval_minutes == minutes).order(-CQStats.end).get()
  if last_cq_stats:
    return intervals_in_range(minutes, last_cq_stats.end, end)
  earliest_record = Record.query().order(Record.timestamp).get()
  if earliest_record:
    begin = earliest_record.timestamp - timedelta(minutes=minutes)
    return intervals_in_range(minutes, begin, end)
  return []
Ejemplo n.º 3
0
  def test_intervals_in_range(self):
    self.assertEqual([
        (datetime(2000, 1, 1, 10), datetime(2000, 1, 1, 11)),
        (datetime(2000, 1, 1, 11), datetime(2000, 1, 1, 12)),
        (datetime(2000, 1, 1, 12), datetime(2000, 1, 1, 13)),
        (datetime(2000, 1, 1, 13), datetime(2000, 1, 1, 14)),
      ], intervals_in_range(60,
          datetime(2000, 1, 1, 10), datetime(2000, 1, 1, 14)))

    self.assertEqual([
        (datetime(2000, 1, 1, 8), datetime(2000, 1, 2, 8)),
        (datetime(2000, 1, 2, 8), datetime(2000, 1, 3, 8)),
        (datetime(2000, 1, 3, 8), datetime(2000, 1, 4, 8)),
      ], intervals_in_range(1440,
          datetime(2000, 1, 1), datetime(2000, 1, 5)))

    self.assertEqual([], intervals_in_range(1440,
        datetime(2000, 1, 1, 8), datetime(2000, 1, 1, 9)))
Ejemplo n.º 4
0
    def test_intervals_in_range(self):
        self.assertEqual([
            (datetime(2000, 1, 1, 10), datetime(2000, 1, 1, 11)),
            (datetime(2000, 1, 1, 11), datetime(2000, 1, 1, 12)),
            (datetime(2000, 1, 1, 12), datetime(2000, 1, 1, 13)),
            (datetime(2000, 1, 1, 13), datetime(2000, 1, 1, 14)),
        ],
                         intervals_in_range(60, datetime(2000, 1, 1, 10),
                                            datetime(2000, 1, 1, 14)))

        self.assertEqual([
            (datetime(2000, 1, 1, 8), datetime(2000, 1, 2, 8)),
            (datetime(2000, 1, 2, 8), datetime(2000, 1, 3, 8)),
            (datetime(2000, 1, 3, 8), datetime(2000, 1, 4, 8)),
        ], intervals_in_range(1440, datetime(2000, 1, 1), datetime(2000, 1,
                                                                   5)))

        self.assertEqual([],
                         intervals_in_range(1440, datetime(2000, 1, 1, 8),
                                            datetime(2000, 1, 1, 9)))