def test_that_observation_can_be_updated_when_minute_already_exists(self): Minute.objects.create(datetime=self.datetime) create_observation(self.liverpool, self.datetime, 123.45, False) create_observation(self.liverpool, self.datetime, 45.67, False) assert_equal(45.67, Observation.objects.get().sea_level)
def _setup_all_ok(self): create_observation( self.liverpool, BASE_TIME - datetime.timedelta(minutes=10), 4.5, True) self.southampton.delete()
def save(self, *args, **kwargs): linked_location = self.tide_gauge.linked_location if linked_location is not None: create_observation(linked_location, self.datetime, self.height, False) super(RawMeasurement, self).save(*args, **kwargs)
def save(self, *args, **kwargs): linked_location = self.tide_gauge.linked_location if linked_location is not None: create_observation( linked_location, self.datetime, self.height, False) super(RawMeasurement, self).save(*args, **kwargs)
def test_that_observations_from_liverpool_dont_affect_southampton(self): create_observation( self.liverpool, BASE_TIME - datetime.timedelta(minutes=self.OK_MINUTES - 1), 10.0, True) with freeze_time(BASE_TIME): (ok, text) = check_observations(self.southampton) assert_equal(False, ok) assert_equal('> 2 hours old', text)
def test_that_observations_more_recent_than_one_hour_are_ok(self): create_observation( self.liverpool, BASE_TIME - datetime.timedelta(minutes=self.OK_MINUTES - 1), 10.0, True) with freeze_time(BASE_TIME): (ok, text) = check_observations(self.liverpool) assert_equal(True, ok) assert_equal('OK', text)
def setUpClass(cls): super(TestSeaLevelsViewShowsObservations, cls).setUpClass() base_time = datetime.datetime(2014, 6, 1, 10, 30, tzinfo=pytz.UTC) for minute, tide_level in [(0, 5.0), (1, 5.1), (2, 5.2)]: create_tide_prediction( cls.location, base_time + datetime.timedelta(minutes=minute), tide_level) create_observation(cls.location, base_time + datetime.timedelta(minutes=1), 4.8, True)
def _setup_all_ok(self): create_tide_prediction( self.liverpool, BASE_TIME + datetime.timedelta(days=31), 5.0) _make_good_surge_predictions(self.liverpool) create_observation( self.liverpool, BASE_TIME - datetime.timedelta(minutes=10), 4.5, True) self.southampton.delete() # so that it doesn't come up as a failure
def update_observations(station, stdout): if observations_up_to_date(station): stdout.write("Nothing to do for {}".format(station)) return stdout.write("Converting measurements at {} => {}".format( station, station.location)) start = get_latest_observation(station.location) end = get_latest_ea_measurement(station) for dt, value, is_interp in make_linear_interpolations(start, end): new_value = convert_to_chart_datum(station, value) create_observation(station.location, dt, new_value, is_interp)
def setUpClass(cls): super(TestSeaLevelsViewShowsObservations, cls).setUpClass() base_time = datetime.datetime(2014, 6, 1, 10, 30, tzinfo=pytz.UTC) for minute, tide_level in [(0, 5.0), (1, 5.1), (2, 5.2)]: create_tide_prediction( cls.location, base_time + datetime.timedelta(minutes=minute), tide_level ) create_observation( cls.location, base_time + datetime.timedelta(minutes=1), 4.8, True)
def test_that_observation_can_be_created_when_minute_doesnt_exist(self): create_observation(self.liverpool, self.datetime, 123.45, False) assert_equal(123.45, Observation.objects.get().sea_level)
def _make_bad_observations(self): create_observation( self.liverpool, BASE_TIME - datetime.timedelta(minutes=self.OK_MINUTES + 1), 10.0, True)
def _setup_all_ok(self): create_observation(self.liverpool, BASE_TIME - datetime.timedelta(minutes=10), 4.5, True) self.southampton.delete()
def test_that_up_to_date_observations_does_nothing(self): self.make_two_measurements() create_observation(self.station.location, self.datetime_2, 10, False) update_observations(self.station, sys.stdout) assert_equal(1, Observation.objects.all().count())