add func parm type

This commit is contained in:
2025-07-12 17:33:38 +02:00
parent b1ce9061b1
commit 7edaef3563
32 changed files with 301 additions and 75 deletions

View File

@@ -8,14 +8,14 @@ from itertools import islice
logger = logging.getLogger(__name__)
async def get_data(cfg: object, id: int, pool) -> tuple:
async def get_data(cfg: object, id: int, pool: object) -> tuple:
"""
Retrieves unit name, tool name, and tool data for a given record ID from the database.
Args:
cfg (object): Configuration object containing database table name.
id (int): The ID of the record to retrieve.
pool: The database connection pool.
pool (object): The database connection pool.
Returns:
tuple: A tuple containing unit_name, tool_name, and tool_data.
"""
@@ -26,14 +26,14 @@ async def get_data(cfg: object, id: int, pool) -> tuple:
return unit_name, tool_name, tool_data
async def make_pipe_sep_matrix(cfg: object, id: int, pool) -> list:
async def make_pipe_sep_matrix(cfg: object, id: int, pool: object) -> list:
"""
Processes pipe-separated data from a CSV record into a structured matrix.
Args:
cfg (object): Configuration object.
id (int): The ID of the CSV record.
pool: The database connection pool.
pool (object): The database connection pool.
Returns:
list: A list of lists, where each inner list represents a row in the matrix.
"""
@@ -58,14 +58,14 @@ async def make_pipe_sep_matrix(cfg: object, id: int, pool) -> list:
return matrice_valori
async def make_ain_din_matrix(cfg: object, id: int, pool) -> list:
async def make_ain_din_matrix(cfg: object, id: int, pool: object) -> list:
"""
Processes analog and digital input data from a CSV record into a structured matrix.
Args:
cfg (object): Configuration object.
id (int): The ID of the CSV record.
pool: The database connection pool.
pool (object): The database connection pool.
Returns:
list: A list of lists, where each inner list represents a row in the matrix.
"""
@@ -92,14 +92,14 @@ async def make_ain_din_matrix(cfg: object, id: int, pool) -> list:
return matrice_valori
async def make_channels_matrix(cfg: object, id: int, pool) -> list:
async def make_channels_matrix(cfg: object, id: int, pool: object) -> list:
"""
Processes channel-based data from a CSV record into a structured matrix.
Args:
cfg (object): Configuration object.
id (int): The ID of the CSV record.
pool: The database connection pool.
pool (object): The database connection pool.
Returns:
list: A list of lists, where each inner list represents a row in the matrix.
"""
@@ -120,14 +120,14 @@ async def make_channels_matrix(cfg: object, id: int, pool) -> list:
return matrice_valori
async def make_musa_matrix(cfg: object, id: int, pool) -> list:
async def make_musa_matrix(cfg: object, id: int, pool: object) -> list:
"""
Processes 'Musa' specific data from a CSV record into a structured matrix.
Args:
cfg (object): Configuration object.
id (int): The ID of the CSV record.
pool: The database connection pool.
pool (object): The database connection pool.
Returns:
list: A list of lists, where each inner list represents a row in the matrix.
"""
@@ -153,14 +153,14 @@ async def make_musa_matrix(cfg: object, id: int, pool) -> list:
return matrice_valori
async def make_tlp_matrix(cfg: object, id: int, pool) -> list:
async def make_tlp_matrix(cfg: object, id: int, pool: object) -> list:
"""
Processes 'TLP' specific data from a CSV record into a structured matrix.
Args:
cfg (object): Configuration object.
id (int): The ID of the CSV record.
pool: The database connection pool.
pool (object): The database connection pool.
Returns:
list: A list of lists, where each inner list represents a row in the matrix.
"""
@@ -180,14 +180,14 @@ async def make_tlp_matrix(cfg: object, id: int, pool) -> list:
async def make_gd_matrix(cfg: object, id: int, pool) -> list:
async def make_gd_matrix(cfg: object, id: int, pool: object) -> list:
"""
Processes 'GD' specific data from a CSV record into a structured matrix.
Args:
cfg (object): Configuration object.
id (int): The ID of the CSV record.
pool: The database connection pool.
pool (object): The database connection pool.
Returns:
list: A list of lists, where each inner list represents a row in the matrix.
"""

View File

@@ -6,14 +6,14 @@ import logging
logger = logging.getLogger(__name__)
async def main_loader(cfg: object, id: int, pool, action: str) -> None:
async def main_loader(cfg: object, id: int, pool: object, action: str) -> None:
"""
Main loader function to process CSV data based on the specified action.
Args:
cfg (object): Configuration object.
id (int): The ID of the CSV record to process.
pool: The database connection pool.
pool (object): The database connection pool.
action (str): The type of data processing to perform (e.g., "pipe_separator", "analogic_digital").
"""
type_matrix_mapping = {

View File

@@ -1,9 +1,7 @@
import re
def extract_value(patterns: list, primary_source: str, secondary_source: str, default='Not Defined') -> str:
"""Extracts the first match for a list of patterns from the primary source.
Falls back to the secondary source if no match is found.
"""
for source in (primary_source, secondary_source):
for pattern in patterns:
matches = re.findall(pattern, source, re.IGNORECASE)

View File

@@ -7,7 +7,7 @@ logger = logging.getLogger(__name__)
timestamp_cols = ["inserted_at", "loaded_at", "elaborated_at"]
async def load_data(cfg: object, matrice_valori: list, pool) -> bool:
async def load_data(cfg: object, matrice_valori: list, pool: object) -> bool:
"""Carica una lista di record di dati grezzi nel database.
Esegue un'operazione di inserimento massivo (executemany) per caricare i dati.
@@ -17,7 +17,7 @@ async def load_data(cfg: object, matrice_valori: list, pool) -> bool:
Args:
cfg (object): L'oggetto di configurazione contenente i nomi delle tabelle e i parametri di re-tentativo.
matrice_valori (list): Una lista di tuple, dove ogni tupla rappresenta una riga da inserire.
pool: Il pool di connessioni al database.
pool (object): Il pool di connessioni al database.
Returns:
bool: True se il caricamento ha avuto successo, False altrimenti.
@@ -93,14 +93,14 @@ async def load_data(cfg: object, matrice_valori: list, pool) -> bool:
return rc
async def update_status(cfg: object, id: int, status: int, pool) -> None:
async def update_status(cfg: object, id: int, status: int, pool: object) -> None:
"""Aggiorna lo stato di un record nella tabella dei record CSV.
Args:
cfg (object): L'oggetto di configurazione contenente il nome della tabella.
id (int): L'ID del record da aggiornare.
status (int): Il nuovo stato da impostare.
pool: Il pool di connessioni al database.
pool (object): Il pool di connessioni al database.
"""
async with pool.acquire() as conn:
async with conn.cursor() as cur:
@@ -115,7 +115,7 @@ async def update_status(cfg: object, id: int, status: int, pool) -> None:
logging.error(f"Error: {e}")
async def unlock(cfg: object, id: int, pool) -> None:
async def unlock(cfg: object, id: int, pool: object) -> None:
"""Sblocca un record nella tabella dei record CSV.
Imposta il campo 'locked' a 0 per un dato ID.
@@ -123,7 +123,7 @@ async def unlock(cfg: object, id: int, pool) -> None:
Args:
cfg (object): L'oggetto di configurazione contenente il nome della tabella.
id (int): L'ID del record da sbloccare.
pool: Il pool di connessioni al database.
pool (object): Il pool di connessioni al database.
"""
async with pool.acquire() as conn:
async with conn.cursor() as cur:
@@ -138,14 +138,14 @@ async def unlock(cfg: object, id: int, pool) -> None:
logging.error(f"Error: {e}")
async def get_matlab_cmd(cfg: object, unit: str, tool: str, pool) -> tuple:
async def get_matlab_cmd(cfg: object, unit: str, tool: str, pool: object) -> tuple:
"""Recupera le informazioni per l'esecuzione di un comando Matlab dal database.
Args:
cfg (object): L'oggetto di configurazione.
unit (str): Il nome dell'unità.
tool (str): Il nome dello strumento.
pool: Il pool di connessioni al database.
pool (object): Il pool di connessioni al database.
Returns:
tuple: Una tupla contenente le informazioni del comando Matlab, o None in caso di errore.

View File

@@ -3,7 +3,7 @@ import aiomysql
logger = logging.getLogger(__name__)
async def get_matlab_command(cfg: object, tool: str, unit: str, pool) -> tuple:
async def get_matlab_command(cfg: object, tool: str, unit: str, pool: object) -> tuple:
"""Recupera le informazioni per l'esecuzione di un comando Matlab dal database.
Interroga il database per ottenere i dettagli necessari all'avvio di uno script
@@ -13,7 +13,7 @@ async def get_matlab_command(cfg: object, tool: str, unit: str, pool) -> tuple:
cfg (object): L'oggetto di configurazione.
tool (str): Il nome dello strumento.
unit (str): Il nome dell'unità.
pool: Il pool di connessioni al database.
pool (object): Il pool di connessioni al database.
Returns:
tuple: Una tupla contenente le informazioni del comando Matlab,

View File

@@ -4,14 +4,14 @@ import logging
logger = logging.getLogger(__name__)
async def get_nodes_type(cfg: object, tool: str, unit: str, pool) -> tuple:
async def get_nodes_type(cfg: object, tool: str, unit: str, pool: object) -> tuple:
"""Recupera le informazioni sui nodi (tipo, canali, input) per un dato strumento e unità.
Args:
cfg (object): L'oggetto di configurazione.
tool (str): Il nome dello strumento.
unit (str): Il nome dell'unità.
pool: Il pool di connessioni al database.
pool (object): Il pool di connessioni al database.
Returns:
tuple: Una tupla contenente quattro liste: canali, tipi, ain, din.

View File

@@ -10,7 +10,11 @@ from utils.database.connection import connetti_db
logger = logging.getLogger(__name__)
def ftp_SITE_ADDU(self: object, line: str) -> None:
"""Adds a virtual user, creates their directory, and saves their details to the database.
"""
Adds a virtual user, creates their directory, and saves their details to the database.
Args:
line (str): A string containing the username and password separated by a space.
"""
cfg = self.cfg
try:
@@ -51,7 +55,12 @@ def ftp_SITE_ADDU(self: object, line: str) -> None:
print(e)
def ftp_SITE_DISU(self: object, line: str) -> None:
"""Removes a virtual user from the authorizer and marks them as deleted in the database."""
"""
Removes a virtual user from the authorizer and marks them as deleted in the database.
Args:
line (str): A string containing the username to be disabled.
"""
cfg = self.cfg
parms = line.split()
user = os.path.basename(parms[0]) # Extract the username
@@ -78,7 +87,12 @@ def ftp_SITE_DISU(self: object, line: str) -> None:
print(e)
def ftp_SITE_ENAU(self: object, line: str) -> None:
"""Restores a virtual user by updating their status in the database and adding them back to the authorizer."""
"""
Restores a virtual user by updating their status in the database and adding them back to the authorizer.
Args:
line (str): A string containing the username to be enabled.
"""
cfg = self.cfg
parms = line.split()
user = os.path.basename(parms[0]) # Extract the username
@@ -117,7 +131,12 @@ def ftp_SITE_ENAU(self: object, line: str) -> None:
print(e)
def ftp_SITE_LSTU(self: object, line: str) -> None:
"""Lists all virtual users from the database."""
"""
Lists all virtual users from the database.
Args:
line (str): An empty string (no arguments needed for this command).
"""
cfg = self.cfg
users_list = []
try:

View File

@@ -1 +1 @@
"""Parser delle centraline"""
"""Parser delle centraline con le tipologie di unit e tool"""

View File

@@ -1 +1 @@
"""Parser delle centraline"""
"""Parser delle centraline con nomi di unit e tool"""

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'cr1000x_cr1000x'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'd2w_d2w'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as channels_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g201_g201'.
Questa funzione è un wrapper per `channels_main_loader` e passa il tipo
di elaborazione come "channels".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await channels_main_loader(cfg, id, pool,"channels")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g301_g301'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g801_iptm'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as analog_dig_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g801_loc'.
Questa funzione è un wrapper per `analog_dig_main_loader` e passa il tipo
di elaborazione come "analogic_digital".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await analog_dig_main_loader(cfg, id, pool, "analogic_digital")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g801_mums'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as musa_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g801_musa'.
Questa funzione è un wrapper per `musa_main_loader` e passa il tipo
di elaborazione come "musa".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await musa_main_loader(cfg, id, pool, "musa")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as channels_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g801_mux'.
Questa funzione è un wrapper per `channels_main_loader` e passa il tipo
di elaborazione come "channels".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await channels_main_loader(cfg, id, pool, "channels")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g802_dsas'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as gd_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g802_gd'.
Questa funzione è un wrapper per `gd_main_loader` e passa il tipo
di elaborazione come "gd".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await gd_main_loader(cfg, id, pool, "gd")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as analog_dig_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g802_loc'.
Questa funzione è un wrapper per `analog_dig_main_loader` e passa il tipo
di elaborazione come "analogic_digital".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await analog_dig_main_loader(cfg, id, pool, "analogic_digital")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g802_modb'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g802_mums'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as channels_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'g802_mux'.
Questa funzione è un wrapper per `channels_main_loader` e passa il tipo
di elaborazione come "channels".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await channels_main_loader(cfg, id, pool, "channels")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as tlp_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'gs1_gs1'.
Questa funzione è un wrapper per `tlp_main_loader` e passa il tipo
di elaborazione come "tlp".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await tlp_main_loader(cfg, id, pool, "tlp")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as pipe_sep_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'hortus_hortus'.
Questa funzione è un wrapper per `pipe_sep_main_loader` e passa il tipo
di elaborazione come "pipe_separator".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await pipe_sep_main_loader(cfg, id, pool, "pipe_separator")

View File

@@ -9,7 +9,7 @@ import logging
logger = logging.getLogger(__name__)
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
UnitName, ToolNameID, ToolData = await get_data(cfg, id, pool)
# Creare un file temporaneo

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as analog_dig_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'tlp_loc'.
Questa funzione è un wrapper per `analog_dig_main_loader` e passa il tipo
di elaborazione come "analogic_digital".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await analog_dig_main_loader(cfg, id, pool, "analogic_digital")

View File

@@ -1,4 +1,15 @@
from utils.csv.loaders import main_loader as tlp_main_loader
async def main_loader(cfg: object, id: int, pool) -> None:
async def main_loader(cfg: object, id: int, pool: object) -> None:
"""
Carica ed elabora i dati CSV specifici per il tipo 'tlp_tlp'.
Questa funzione è un wrapper per `tlp_main_loader` e passa il tipo
di elaborazione come "tlp".
Args:
cfg (object): L'oggetto di configurazione.
id (int): L'ID del record CSV da elaborare.
pool (object): Il pool di connessioni al database.
"""
await tlp_main_loader(cfg, id, pool, "tlp")