From 1785114ec138ea4ca598a30453c252f79ef1f033 Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Thu, 11 Jan 2024 00:39:11 +0100 Subject: [PATCH] Removed dead docstrings --- .../NetworkX/archive_prod/networkx_dash.py | 27 ++-------- .../archive_prod/networkx_dash_overall.py | 12 +---- .../utils/mongo/company_mongo_service.py | 15 +----- .../utils/mongo/news_mongo_service.py | 6 +-- .../utils/networkx/networkx_data.py | 53 +++++++------------ 5 files changed, 27 insertions(+), 86 deletions(-) diff --git a/Jupyter/NetworkX/archive_prod/networkx_dash.py b/Jupyter/NetworkX/archive_prod/networkx_dash.py index 5700b19..0b6c1af 100644 --- a/Jupyter/NetworkX/archive_prod/networkx_dash.py +++ b/Jupyter/NetworkX/archive_prod/networkx_dash.py @@ -11,14 +11,7 @@ test_company = 13 # 2213 # 13 def find_company_relations(company_id: int) -> pd.DataFrame: - """_summary_. - - Args: - company_id (int): _description_ - - Returns: - pd.DataFrame: _description_ - """ + """_summary_.""" session = connector.get_session(JsonFileConfigProvider("./secrets.json")) query_companies = session.query(entities.Company) query_relations = session.query(entities.CompanyRelation) @@ -54,14 +47,7 @@ def find_company_relations(company_id: int) -> pd.DataFrame: # Plotly figure def network_graph(company_id: int) -> go.Figure: - """_summary_. - - Args: - company_id (int): _description_ - - Returns: - go.Figure: _description_ - """ + """_summary_.""" edges = [] for _, row in find_company_relations(company_id).iterrows(): edges.append([row["company_name"], row["connected_company_name"]]) @@ -136,14 +122,7 @@ def network_graph(company_id: int) -> go.Figure: def networkx_component(company_id: int) -> html.Div: - """Retruns the Layout with a Graph. - - Args: - company_id (int): _description_ - - Returns: - any: _description_ - """ + """Returns the Layout with a Graph.""" return html.Div( [ dcc.Graph(id="my-graph", figure=network_graph(company_id)), diff --git a/Jupyter/NetworkX/archive_prod/networkx_dash_overall.py b/Jupyter/NetworkX/archive_prod/networkx_dash_overall.py index 5bedccd..183e1da 100644 --- a/Jupyter/NetworkX/archive_prod/networkx_dash_overall.py +++ b/Jupyter/NetworkX/archive_prod/networkx_dash_overall.py @@ -11,11 +11,7 @@ test_company = 13 # 2213 # 13 def find_all_company_relations() -> pd.DataFrame: - """Searches for all companies and their relation in the DB. - - Returns: - pd.DataFrame: _description_ - """ + """Searches for all companies and their relation in the DB.""" session = connector.get_session(JsonFileConfigProvider("./secrets.json")) query_companies = session.query(entities.Company) # .all() query_relations = session.query(entities.CompanyRelation) # .all() @@ -57,11 +53,7 @@ def find_all_company_relations() -> pd.DataFrame: # Plotly figure def create_network_graph() -> go.Figure: - """Create a NetworkX Graph. - - Returns: - go.Figure: _description_ - """ + """Create a NetworkX Graph.""" edges = [] for _, row in find_all_company_relations().iterrows(): edges.append([row["company_name"], row["connected_company_name"]]) diff --git a/src/aki_prj23_transparenzregister/utils/mongo/company_mongo_service.py b/src/aki_prj23_transparenzregister/utils/mongo/company_mongo_service.py index 16d00fb..38a02ee 100644 --- a/src/aki_prj23_transparenzregister/utils/mongo/company_mongo_service.py +++ b/src/aki_prj23_transparenzregister/utils/mongo/company_mongo_service.py @@ -13,11 +13,7 @@ class CompanyMongoService: """Wrapper for MongoDB regarding management of Company documents.""" def __init__(self, connector: MongoConnector): - """Constructor. - - Args: - connector (MongoConnector): _description_ - """ + """Constructor.""" self.collection = connector.database["companies"] self.lock = Lock() # Create a lock for synchronization @@ -137,14 +133,7 @@ class CompanyMongoService: return malformed_entries def insert(self, company: Company) -> InsertOneResult: - """Insert a new Company document. - - Args: - company (Company): _description_ - - Returns: - _description_ - """ + """Insert a new Company document.""" with self.lock: return self.collection.insert_one(company.to_dict()) diff --git a/src/aki_prj23_transparenzregister/utils/mongo/news_mongo_service.py b/src/aki_prj23_transparenzregister/utils/mongo/news_mongo_service.py index 6143e02..cc39dd5 100644 --- a/src/aki_prj23_transparenzregister/utils/mongo/news_mongo_service.py +++ b/src/aki_prj23_transparenzregister/utils/mongo/news_mongo_service.py @@ -9,11 +9,7 @@ class MongoNewsService: """Wrapper for MongoDB regarding News documents.""" def __init__(self, connector: MongoConnector): - """Constructor. - - Args: - connector (MongoConnector): _description_ - """ + """Constructor.""" self.collection = connector.database["news"] def get_all(self) -> list[News]: diff --git a/src/aki_prj23_transparenzregister/utils/networkx/networkx_data.py b/src/aki_prj23_transparenzregister/utils/networkx/networkx_data.py index 47aebd8..9249469 100644 --- a/src/aki_prj23_transparenzregister/utils/networkx/networkx_data.py +++ b/src/aki_prj23_transparenzregister/utils/networkx/networkx_data.py @@ -1,8 +1,10 @@ """Module to receive and filter Data for working with NetworkX.""" +import os from functools import lru_cache import networkx as nx import pandas as pd +from cachetools import TTLCache, cached from sqlalchemy.orm import aliased from aki_prj23_transparenzregister.ui.session_handler import SessionHandler @@ -24,12 +26,11 @@ COLOR_COMPANY = "#006250" COLOR_PERSON = "#ff5200" +@cached( # type: ignore + cache=TTLCache(maxsize=100, ttl=int(os.getenv("PYTHON_CACHE_TTL", "3600"))) +) def find_all_company_relations() -> pd.DataFrame: - """_summary_. - - Returns: - pd.DataFrame: _description_ - """ + """_summary_.""" session = SessionHandler.session assert session # noqa: S101 query_companies = session.query(entities.Company) # .all() @@ -64,7 +65,7 @@ def find_all_company_relations() -> pd.DataFrame: def get_all_company_relations() -> pd.DataFrame: - """This Methods makes a Database Request for all Companies and their relations, modifies the ID Column and returns the Result as an DataFrame. + """Makes a Database Request for all Companies and their relations, modifies the ID Column and returns the Result as an DataFrame. Returns: DataFrame: DataFrame with all Relations between Companies. @@ -102,7 +103,11 @@ def get_all_company_relations() -> pd.DataFrame: return company_relations -def get_all_person_relations() -> pd.DataFrame: +@cached( # type: ignore + cache=TTLCache(maxsize=100, ttl=int(os.getenv("PYTHON_CACHE_TTL", "3600"))), + key=lambda drop_min_person_links: hash(drop_min_person_links), +) +def get_all_person_relations(drop_min_person_links: bool) -> pd.DataFrame: """These method makes a Database Request for all Persons and their relations, modifies the ID Column and returns the Result as an DataFrame. Returns: @@ -137,7 +142,8 @@ def get_all_person_relations() -> pd.DataFrame: person_relations["id_person"] = person_relations["id_person"].apply( lambda x: f"p_{x}" ) - + if drop_min_person_links: + return person_relations.groupby("id_person").filter(lambda x: len(x) > 1) return person_relations @@ -163,15 +169,7 @@ def filter_relation_type( def create_edge_and_node_list( person_relations: pd.DataFrame, company_relations: pd.DataFrame ) -> tuple[dict, list]: - """In this Method the given DataFrames with the relation will be morphed to Edge and Node lists and enhanced by a coloring for companies and person Nodes. - - Args: - person_relations (pd.DataFrame): _description_ - company_relations (pd.DataFrame): _description_ - - Returns: - _description_ - """ + """In this Method the given DataFrames with the relation will be morphed to Edge and Node lists and enhanced by a coloring for companies and person Nodes.""" nodes: dict = {} edges: list = [] @@ -332,15 +330,7 @@ def find_person_relations( def create_edge_and_node_list_for_company( company_relations: pd.DataFrame, ) -> tuple[dict, list]: - """In this Method the given DataFrames with the relation will be morphed to Edge and Node lists and enhanced by a coloring for companies and person Nodes. - - Args: - person_relations (pd.DataFrame): _description_ - company_relations (pd.DataFrame): _description_ - - Returns: - _description_ - """ + """In this Method the given DataFrames with the relation will be morphed to Edge and Node lists and enhanced by a coloring for companies and person Nodes.""" nodes: dict = {} edges: list = [] @@ -374,12 +364,9 @@ def get_all_metrics_from_id(company_id: int) -> pd.Series: Args: company_id (int): Id of the Company. - - Returns: - pd.DataFrame: _description_ """ # Get Data - person_df = get_all_person_relations() + person_df = get_all_person_relations(False) company_df = get_all_company_relations() # Create Edge and Node List from data @@ -412,11 +399,9 @@ def get_relations_number_from_id(id: str) -> tuple[int, int, int]: Args: id: String of the Company or Person Id. - Returns: - tuple[int,int,int]: _description_ """ # Get Data - person_df = get_all_person_relations() + person_df = get_all_person_relations(False) company_df = get_all_company_relations() # Create Edge and Node List from data @@ -457,7 +442,7 @@ def get_relations_until_level_3(id: str) -> tuple[dict, list]: tuple[dict, list]: nodes, edges """ # Get Data - person_df = get_all_person_relations() + person_df = get_all_person_relations(False) company_df = get_all_company_relations() # Create Edge and Node List from data