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
예제 #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
예제 #3
0
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
예제 #4
0
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
예제 #8
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
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
예제 #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
예제 #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)
예제 #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)
예제 #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)
예제 #15
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)
예제 #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
예제 #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)
예제 #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)
예제 #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
예제 #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)
예제 #24
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)
예제 #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
예제 #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)
예제 #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)
예제 #29
0
def sensors_delete() -> str:
    temp = []
    for item in Sensor.scan():
        temp.append(item.delete())
    return "%s items deleted." % len(temp)
예제 #30
0
def sensors_get():
    """ method to get all sensors """
    resultlist = []
    for item in Sensor.scan():
        resultlist.append(item.attribute_values)
    return resultlist
예제 #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
예제 #32
0
def sensors_post() -> str:
    newID = str(uuid.uuid4())
    sensorObj = Sensor(id=newID)
    sensorObj.save()
    return sensorObj.attribute_values
예제 #33
0
def sensors_post() -> str:
    newID = str(uuid.uuid4())
    sensorObj = Sensor(id=newID)
    sensorObj.save()
    return sensorObj.attribute_values
예제 #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)
예제 #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()
예제 #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)
예제 #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 )
예제 #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
예제 #39
0
def sensors_get() -> str:
    resultList = []
    for item in Sensor.scan():
        resultList.append(item.attribute_values)
    return resultList
예제 #40
0
def sensors_delete():
    """ method to delete sensor """
    temp = []
    for item in Sensor.scan():
        temp.append(item.delete())
    return "%s items deleted." % len(temp)
예제 #41
0
def sensors_delete() -> str:
    temp = []
    for item in Sensor.scan():
        temp.append(item.delete())
    return "%s items deleted." % len(temp)
예제 #42
0
def sensors_get() -> str:
    resultList = []
    for item in Sensor.scan():
        resultList.append(item.attribute_values)
    return resultList
예제 #43
0
def sensors_get():
    """ method to get all sensors """
    resultlist = []
    for item in Sensor.scan():
        resultlist.append(item.attribute_values)
    return resultlist
예제 #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)
예제 #45
0
def sensors_post():
    """ method to post a new sensor """
    newid = str(uuid.uuid4())
    sensorobj = Sensor(id=newid)
    sensorobj.save()
    return sensorobj.attribute_values
예제 #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()
예제 #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)