示例#1
0
    def testGeoJsonIn(self):
        uri = "/%s/inbox/json/%s" % (self.e.key().id(), TEST_SENSOR_ID)
        lat = 1.3
        lon = 36.9
        MOVE_SIZE = 0.01
        MAX_ACCEL = 10
        N_POINTS = 10
        DELAY_SECS = 1
        now = datetime.now() - timedelta(seconds=60)

        # Populate dummy data with random moves
        data = []
        target_accel_mags = []
        for x in range(N_POINTS):
            now += timedelta(seconds=DELAY_SECS)
            lat += (random.random() - 0.5) * MOVE_SIZE
            lon += (random.random() - 0.5) * MOVE_SIZE
            loc = "%s,%s" % (lat, lon)
            ax = (random.random() * MAX_ACCEL) - MAX_ACCEL / 2
            ay = (random.random() * MAX_ACCEL) - MAX_ACCEL / 2
            az = (random.random() * MAX_ACCEL) - MAX_ACCEL / 2
            accel_mag = math.sqrt(pow(ax, 2) + pow(ay, 2) + pow(az, 2))
            target_accel_mags.append(accel_mag)
            data.append({
                'timestamp': tools.unixtime(dt=now),  # milliseconds
                'location': loc,
                'ax': ax,
                'ay': ay,
                'az': az
            })
        last_loc = loc
        body = json.dumps(data)
        response = self.post(uri, body)
        self.assertEqual(response.status_int, 200)
        content = json.loads(response.normal_body)
        self.assertTrue(content['success'])
        self.assertEqual(content['data']['count'], N_POINTS)

        # Fetch created records from db
        records = Record.Fetch(self.geosensor1)
        self.assertEqual(len(records), N_POINTS)
        last_r = records[0]
        self.assertEqual(tools.unixtime(last_r.dt_recorded),
                         tools.unixtime(now))

        accel_mags = [r.columnValue('accel_mag') for r in records]
        self.assertListEqual(accel_mags, list(reversed(target_accel_mags)))

        # Confirm sensor state update
        self.geosensor1 = Sensor.get(self.geosensor1.key())  # Refetch from db
        self.assertEqual(self.geosensor1.location, db.GeoPt(last_loc))
    def testGeoJsonIn(self):
        uri = "/%s/inbox/json/%s" % (self.e.key().id(), TEST_SENSOR_ID)
        lat = 1.3
        lon = 36.9
        MOVE_SIZE = 0.01
        MAX_ACCEL = 10
        N_POINTS = 10
        DELAY_SECS = 1
        now = datetime.now()

        # Populate dummy data with random moves
        data = []
        target_accel_mags = []
        for x in range(N_POINTS):
            now += timedelta(seconds=DELAY_SECS)
            lat += (random.random()-0.5) * MOVE_SIZE
            lon += (random.random()-0.5) * MOVE_SIZE
            loc = "%s,%s" % (lat, lon)
            ax = (random.random() * MAX_ACCEL) - MAX_ACCEL/2
            ay = (random.random() * MAX_ACCEL) - MAX_ACCEL/2
            az = (random.random() * MAX_ACCEL) - MAX_ACCEL/2
            accel_mag = math.sqrt(pow(ax,2)+pow(ay,2)+pow(az,2))
            target_accel_mags.append(accel_mag)
            data.append({
                'timestamp': tools.unixtime(dt=now),  # milliseconds
                'location': loc,
                'ax': ax,
                'ay': ay,
                'az': az
            })
        last_loc = loc
        body = json.dumps(data)
        response = self.post(uri, body)
        self.assertEqual(response.status_int, 200)
        content = json.loads(response.normal_body)
        self.assertTrue(content['success'])
        self.assertEqual(content['data']['count'], N_POINTS)

        # Fetch created records from db
        records = Record.Fetch(self.geosensor1)
        self.assertEqual(len(records), N_POINTS)
        last_r = records[0]
        self.assertEqual(tools.unixtime(last_r.dt_recorded), tools.unixtime(now))

        accel_mags = [r.columnValue('accel_mag') for r in records]
        self.assertListEqual(accel_mags, list(reversed(target_accel_mags)))

        # Confirm sensor state update
        self.geosensor1 = Sensor.get(self.geosensor1.key())  # Refetch from db
        self.assertEqual(self.geosensor1.location, db.GeoPt(last_loc))
示例#3
0
from external_db import get_all
from models import Sensor, Reading, User, save_external_db_record

# Copy database to local database
readings = get_all()
for reading in readings:
    save_external_db_record(reading)

# Grant sudo user all sensors
sensors = Sensor.get()
sudo = User.find("sudo")

for sensor in sensors:
    sudo.grant_sensor_access(sensor)
示例#4
0
 def testStateUpdates(self):
     self.geosensor1 = Sensor.get(self.geosensor1.key())  # Refetch from db
     self.geosensor1.update_state(COLUMN.LOCATION, NBO_LOC)
     self.assertEqual(self.geosensor1.location, db.GeoPt(NBO_LOC))
 def testStateUpdates(self):
     self.geosensor1 = Sensor.get(self.geosensor1.key())  # Refetch from db
     self.geosensor1.update_state(COLUMN.LOCATION, NBO_LOC)
     self.assertEqual(self.geosensor1.location, db.GeoPt(NBO_LOC))