def create_scenario(admin_id, db_name, data): """Method to create new scenario. Args: admin_id (str): Admin privileges flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. data (dict): Scenario data structure. """ # table = get_db_table(is_admin(admin_id)) scenario = Scenario(name=data['name'], root=is_admin(admin_id), db_name=db_name) try: positions = [] for position in data['positions']: positions.append( Position(name=position["name"], cartesian_coords=position["cartesian_coords"], polar_coords=position["polar_coords"], root=is_admin(admin_id), db_name=db_name, is_for_scenario=True)) scenario.add_positions(positions) scenario_id = scenario.id result = True except Exception: result = False scenario_id = None return result, scenario_id
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 (str): 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_position(admin_id, db_name, position_id, data): """Method to update the position that is recorded in database with given parameters. Args: admin_id (str): Root privileges flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. position_id (str): The id of the position. data (dict): Position data structure. """ table = get_db_table(is_admin(admin_id), db_name) 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_website(admin_id, root, website_id): """Method to return existing website with given id. Args: admin_id (str): Root privileges flag. root (str): Root privileges activation flag. website_id (str): The id of the position. """ result = [] try: if not is_admin(admin_id): root = False else: root = root in ["true", "True"] websites = seer.online_streamer.get_websites(w_ids=[website_id]) if websites: for website in websites: result.append({ "id": website.id, "name": website.name, "url": website.url, "server": website.server, "to_be_used": website.to_be_used, "stream_ids": website.stream_ids }) except Exception as e: logger.error(e) result = [] return result
def get_service(admin_id, root, service_name): """Method to return existing service with given name. Args: admin_id (str): Root privileges flag. root (str): Root privileges activation flag. service_name (str): The name of the remote storage service. """ result = [] try: if not is_admin(admin_id): root = False else: root = root in ["true", "True"] services = r_synchronizer.get_websites(service_names=[service_name]) if services: for service in services: if service.name == "Dropbox": result.append({"name": service.name, "to_be_used": service.to_be_used, "accounts": service.accounts}) except Exception as e: logger.error(e) result = [] return result
def delete_scenario(admin_id, root, db_name, scenario_id): """Method to remove existing position with given id. Args: admin_id (str): Root privileges flag. root (str): Root privileges activation flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. scenario_id (str): The id of the position. """ if not is_admin(admin_id): root = False else: root = root in ["true", "True"] table = get_db_table(root, db_name) if table.search((Query().id == scenario_id)): table.remove((Query().id == scenario_id)) deterfresh_manager(root, db_name) result = True else: result = False return result
def get_position(admin_id, root, db_name, position_id): """Method to return existing position with given id. Args: admin_id (str): Root privileges flag. root (str): Root privileges activation flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. position_id (str): The id of the position. """ try: if not is_admin(admin_id): root = False else: root = root in ["true", "True"] table = get_db_table(root, db_name) position = table.search((Query().id == position_id)) if not position: result = [] else: result = [position[0]] except Exception as e: logger.error(e) result = [] return result
def create_position(admin_id, root, db_name, data): """Method to create new position. Args: admin_id (str): Admin privileges flag. root (str): Root privileges activation flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. data (dict): Position data structure. """ try: if not is_admin(admin_id): root = False else: root = root in ["true", "True"] position = Position(name=data['name'], cartesian_coords=data['cartesian_coords'], polar_params=data['polar_params'], root=root, db_name=db_name) position_id = position.id deterfresh_manager(root, db_name) result = True except Exception: result = False position_id = None return result, position_id
def upsert_website(admin_id, root, data, force_insert=False): """Method to update and insert new website to live streaming. Args: admin_id (str): Admin privileges flag. root (str): Root privileges activation flag. data (dict): website data structure. force_insert (bool): Force insert Flag for updating the website information. """ try: if not is_admin(admin_id): root = False else: root = root in ["true", "True"] if root: result = seer.online_streamer.add_website( data["name"], data["url"], data["server"], force_insert=force_insert) else: result = False except Exception: result = False return result
def create_position(admin_id, db_name, data): """Method to create new position. Args: admin_id (str): Root privileges flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. 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), db_name=db_name) try: result = True position_id = position.id except Exception: result = False position_id = None return result, position_id
def update_scenario(admin_id, db_name, scenario_id, data): """Method to update the scenario that is recorded in database with given parameters. Args: admin_id (str): Root privileges flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. scenario_id (str): The id of the scenario. data (dict): Position data structure. """ root = is_admin(admin_id) table = get_db_table(root, db_name) scenario = table.search((Query().id == scenario_id)) if not scenario: result = False else: Scenario(data['name'], scenario_id, root, db_name).update_all_positions([ Position(name=position["name"], cartesian_coords=position["cartesian_coords"], polar_coords=position["polar_coords"], root=root, db_name=db_name, is_for_scenario=True) for position in data['positions'] ]) result = True return result
def update_identity(admin_id, cause, data): """Method to identity information of T_System as given parameters. Args: admin_id (str): Root privileges flag. cause (str): Key that will be change. data (dict): Identity data structure. """ result = True root = is_admin(admin_id) if cause: if root: if cause == "public_id": identifier.change_keys(public_id=data["public_id"]) elif cause == "private_id": identifier.change_keys(private_id=data["private_id"]) if cause == "name": identifier.change_keys(name=data["name"]) else: result = False else: if root: result = identifier.change_keys(data["public_id"], data["private_id"], data["name"]) else: result = identifier.change_keys(name=data["name"]) return result
def get_scenario(admin_id, root, db_name, scenario_id): """Method to return existing scenario with given id. Args: admin_id (str): Root privileges flag. root (str): Root privileges activation flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. scenario_id (str): The id of the scenario. """ try: if not is_admin(admin_id): root = False else: root = root in ["true", "True"] table = get_db_table(root, db_name) 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: logger.error(e) result = [] return result
def get_logfile(admin_id): """Method to get logfile of log_manager object. Args: admin_id (str): Admin privileges flag. """ if is_admin(admin_id): return log_manager.get_logfile() return False, False
def clear_logs(admin_id): """Method to clear logs that taken from log_manager object. Args: admin_id (str): Admin privileges flag. """ if is_admin(admin_id): return log_manager.clear_logs() return False
def get_ram_usage(admin_id): """Method to provide getting system's ram usage. Args: admin_id: ID of the administration authentication. Returns: dict: Response. """ if is_admin(admin_id): return {"ram_usage_percent": psutil.virtual_memory()[2]} else: return {"ram_usage_percent": None}
def get_cpu_usage(admin_id): """Method to provide getting system's cpu usage. Args: admin_id: ID of the administration authentication. Returns: dict: Response. """ if is_admin(admin_id): return {"cpu_usage_percent": psutil.cpu_percent()} else: return {"cpu_usage_percent": None}
def get_versions(admin_id): """Method to provide getting versions of `t_system`, `remote_ui` and `stand`. Returns: dict: Response. """ if is_admin(admin_id): from t_system import __version__ as t_system_version from t_system.stand import __version__ as stand_version from t_system.remote_ui import __version__ as remote_ui_version return {"versions": {"t_system": t_system_version, "stand": stand_version, "remote_ui": remote_ui_version}} else: return {"versions": {"t_system": None, "stand": None, "remote_ui": None}}
def get_cpu_temperature(admin_id): """Method to provide getting temperature of system's components. Args: admin_id: ID of the administration authentication. Returns: dict: Response. """ if is_admin(admin_id): cpu = CPUTemperature() return {"cpu_temperature": cpu.temperature} else: return {"cpu_temperature": None}
def get_disk_usage(admin_id): """Method to provide getting system's disk usage. Args: admin_id: ID of the administration authentication. Returns: dict: Response. """ usage = psutil.disk_usage('/') if is_admin(admin_id): return {"disk_usage_percent": round(usage.percent, 2), "free_disk_space": round(usage.free / 10**9, 2)} else: return {"disk_usage_percent": round(usage.percent * 1.1, 2), "free_disk_space": round(usage.free / 10**9 * 0.9, 2)}
def get_faces(admin_id): """The high-level method to return existing faces. Args: admin_id (str): Root privileges flag. """ try: table = get_db_table(is_admin(admin_id)) result = table.all() # result = faces except Exception as e: print(e) result = [] return result
def get_identity_info(admin_id): """Method to get identity information of T_System. Args: admin_id (str): Root privileges flag. """ identity_info = { "public_id": identifier.public_id, "private_id": None, "name": identifier.name } if admin_id: if is_admin(admin_id): identity_info["private_id"] = identifier.private_id return identity_info
def delete_scenario(admin_id, scenario_id): """The high-level method to remove existing position with given id. Args: admin_id (str): Root privileges flag. scenario_id (str): The id of the position. """ table = get_db_table(is_admin(admin_id)) if table.search((Query().id == scenario_id)): table.remove((Query().id == scenario_id)) result = True else: result = False return result
def get_scenarios(admin_id, db_name): """Method to return existing scenarios. Args: admin_id (str): Root privileges flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. """ try: table = get_db_table(is_admin(admin_id), db_name) result = table.all() # result = scenarios except Exception as e: logger.error(e) result = [] return result
def delete_position(admin_id, db_name, position_id): """Method to remove existing position with given id. Args: admin_id (str): Root privileges flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. position_id (str): The id of the position. """ table = get_db_table(is_admin(admin_id), db_name) if table.search((Query().id == position_id)): table.remove((Query().id == position_id)) result = True else: result = False return result
def delete_website(admin_id, root, website_id): """Method to remove existing website with given id. Args: admin_id (str): Root privileges flag. root (str): Root privileges activation flag. website_id (str): The id of the website. """ if not is_admin(admin_id): root = False else: root = root in ["true", "True"] if root: result = seer.online_setreamer.remove_websites([website_id]) else: result = False return result
def create_scenario(admin_id, data): """The high-level method to create new scenario. Args: admin_id (str): 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 move_arm_by(admin_id, root, db_name, action, a_type): """Method to get coordinates of T_System's arm current position as polar and cartesian. Args: admin_id (str): Admin privileges flag. root (str): Root privileges flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. action (str): Name of the position or scenario that will simulated. a_type (str): The type of the action. Position or Scenario """ if not is_admin(admin_id): root = False else: root = root in ["true", "True"] if db_name == "emotions": emotion_manager.make_feel(action, a_type) elif db_name in ["missions", "predicted_missions"]: mission_manager.execute(action, a_type, root)
def get_system_info(admin_id): """Method to get system info. Args: admin_id (str): Admin privileges flag. """ multiprocessing.Process(target=i_am_ready).start() root = is_admin(admin_id) result = {} result.update(get_ram_usage(root)) result.update(get_cpu_usage(root)) result.update(get_cpu_temperature(root)) result.update(get_disk_usage(root)) result.update(get_versions(root)) return result
def get_positions(admin_id, root, db_name): """Method to return existing positions. Args: admin_id (str): Root privileges flag. root (str): Root privileges activation flag. db_name (str): Name of the registered Database. It uses if administration privileges activated. """ try: if not is_admin(admin_id): root = False else: root = root in ["true", "True"] table = get_db_table(root, db_name) result = table.all() # result = positions except Exception as e: logger.error(e) result = [] return result