def buildings_building_id_sensors_post(buildingId):
    """ method to post a sensor using sensor id """
    try:
        building = Building.get(buildingId)
    except Exception:
        return 'Building with id=%s does not exist.' % (buildingId)
    newid = str(uuid.uuid4())
    newobj = Sensor(id=newid, buildingId=buildingId)
    newobj.save()
    return newobj.attribute_values
Exemple #2
0
def buildings_building_id_sensors_post(buildingId):
    """ method to post a sensor using sensor id """
    try:
        building = Building.get(buildingId)
    except Exception:
        return 'Building with id=%s does not exist.' % (buildingId)
    newid = str(uuid.uuid4())
    newobj = Sensor(id=newid, buildingId=buildingId)
    newobj.save()
    return newobj.attribute_values
def buildings_building_id_sensors_post(buildingId) -> str:
    try:
        building = Building.get(buildingId)
    except Exception as e:
        print(e)
        return 'Building with id=%s does not exist.' % (buildingId)
    newID = str(uuid.uuid4())
    newObj = Sensor(id=newID, buildingId=buildingId)
    newObj.save()
    return newObj.attribute_values
def buildings_building_id_sensors_post(buildingId) -> str:
    try:
        building = Building.get(buildingId)
    except Exception as e:
        print(e)
        return 'Building with id=%s does not exist.' % (buildingId)
    newID = str(uuid.uuid4())
    newObj = Sensor(id=newID, buildingId=buildingId)
    newObj.save()
    return newObj.attribute_values
def sensors_delete(sensor_type=[]):
    """ method to delete sensors by type """
    resultlist = []

    items=[]
    if sensor_type:
       items = Sensor.scan(type__contains=sensor_type)
    else:
       items = Sensor.scan()
    for item in items:
        resultlist.append(item.delete())
    return "%s items deleted." % len(resultlist)
def sensors_get(sensor_type=[]):
    """ method to get sensors by type """
    resultlist = []

    items=[]
    if sensor_type:
        items = Sensor.scan(type__contains=sensor_type)            
    else:
        items = Sensor.scan()          
    for item in items:
        resultlist.append(item.attribute_values)
    return resultlist
def buildings_building_id_sensors_get(buildingId, room=[], type=[]):
    """ method to get sensors using building id """
    resultlist = []
    items = []
    if room and type:
       items = Sensor.scan(buildingId__eq=buildingId,room__eq=room,type__eq=type)
    elif room:
       items = Sensor.scan(buildingId__eq=buildingId,room__eq=room)
    elif type:
       items = Sensor.scan(buildingId__eq=buildingId,type__eq=type)
    else:
       items = Sensor.scan(buildingId__eq=buildingId)
    for item in items:
        resultlist.append(item.attribute_values)
    return resultlist
def sensors_sensor_id_get(sensorId):
    """ method to get a sensor using sensor id """
    try:
        sensor = Sensor.get(sensorId)
    except Exception:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    return sensor.attribute_values
def robots_robot_id_put(robotId, newRobot):
    """ method to update a robot using robot id """
    try:
        robot = Robot.get(robotId)
    except Exception:
        return 'Robot with id=%s does not exist.' % (robotId),404
	
	# Need to check that if building ID is changed, the new Building exists
    if 'buildingId' in newRobot:
    	try:
    		building = Building.get(newRobot['buildingId'])
    	except Exception as e:
    		return 'Building with specified ID does not exist',412
    
    # Do the same for sensor ID
    if 'sensorId' in newRobot:
        for val in newRobot['sensorId']:
     	    try:
     		    #print(val)
     		    sensor = Sensor.get(val)
     	    except Exception as e:
     		    return 'Sensor with specified ID does not exist',412

    attributes = robot.attribute_values.keys()
    for key in newRobot.keys():
        if key in attributes and key!= "id":
            # print(key)
            robot.update_item(key, value=newRobot[key], action='PUT')
    return 'Robot with id=%s updated successfully.' % (robotId),200
def db_put(id,type,newSensor):
    if type not in types:
        return 1

    if type == 'sensor':
        try:
            sensor = Sensor.get(id)
        except Exception:
            return 2
        
        # Need to check that if building ID is changed, the new Building exists
        if 'buildingId' in newSensor:
            try:
                building = Building.get(newSensor['buildingId'])
            except Exception as e:
                return 2

        attributes = sensor.attribute_values.keys()
        for key in newSensor.keys():
            if key in attributes and key != 'id':
                if newSensor[key] == '':
                    sensor.update_item(key, value=' ', action='PUT')
                else:
                    sensor.update_item(key, value=newSensor[key], action='PUT')
    return 0
Exemple #11
0
def sensors_sensor_id_get(sensorId):
    """ method to get a sensor using sensor id """
    try:
        sensor = Sensor.get(sensorId)
    except Exception:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    return sensor.attribute_values
Exemple #12
0
def robots_robot_id_put(robotId, newRobot):
    """ method to update a robot using robot id """
    try:
        robot = Robot.get(robotId)
    except Exception:
        return 'Robot with id=%s does not exist.' % (robotId)

# Need to check that if building ID is changed, the new Building exists
    if 'buildingId' in newRobot:
        try:
            building = Building.get(newRobot['buildingId'])
        except Exception as e:
            return 'Building with specified ID does not exist'

    # Do the same for sensor ID
    if 'sensorId' in newRobot:
        try:
            sensor = Sensor.get(newRobot['sensorId'])
        except Exception as e:
            return 'Sensor with specified ID does not exist'

    attributes = robot.attribute_values.keys()
    for key in newRobot.keys():
        if key in attributes and key is not 'id':
            robot.update_item(key, value=newRobot[key], action='PUT')
    return 'Robot with id=%s updated successfully.' % (robotId)
Exemple #13
0
def sensors_sensor_id_delete(sensorId) -> str:
    try:
        sensor = Sensor.get(sensorId)
        sensor.delete()
    except Exception as e:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    return 'Successfully deleted sensor with id=%s.' % (sensorId)
Exemple #14
0
def sensors_sensor_id_delete(sensorId) -> str:
    try:
        sensor = Sensor.get(sensorId)
        sensor.delete()
    except Exception as e:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    return 'Successfully deleted sensor with id=%s.' % (sensorId)
def sensors_sensor_id_delete(sensorId):
    """ method to delete a sensor using sensor id """
    try:
        sensor = Sensor.get(sensorId)
        sensor.delete()
    except Exception:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    return 'Successfully deleted sensor with id=%s.' % (sensorId)
Exemple #16
0
def buildings_building_id_sensors_get(buildingId, room=[], type=[]):
    """ method to get sensors using building id """
    resultlist = []
    items = []
    if room and type:
        items = Sensor.scan(buildingId__eq=buildingId,
                            room__eq=room,
                            type__eq=type)
    elif room:
        items = Sensor.scan(buildingId__eq=buildingId, room__eq=room)
    elif type:
        items = Sensor.scan(buildingId__eq=buildingId, type__eq=type)
    else:
        items = Sensor.scan(buildingId__eq=buildingId)
    for item in items:
        resultlist.append(item.attribute_values)
    return resultlist
Exemple #17
0
def sensors_sensor_id_delete(sensorId):
    """ method to delete a sensor using sensor id """
    try:
        sensor = Sensor.get(sensorId)
        sensor.delete()
    except Exception:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    return 'Successfully deleted sensor with id=%s.' % (sensorId)
Exemple #18
0
def sensors_sensor_id_put(sensorId, newSensor) -> str:
    try:
        sensor = Sensor.get(sensorId)
    except Exception as e:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    attributes = sensor.attribute_values.keys()
    for key in newSensor.keys():
        if key in attributes and key is not 'id':
            sensor.update_item(key, value=newSensor[key], action='PUT')
    return 'Sensor with id=%s updated successfully.' % (sensorId)
Exemple #19
0
def sensors_sensor_id_put(sensorId, newSensor) -> str:
    try:
        sensor = Sensor.get(sensorId)
    except Exception as e:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    attributes = sensor.attribute_values.keys()
    for key in newSensor.keys():
        if key in attributes and key is not 'id':
            sensor.update_item(key, value=newSensor[key], action='PUT')
    return 'Sensor with id=%s updated successfully.' % (sensorId)
def db_get(id,type):
    if type not in types:
        return [1,'']

    if type == 'sensor':
        try:
            sensor = Sensor.get(id)
            returnList = [0,sensor.attribute_values]
        except Exception:
            return [2,'']
    return returnList
def db_delete(id, type):
    if type not in types:
        return 1
    
    if type == 'sensor':
        try:
            sensor = Sensor.get(id)
            sensor.delete()
        except Exception:
            return 2
    return 0    
def sensors_post(newSensor=[]):
    """ method to post a new sensor """
    newid = str(uuid.uuid4())
    sensor = Sensor(id=newid)
    sensor.save()
    #sensorobj.save()
    #sensor = Sensor.get(newid)
    if newSensor:
        attributes = sensor.attribute_values.keys()
        for key in newSensor.keys():
            if key in attributes and key != 'id':
                if newSensor[key] == '':
                    sensor.update_item(key, value=' ', action='PUT')
                else:
                    sensor.update_item(key, value=newSensor[key], action='PUT')
    return sensor.attribute_values
Exemple #23
0
def sensors_sensor_id_put(sensorId, newSensor):
    """ method to update sensor using sensor id """
    try:
        sensor = Sensor.get(sensorId)
    except Exception:
        return 'Sensor with id=%s does not exist.' % (sensorId)

    # Need to check that if building ID is changed, the new Building exists
    if 'buildingId' in newSensor:
        try:
            building = Building.get(newSensor['buildingId'])
        except Exception as e:
            return 'Building with specified ID does not exist'

    attributes = sensor.attribute_values.keys()
    for key in newSensor.keys():
        if key in attributes and key is not 'id':
            sensor.update_item(key, value=newSensor[key], action='PUT')
    return 'Sensor with id=%s updated successfully.' % (sensorId)
def sensors_sensor_id_put(sensorId, newSensor):
    """ method to update sensor using sensor id """
    try:
        sensor = Sensor.get(sensorId)
    except Exception:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    
    # Need to check that if building ID is changed, the new Building exists
    if 'buildingId' in newSensor:
    	try:
    		building = Building.get(newSensor['buildingId'])
    	except Exception as e:
    		return 'Building with specified ID does not exist'
    
    attributes = sensor.attribute_values.keys()
    for key in newSensor.keys():
        if key in attributes and key is not 'id':
            sensor.update_item(key, value=newSensor[key], action='PUT')
    return 'Sensor with id=%s updated successfully.' % (sensorId)
Exemple #25
0
def sensors_sensor_id_get(sensorId) -> str:
    try:
        sensor = Sensor.get(sensorId)
    except Exception as e:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    return sensor.attribute_values
Exemple #26
0
from storageModels import Sensor, Building, Robot, User

Sensor.create_table(read_capacity_units=1, write_capacity_units=1)
Building.create_table(read_capacity_units=1, write_capacity_units=1)
Robot.create_table(read_capacity_units=1, write_capacity_units=1)
User.create_table(read_capacity_units=1, write_capacity_units=1)
def buildings_building_id_sensors_delete(buildingId):
    """ method to delete sensor using building id """
    resultlist = []
    for item in Sensor.scan(buildingId__eq=buildingId):
        resultlist.append(item.delete())
    return "%s items deleted." % len(resultlist)
Exemple #28
0
def sensors_delete():
    """ method to delete sensor """
    temp = []
    for item in Sensor.scan():
        temp.append(item.delete())
    return "%s items deleted." % len(temp)
Exemple #29
0
def sensors_delete() -> str:
    temp = []
    for item in Sensor.scan():
        temp.append(item.delete())
    return "%s items deleted." % len(temp)
Exemple #30
0
def sensors_get():
    """ method to get all sensors """
    resultlist = []
    for item in Sensor.scan():
        resultlist.append(item.attribute_values)
    return resultlist
Exemple #31
0
def sensors_post():
    """ method to post a new sensor """
    newid = str(uuid.uuid4())
    sensorobj = Sensor(id=newid)
    sensorobj.save()
    return sensorobj.attribute_values
Exemple #32
0
def sensors_post() -> str:
    newID = str(uuid.uuid4())
    sensorObj = Sensor(id=newID)
    sensorObj.save()
    return sensorObj.attribute_values
Exemple #33
0
def sensors_post() -> str:
    newID = str(uuid.uuid4())
    sensorObj = Sensor(id=newID)
    sensorObj.save()
    return sensorObj.attribute_values
Exemple #34
0
def buildings_building_id_sensors_delete(buildingId):
    """ method to delete sensor using building id """
    resultlist = []
    for item in Sensor.scan(buildingId__eq=buildingId):
        resultlist.append(item.delete())
    return "%s items deleted." % len(resultlist)
Exemple #35
0
from storageModels import Sensor, Building

mySens = Sensor(sensorId='yet another id',
                sensorType='type',
                buildingId='theHASH',
                roomId='another hash',
                data=['data', 'moredata'])
mySens.save()

newBuilding = Building(id='one other id something',
                       buildingId='1',
                       building='Franks shop',
                       rooms=['a', 'b'],
                       owner=1,
                       users=['a', 'b'],
                       sensors=['a', 'b'],
                       robots=['a', 'b'])
newBuilding.save()
Exemple #36
0
def buildings_building_id_sensors_delete(buildingId) -> str:
    resultList = []
    for item in Sensor.scan(buildingId__eq=buildingId):
        resultList.append(item.delete())
    return "%s items deleted." % len(resultList)
Exemple #37
0
def buildings_building_id_sensors_get(buildingId) -> str:
    resultList = []
    for item in Sensor.scan(buildingId__eq=buildingId):
        resultList.append(item.attribute_values)
    return ( resultList )
Exemple #38
0
def sensors_sensor_id_get(sensorId) -> str:
    try:
        sensor = Sensor.get(sensorId)
    except Exception as e:
        return 'Sensor with id=%s does not exist.' % (sensorId)
    return sensor.attribute_values
Exemple #39
0
def sensors_get() -> str:
    resultList = []
    for item in Sensor.scan():
        resultList.append(item.attribute_values)
    return resultList
def sensors_delete():
    """ method to delete sensor """
    temp = []
    for item in Sensor.scan():
        temp.append(item.delete())
    return "%s items deleted." % len(temp)
Exemple #41
0
def sensors_delete() -> str:
    temp = []
    for item in Sensor.scan():
        temp.append(item.delete())
    return "%s items deleted." % len(temp)
Exemple #42
0
def sensors_get() -> str:
    resultList = []
    for item in Sensor.scan():
        resultList.append(item.attribute_values)
    return resultList
def sensors_get():
    """ method to get all sensors """
    resultlist = []
    for item in Sensor.scan():
        resultlist.append(item.attribute_values)
    return resultlist
Exemple #44
0
def buildings_building_id_sensors_delete(buildingId) -> str:
    resultList = []
    for item in Sensor.scan(buildingId__eq=buildingId):
        resultList.append(item.delete())
    return "%s items deleted." % len(resultList)
def sensors_post():
    """ method to post a new sensor """
    newid = str(uuid.uuid4())
    sensorobj = Sensor(id=newid)
    sensorobj.save()
    return sensorobj.attribute_values
Exemple #46
0
from storageModels import Sensor, Building


mySens = Sensor(sensorId = 'yet another id',
                sensorType='type',
                buildingId = 'theHASH',
                roomId = 'another hash',
                data=['data', 'moredata'])
mySens.save()


newBuilding = Building(id = 'one other id something',
                       buildingId = '1',
                       building='Franks shop',
                       rooms = ['a', 'b'],
                       owner = 1,
                       users = ['a', 'b'],
                       sensors = ['a', 'b'],
                       robots = ['a', 'b'])
newBuilding.save()
Exemple #47
0
def buildings_building_id_sensors_get(buildingId) -> str:
    resultList = []
    for item in Sensor.scan(buildingId__eq=buildingId):
        resultList.append(item.attribute_values)
    return (resultList)