mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-20 23:12:53 +02:00
Removed dead docstrings
This commit is contained in:
parent
609599f9f3
commit
1785114ec1
@ -11,14 +11,7 @@ test_company = 13 # 2213 # 13
|
|||||||
|
|
||||||
|
|
||||||
def find_company_relations(company_id: int) -> pd.DataFrame:
|
def find_company_relations(company_id: int) -> pd.DataFrame:
|
||||||
"""_summary_.
|
"""_summary_."""
|
||||||
|
|
||||||
Args:
|
|
||||||
company_id (int): _description_
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
pd.DataFrame: _description_
|
|
||||||
"""
|
|
||||||
session = connector.get_session(JsonFileConfigProvider("./secrets.json"))
|
session = connector.get_session(JsonFileConfigProvider("./secrets.json"))
|
||||||
query_companies = session.query(entities.Company)
|
query_companies = session.query(entities.Company)
|
||||||
query_relations = session.query(entities.CompanyRelation)
|
query_relations = session.query(entities.CompanyRelation)
|
||||||
@ -54,14 +47,7 @@ def find_company_relations(company_id: int) -> pd.DataFrame:
|
|||||||
|
|
||||||
# Plotly figure
|
# Plotly figure
|
||||||
def network_graph(company_id: int) -> go.Figure:
|
def network_graph(company_id: int) -> go.Figure:
|
||||||
"""_summary_.
|
"""_summary_."""
|
||||||
|
|
||||||
Args:
|
|
||||||
company_id (int): _description_
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
go.Figure: _description_
|
|
||||||
"""
|
|
||||||
edges = []
|
edges = []
|
||||||
for _, row in find_company_relations(company_id).iterrows():
|
for _, row in find_company_relations(company_id).iterrows():
|
||||||
edges.append([row["company_name"], row["connected_company_name"]])
|
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:
|
def networkx_component(company_id: int) -> html.Div:
|
||||||
"""Retruns the Layout with a Graph.
|
"""Returns the Layout with a Graph."""
|
||||||
|
|
||||||
Args:
|
|
||||||
company_id (int): _description_
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
any: _description_
|
|
||||||
"""
|
|
||||||
return html.Div(
|
return html.Div(
|
||||||
[
|
[
|
||||||
dcc.Graph(id="my-graph", figure=network_graph(company_id)),
|
dcc.Graph(id="my-graph", figure=network_graph(company_id)),
|
||||||
|
@ -11,11 +11,7 @@ test_company = 13 # 2213 # 13
|
|||||||
|
|
||||||
|
|
||||||
def find_all_company_relations() -> pd.DataFrame:
|
def find_all_company_relations() -> pd.DataFrame:
|
||||||
"""Searches for all companies and their relation in the DB.
|
"""Searches for all companies and their relation in the DB."""
|
||||||
|
|
||||||
Returns:
|
|
||||||
pd.DataFrame: _description_
|
|
||||||
"""
|
|
||||||
session = connector.get_session(JsonFileConfigProvider("./secrets.json"))
|
session = connector.get_session(JsonFileConfigProvider("./secrets.json"))
|
||||||
query_companies = session.query(entities.Company) # .all()
|
query_companies = session.query(entities.Company) # .all()
|
||||||
query_relations = session.query(entities.CompanyRelation) # .all()
|
query_relations = session.query(entities.CompanyRelation) # .all()
|
||||||
@ -57,11 +53,7 @@ def find_all_company_relations() -> pd.DataFrame:
|
|||||||
|
|
||||||
# Plotly figure
|
# Plotly figure
|
||||||
def create_network_graph() -> go.Figure:
|
def create_network_graph() -> go.Figure:
|
||||||
"""Create a NetworkX Graph.
|
"""Create a NetworkX Graph."""
|
||||||
|
|
||||||
Returns:
|
|
||||||
go.Figure: _description_
|
|
||||||
"""
|
|
||||||
edges = []
|
edges = []
|
||||||
for _, row in find_all_company_relations().iterrows():
|
for _, row in find_all_company_relations().iterrows():
|
||||||
edges.append([row["company_name"], row["connected_company_name"]])
|
edges.append([row["company_name"], row["connected_company_name"]])
|
||||||
|
@ -13,11 +13,7 @@ class CompanyMongoService:
|
|||||||
"""Wrapper for MongoDB regarding management of Company documents."""
|
"""Wrapper for MongoDB regarding management of Company documents."""
|
||||||
|
|
||||||
def __init__(self, connector: MongoConnector):
|
def __init__(self, connector: MongoConnector):
|
||||||
"""Constructor.
|
"""Constructor."""
|
||||||
|
|
||||||
Args:
|
|
||||||
connector (MongoConnector): _description_
|
|
||||||
"""
|
|
||||||
self.collection = connector.database["companies"]
|
self.collection = connector.database["companies"]
|
||||||
self.lock = Lock() # Create a lock for synchronization
|
self.lock = Lock() # Create a lock for synchronization
|
||||||
|
|
||||||
@ -137,14 +133,7 @@ class CompanyMongoService:
|
|||||||
return malformed_entries
|
return malformed_entries
|
||||||
|
|
||||||
def insert(self, company: Company) -> InsertOneResult:
|
def insert(self, company: Company) -> InsertOneResult:
|
||||||
"""Insert a new Company document.
|
"""Insert a new Company document."""
|
||||||
|
|
||||||
Args:
|
|
||||||
company (Company): _description_
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
_description_
|
|
||||||
"""
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
return self.collection.insert_one(company.to_dict())
|
return self.collection.insert_one(company.to_dict())
|
||||||
|
|
||||||
|
@ -9,11 +9,7 @@ class MongoNewsService:
|
|||||||
"""Wrapper for MongoDB regarding News documents."""
|
"""Wrapper for MongoDB regarding News documents."""
|
||||||
|
|
||||||
def __init__(self, connector: MongoConnector):
|
def __init__(self, connector: MongoConnector):
|
||||||
"""Constructor.
|
"""Constructor."""
|
||||||
|
|
||||||
Args:
|
|
||||||
connector (MongoConnector): _description_
|
|
||||||
"""
|
|
||||||
self.collection = connector.database["news"]
|
self.collection = connector.database["news"]
|
||||||
|
|
||||||
def get_all(self) -> list[News]:
|
def get_all(self) -> list[News]:
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
"""Module to receive and filter Data for working with NetworkX."""
|
"""Module to receive and filter Data for working with NetworkX."""
|
||||||
|
import os
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
from cachetools import TTLCache, cached
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
|
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
|
||||||
@ -24,12 +26,11 @@ COLOR_COMPANY = "#006250"
|
|||||||
COLOR_PERSON = "#ff5200"
|
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:
|
def find_all_company_relations() -> pd.DataFrame:
|
||||||
"""_summary_.
|
"""_summary_."""
|
||||||
|
|
||||||
Returns:
|
|
||||||
pd.DataFrame: _description_
|
|
||||||
"""
|
|
||||||
session = SessionHandler.session
|
session = SessionHandler.session
|
||||||
assert session # noqa: S101
|
assert session # noqa: S101
|
||||||
query_companies = session.query(entities.Company) # .all()
|
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:
|
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:
|
Returns:
|
||||||
DataFrame: DataFrame with all Relations between Companies.
|
DataFrame: DataFrame with all Relations between Companies.
|
||||||
@ -102,7 +103,11 @@ def get_all_company_relations() -> pd.DataFrame:
|
|||||||
return company_relations
|
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.
|
"""These method makes a Database Request for all Persons and their relations, modifies the ID Column and returns the Result as an DataFrame.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -137,7 +142,8 @@ def get_all_person_relations() -> pd.DataFrame:
|
|||||||
person_relations["id_person"] = person_relations["id_person"].apply(
|
person_relations["id_person"] = person_relations["id_person"].apply(
|
||||||
lambda x: f"p_{x}"
|
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
|
return person_relations
|
||||||
|
|
||||||
|
|
||||||
@ -163,15 +169,7 @@ def filter_relation_type(
|
|||||||
def create_edge_and_node_list(
|
def create_edge_and_node_list(
|
||||||
person_relations: pd.DataFrame, company_relations: pd.DataFrame
|
person_relations: pd.DataFrame, company_relations: pd.DataFrame
|
||||||
) -> tuple[dict, list]:
|
) -> 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.
|
"""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_
|
|
||||||
"""
|
|
||||||
nodes: dict = {}
|
nodes: dict = {}
|
||||||
edges: list = []
|
edges: list = []
|
||||||
|
|
||||||
@ -332,15 +330,7 @@ def find_person_relations(
|
|||||||
def create_edge_and_node_list_for_company(
|
def create_edge_and_node_list_for_company(
|
||||||
company_relations: pd.DataFrame,
|
company_relations: pd.DataFrame,
|
||||||
) -> tuple[dict, list]:
|
) -> 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.
|
"""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_
|
|
||||||
"""
|
|
||||||
nodes: dict = {}
|
nodes: dict = {}
|
||||||
edges: list = []
|
edges: list = []
|
||||||
|
|
||||||
@ -374,12 +364,9 @@ def get_all_metrics_from_id(company_id: int) -> pd.Series:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
company_id (int): Id of the Company.
|
company_id (int): Id of the Company.
|
||||||
|
|
||||||
Returns:
|
|
||||||
pd.DataFrame: _description_
|
|
||||||
"""
|
"""
|
||||||
# Get Data
|
# Get Data
|
||||||
person_df = get_all_person_relations()
|
person_df = get_all_person_relations(False)
|
||||||
company_df = get_all_company_relations()
|
company_df = get_all_company_relations()
|
||||||
|
|
||||||
# Create Edge and Node List from data
|
# Create Edge and Node List from data
|
||||||
@ -412,11 +399,9 @@ def get_relations_number_from_id(id: str) -> tuple[int, int, int]:
|
|||||||
Args:
|
Args:
|
||||||
id: String of the Company or Person Id.
|
id: String of the Company or Person Id.
|
||||||
|
|
||||||
Returns:
|
|
||||||
tuple[int,int,int]: _description_
|
|
||||||
"""
|
"""
|
||||||
# Get Data
|
# Get Data
|
||||||
person_df = get_all_person_relations()
|
person_df = get_all_person_relations(False)
|
||||||
company_df = get_all_company_relations()
|
company_df = get_all_company_relations()
|
||||||
|
|
||||||
# Create Edge and Node List from data
|
# 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
|
tuple[dict, list]: nodes, edges
|
||||||
"""
|
"""
|
||||||
# Get Data
|
# Get Data
|
||||||
person_df = get_all_person_relations()
|
person_df = get_all_person_relations(False)
|
||||||
company_df = get_all_company_relations()
|
company_df = get_all_company_relations()
|
||||||
|
|
||||||
# Create Edge and Node List from data
|
# Create Edge and Node List from data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user