def update_position(admin_id, position_id, data): """The high-level method to update the position that is recorded in database with given parameters. Args: admin_id (bool): Root privileges flag. position_id (str): The id of the position. data (dict): Position data structure. """ table = get_db_table(is_admin(admin_id)) position = table.search((Query().id == position_id)) if not position: result = False else: try: table.update( { 'name': data['name'], 'cartesian_coords': data['cartesian_coords'], 'polar_coords': data['polar_coords'] }, Query().id == position_id) result = True except Exception: result = False return result
def get_face(admin_id, face_id): """The high-level method to return existing face and copying its images under the static folder with given id. Args: admin_id (bool): Root privileges flag. face_id (str): The id of the position. """ try: table = get_db_table(is_admin(admin_id)) face = table.search((Query().id == face_id)) if not face: result = [] else: # result = [b.to_dict() for b in record] face_encode_manager = FaceEncodeManager() for face in face_encode_manager.faces: if face.id == face_id: face.copy_images_to(f'{T_SYSTEM_PATH}/remote_ui/www/static/images/face_encodings') result = [face[0]] except Exception as e: print(e) result = [] return result
def update_scenario(admin_id, scenario_id, data): """The high-level method to update the scenario that is recorded in database with given parameters. Args: admin_id (bool): Root privileges flag. scenario_id (str): The id of the scenario. data (dict): Position data structure. """ table = get_db_table(is_admin(admin_id)) scenario = table.search((Query().id == scenario_id)) if not scenario: result = False else: try: table.update({ 'name': data['name'], 'positions': data['positions'] }, Query().id == scenario_id) result = True except Exception: result = False return result
def get_system_info(admin_id): """The high-level method to get system info. Args: admin_id (bool): Admin privileges flag. """ result = {} if is_admin(admin_id): result.update(get_ram_usage()) result.update(get_cpu_usage()) result.update(get_cpu_temperature()) result.update(get_disk_usage(admin_id)) return result
def get_positions(admin_id): """The high-level method to return existing positions. Args: admin_id (bool): Root privileges flag. """ try: table = get_db_table(is_admin(admin_id)) result = table.all() # result = positions except Exception as e: print(e) result = [] return result
def delete_position(admin_id, position_id): """The high-level method to remove existing position with given id. Args: admin_id (bool): Root privileges flag. position_id (str): The id of the position. """ table = get_db_table(is_admin(admin_id)) if table.search((Query().id == position_id)): table.remove((Query().id == position_id)) result = True else: result = False return result
def create_scenario(admin_id, data): """The high-level method to create new scenario. Args: admin_id (bool): Admin privileges flag. data (dict): Scenario data structure. """ # table = get_db_table(is_admin(admin_id)) scenario = Scenario(name=data['name'], root=is_admin(admin_id)) try: result = True scenario_id = scenario.id except Exception: result = False scenario_id = None return result, scenario_id
def get_position(admin_id, position_id): """The high-level method to return existing position with given id. Args: admin_id (bool): Root privileges flag. position_id (str): The id of the position. """ try: table = get_db_table(is_admin(admin_id)) position = table.search((Query().id == position_id)) if not position: result = [] else: # result = [b.to_dict() for b in record] result = [position[0]] except Exception as e: print(e) result = [] return result
def create_position(admin_id, data): """The high-level method to create new position. Args: admin_id (bool): Root privileges flag. data (dict): Position data structure. """ # table = get_db_table(admin_id) position = Position(name=data['name'], cartesian_coords=data['cartesian_coords'], polar_coords=data['polar_coords'], root=is_admin(admin_id)) try: result = True position_id = position.id except Exception: result = False position_id = None return result, position_id
def get_scenario(admin_id, scenario_id): """The high-level method to return existing scenario with given id. Args: admin_id (bool): Root privileges flag. scenario_id (str): The id of the scenario. """ try: table = get_db_table(is_admin(admin_id)) scenario = table.search((Query().id == scenario_id)) if not scenario: result = [] else: # result = [b.to_dict() for b in record] result = [scenario[0]] except Exception as e: print(e) result = [] return result