def test_insert_reading_collision(self): ''' Test that if we insert two readings with the same timestamp and datastream we get a collision ''' sensor = Sensor.objects.get(uuid="sensor_one_id") ds = DataStream.objects.get(pk=1) timestamp = int(time.time()) insert_reading(ds, sensor, 10.5, timestamp) self.assertRaises(SensorReadingCollision, insert_reading, *(ds, sensor, 10.5, timestamp) )
def test_insert_reading_no_timestamp(self): ''' Test that a sensor reading get's creating without an explicit timestamp ''' sensor = Sensor.objects.get(uuid="sensor_one_id") ds = DataStream.objects.get(pk=1) reading = insert_reading(ds, sensor, 10.5) self.assertTrue(isinstance(reading, SensorReading))
def test_insert_reading_no_ds(self): ''' Test that we get a new sensor reading even with no datastream ''' sensor = Sensor.objects.get(uuid="sensor_one_id") timestamp = int(time.time()) reading = insert_reading(None, sensor, 10.5, timestamp) self.assertEqual(reading, SensorReading.objects.get(datastream=None, timestamp=timestamp))
def test_insert_reading_ds(self): ''' Test that we get a new sensor reading with a datastream ''' sensor = Sensor.objects.get(uuid="sensor_one_id") ds = DataStream.objects.get(pk=1) timestamp = int(time.time()) reading = insert_reading(ds, sensor, 10.5, timestamp) self.assertEqual(reading, SensorReading.objects.get(datastream=ds, timestamp=timestamp))
if len(foundSensors) <= 0: msg = "Out of the possible test Sensors " + ", ".join(sensors) msg += " not a single one was found. Aborting" sys.exit(msg) print "Found Sensors " +", ".join(map(lambda d: str(d.uuid), foundSensors)) print "Found Streams " +", ".join(map(lambda d: str(d.pk), foundStreams)) for t in range(startTime, startTime + 60*60*24*31, 1000*60): print "Time = %s" % time.localtime(t) for i in range(t, t + 1000*60, 60): for si, sensor in enumerate(foundSensors): if si % 2 == 0: value = 50 * math.sin(i*math.pi/(86400)) insert_reading(foundStreams[si], sensor, value, i) elif si % 3 == 0: value = 50 * math.sin(i*2*math.pi/(60*60*24*30)) * math.sin(i*math.pi/(86400)) insert_reading(foundStreams[si], sensor, value, i) else: value = random.randint(0, 50) * math.sin(i*math.pi/(86400)) insert_reading(foundStreams[si], sensor, value, i) time.sleep(1) print 'Done'
description="Random amplitude modulation", color="blue", min_value=-50.0, max_value=50.0, scaling_function=scaleF, owner=AuthUser.objects.get(username="******"), ) ds3.save() if len(sys.argv) > 1: startTime = int(time.mktime(time.strptime(sys.argv[1], strf))) else: print "You must give a date in the format: YYYY-MM-DD" sys.exit(1) if len(sys.argv) > 2: nMonths = int(sys.argv[2]) else: nMonths = 1 for t in range(startTime, startTime + 60 * 60 * 24 * 31 * nMonths, 1000 * 60): print "Time = %s" % time.localtime(t) for i in range(t, t + 1000 * 60, 60): insert_reading(ds1, 50 * math.sin(i * math.pi / (86400)), i) insert_reading(ds2, 50 * math.sin(i * 2 * math.pi / (60 * 60 * 24 * 30)) * math.sin(i * math.pi / (86400)), i) insert_reading(ds3, random.randint(0, 50) * math.sin(i * math.pi / (86400)), i) time.sleep(1) print "Done"