def __onNewValues(self, dateTime, value): if self.__range is None: self.__range = resamplebase.build_range(dateTime, self.getFrequency()) self.__grouper = BarsGrouper(self.__range.getBeginning(), value, self.getFrequency()) elif self.__range.belongs(dateTime): self.__grouper.addValue(value) else: self.__values.append(self.__grouper.getGrouped()) self.__range = resamplebase.build_range(dateTime, self.getFrequency()) self.__grouper = BarsGrouper(self.__range.getBeginning(), value, self.getFrequency())
def testDecember(self): freq = bar.Frequency.MONTH begin = datetime.datetime(2011, 12, 1) r = resamplebase.build_range(begin + datetime.timedelta(hours=5, minutes=25), freq) self.assertEqual(r.getBeginning(), begin) for i in range(freq): self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i))) self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1))) self.assertEqual(r.getEnding(), datetime.datetime(2012, 1, 1))
def __testHourRangeImpl(self, timezone=None): freq = bar.Frequency.HOUR begin = datetime.datetime(2011, 1, 1, 16) end = datetime.datetime(2011, 1, 1, 17) if timezone is not None: begin = dt.localize(begin, timezone) end = dt.localize(end, timezone) r = resamplebase.build_range(begin + datetime.timedelta(seconds=120), freq) self.assertEqual(r.getBeginning(), begin) for i in range(freq): self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i))) self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1))) self.assertEqual(r.getEnding(), end)