def buildings_building_id_robots_post(buildingId): """ method to post robot under a building """ try: building = Building.get(buildingId) except Exception: return 'Building with id %s does not exist.' % (buildingId) newid = str(uuid.uuid4()) newobj = Robot(id=newid, buildingId=buildingId) newobj.save() return newobj.attribute_values
def buildings_building_id_robots_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 = Robot(id=newID, buildingId=buildingId) newObj.save() return newObj.attribute_values
def robots_get(capability=[]): """ method to get all robots """ resultlist = [] items=[] if capability: items = Robot.scan(capabilities__contains=capability) else: items = Robot.scan() for item in items: resultlist.append(item.attribute_values) return resultlist
def buildings_building_id_robots_get(buildingId, capability = None): resultList = [] try: building = Building.get(buildingId) except Exception as e: return 'Building with id=%s does not exist.' % (buildingId) if capability is not None and capability != '': for item in Robot.scan(buildingId__eq=buildingId, capabilities__contains=capability, conditional_operator='AND'): resultList.append(item.attribute_values) else: for item in Robot.scan(buildingId__eq=buildingId): resultList.append(item.attribute_values) return resultList
def robots_robot_id_get(robotId): """ method to get a robot using robot id """ try: robot = Robot.get(robotId) except Exception: return 'Robot with id=%s does not exist.' % (robotId),404 return robot.attribute_values,200
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 buildings_building_id_robots_get(buildingId, capability=None): resultList = [] try: building = Building.get(buildingId) except Exception as e: return 'Building with id=%s does not exist.' % (buildingId) if capability is not None and capability != '': for item in Robot.scan(buildingId__eq=buildingId, capabilities__contains=capability, conditional_operator='AND'): resultList.append(item.attribute_values) else: for item in Robot.scan(buildingId__eq=buildingId): resultList.append(item.attribute_values) return resultList
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)
def robots_robot_id_get(robotId): """ method to get a robot using robot id """ try: robot = Robot.get(robotId) except Exception: return 'Robot with id=%s does not exist.' % (robotId) return robot.attribute_values
def robots_robot_id_delete(robotId) -> str: try: robot = Robot.get(robotId) robot.delete() except Exception as e: return 'Robot with id=%s does not exist.' % (robotId) return 'Successfully deleted robot with id=%s.' % (robotId)
def robots_robot_id_delete(robotId): """ method to delete a robot using robot id """ try: robot = Robot.get(robotId) robot.delete() except Exception: return 'Robot with id=%s does not exist.' % (robotId) return 'Successfully deleted robot with id=%s.' % (robotId)
def robots_robot_id_delete(robotId): """ method to delete a robot using robot id """ try: robot = Robot.get(robotId) robot.delete() except Exception: return 'Robot with id=%s does not exist.' % (robotId),404 return 'Successfully deleted robot with id=%s.' % (robotId),200
def robots_robot_id_put(robotId, newRobot) -> str: try: robot = Robot.get(robotId) except Exception as e: return 'Robot with id=%s does not exist.' % (robotId) 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)
def buildings_building_id_robots_delete(buildingId) -> str: resultList = [] for item in Robot.scan(buildingId__eq=buildingId): resultList.append(item.delete()) return "%s items deleted." % len(resultList)
def robots_delete() -> str: temp = [] for item in Robot.scan(): temp.append(item.delete()) return "%s items deleted." % len(temp)
def robots_get() -> str: resultList = [] for item in Robot.scan(): resultList.append(item.attribute_values) return resultList
def buildings_building_id_robots_get(buildingId) -> str: resultList = [] for item in Robot.scan(buildingId__eq=buildingId): resultList.append(item.attribute_values) return ( resultList )
def buildings_building_id_robots_delete(buildingId): """ method to delete all robots inside a building """ resultlist = [] for item in Robot.scan(buildingId__eq=buildingId): resultlist.append(item.delete()) return "%s items deleted." % len(resultlist)
def robots_robot_id_get(robotId) -> str: try: robot = Robot.get(robotId) except Exception as e: return 'Robot with id=%s does not exist.' % (robotId) return robot.attribute_values
def robots_delete(): """ method to delete all robots """ temp = [] for item in Robot.scan(): temp.append(item.delete()) return "%s items deleted." % len(temp)
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 robots_get(): """ method to get all robots """ resultlist = [] for item in Robot.scan(): resultlist.append(item.attribute_values) return resultlist
def buildings_building_id_robots_get(buildingId) -> str: resultList = [] for item in Robot.scan(buildingId__eq=buildingId): resultList.append(item.attribute_values) return (resultList)