예제 #1
0
파일: tests.py 프로젝트: kkleidal/chain-api
 def setUp(self):
     self.unit = Unit(name='C')
     self.unit.save()
     self.temp_metric = Metric(name='temperature')
     self.temp_metric.save()
     self.setpoint_metric = Metric(name='setpoint')
     self.setpoint_metric.save()
     self.geo_locations = [
         GeoLocation(elevation=50, latitude=42.847, longitude=72.917),
         GeoLocation(elevation=-23.8, latitude=40.847, longitude=42.917)
     ]
     for loc in self.geo_locations:
         loc.save()
     self.sites = [
         Site(name='Test Site 1',
              geo_location=self.geo_locations[0],
              raw_zmq_stream='tcp://example.com:8372'),
         Site(name='Test Site 2',
              geo_location=self.geo_locations[1],
              raw_zmq_stream='tcp://example.com:8172')
     ]
     for site in self.sites:
         site.save()
     num_devices = 2 * len(self.sites)
     self.devices = [Device(name='Thermostat %d' % i,
                            site=self.sites[i % len(self.sites)])
                     for i in range(0, num_devices)]
     num_people = 2 * len(self.sites)
     self.people = [Person(first_name='John',
                           last_name = 'Doe %d' % i,
                           site=self.sites[i % len(self.sites)])
                    for i in range(0, num_people)]
     for person in self.people:
         person.save()
     self.sensors = []
     for device in self.devices:
         device.save()
         self.sensors.append(ScalarSensor(device=device,
                                          metric=self.temp_metric,
                                          unit=self.unit))
         self.sensors.append(ScalarSensor(device=device,
                                          metric=self.setpoint_metric,
                                          unit=self.unit))
     self.scalar_data = []
     for sensor in self.sensors:
         sensor.save()
         self.scalar_data.append(ScalarData(
             sensor=sensor,
             timestamp=now() - timedelta(minutes=2),
             value=22.0))
         self.scalar_data.append(ScalarData(
             sensor=sensor,
             timestamp=now() - timedelta(minutes=1),
             value=23.0))
     for data in self.scalar_data:
         data.save()
예제 #2
0
파일: tests.py 프로젝트: npowern/chain-api
 def test_data_can_be_added(self):
     data = ScalarData(sensor=self.sensors[0], value=25)
     data.save()
     self.assertEqual(data.value, 25)
예제 #3
0
 def test_data_can_be_added(self):
     data = ScalarData(sensor=self.sensors[0], value=25)
     data.save()
     resources.influx_client.post(data.sensor_id, data.value, data.timestamp)
     self.assertEqual(data.value, 25)