Exemple #1
0
    def cache_script_is_due(self):
        if self.script_run_next_opportunity:
            return True

        if self.script_last_run_started is None:
            return True

        if not (0 < self.script_times_to_run_per_day <= (24 * 60)):
            return False

        minutes_between_scripts = (
            (60 * 24) // self.script_times_to_run_per_day)

        current_time = dates.utc_now()

        minutes_since_midnight = (
            60 * current_time.hour + current_time.minute)

        script_should_run_at_minutes = (
            minutes_since_midnight -
            (minutes_since_midnight % minutes_between_scripts))

        script_should_run_at = current_time.replace(
            hour=script_should_run_at_minutes // 60,
            minute=script_should_run_at_minutes % 60)

        return (
            script_should_run_at > dates.to_utc(self.script_last_run_started))
Exemple #2
0
    def test_naive_date_becomes_utc(self):
        d = datetime.datetime(2012, 11, 13, 12, 00)
        u = dates.to_utc(d)

        self.assertRaises(TypeError, lambda: d == u)
        self.assertEquals(u.tzinfo, dates.UTC)

        self.assertEquals(d.utctimetuple(), u.timetuple())
    def timeseries(self, location_id, start_datetime=None, end_datetime=None):
        try:
            jdbc_result = self.jdbc_source.get_timeseries(
                self._choices_made['filter'],
                location_id,
                self._choices_made['parameter'],
                start_datetime,
                end_datetime)
        except Exception as e:
            logger.warn("Oh no, an exception: {0}:".format(e))
            # Timeouts and such
            jdbc_result = []

        series_name = self.cached_unit()

        dataframe = timeseries.DataFrame({
                series_name: timeseries.Series(dict(
                        (dates.to_utc(point['time']), point['value'])
                        for point in jdbc_result))})

        return timeseries.Timeseries(dataframe)
Exemple #4
0
 def test_utc_unchanged(self):
     d = datetime.datetime(
         2012, 11, 13, 12, 00,
         tzinfo=dates.UTC)
     u = dates.to_utc(d)
     self.assertEquals(d, u)
Exemple #5
0
 def test_other_timezone_becomes_utc(self):
     d = datetime.datetime(
         2012, 11, 13, 12, 00,
         tzinfo=pytz.timezone('Europe/Amsterdam'))
     u = dates.to_utc(d)
     self.assertEquals(u.tzinfo, dates.UTC)