reorg parsers
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!.venv/bin/python
|
||||
from utils.database.connection import connetti_db
|
||||
from utils.database.nodes_query import get_nodes_type
|
||||
import utils.timestamp.date_check as date_check
|
||||
import logging
|
||||
import re
|
||||
@@ -32,7 +33,7 @@ def get_data(cfg: object, id: int) -> tuple:
|
||||
conn.close()
|
||||
return unit_name, tool_name, tool_data
|
||||
|
||||
def make_matrix(cfg: object, id: int) -> list:
|
||||
def make_pipe_sep_matrix(cfg: object, id: int) -> list:
|
||||
"""
|
||||
Processes raw tool data and transforms it into a matrix format for database insertion.
|
||||
|
||||
@@ -67,7 +68,7 @@ def make_matrix(cfg: object, id: int) -> list:
|
||||
|
||||
return matrice_valori
|
||||
|
||||
def make_loc_matrix(cfg: object, id: int) -> list:
|
||||
def make_ain_din_matrix(cfg: object, id: int) -> list:
|
||||
"""
|
||||
Processes raw location (LOC) tool data and transforms it into a matrix format for database insertion.
|
||||
|
||||
@@ -101,7 +102,7 @@ def make_loc_matrix(cfg: object, id: int) -> list:
|
||||
|
||||
return matrice_valori
|
||||
|
||||
def make_matrix_with_channels(cfg: object, id: int, node_channels: list) -> list:
|
||||
def make_channels_matrix(cfg: object, id: int) -> list:
|
||||
UnitName, ToolNameID, ToolData = get_data(cfg, id)
|
||||
righe = ToolData.splitlines()
|
||||
matrice_valori = []
|
||||
@@ -110,11 +111,11 @@ def make_matrix_with_channels(cfg: object, id: int, node_channels: list) -> list
|
||||
EventDate, EventTime = timestamp.split(' ')
|
||||
valori_splitted = [valore for valore in rilevazioni.split(';') if valore != '|']
|
||||
valori_iter = iter(valori_splitted)
|
||||
node_channels, node_types, node_ains, node_dins = get_nodes_type(cfg, ToolNameID, UnitName)
|
||||
|
||||
valori_nodi = [list(islice(valori_iter, channels)) for channels in node_channels]
|
||||
|
||||
for num_nodo, valori in enumerate(valori_nodi, start=1):
|
||||
matrice_valori.append([UnitName, ToolNameID, num_nodo, date_check.conforma_data(EventDate), EventTime, batlevel, temperature] + valori + ([None] * (19 - len(valori))))
|
||||
|
||||
return matrice_valori
|
||||
|
||||
|
||||
|
||||
22
utils/csv/loaders.py
Normal file
22
utils/csv/loaders.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from utils.database.loader_action import load_data, update_status, DATA_LOADED
|
||||
from utils.csv.data_preparation import make_pipe_sep_matrix, make_ain_din_matrix, make_channels_matrix
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def main_loader(cfg: object, id: int, action: str) -> None:
|
||||
type_matrix_mapping = {
|
||||
"pipe_separator": make_pipe_sep_matrix,
|
||||
"analogic_digital": make_ain_din_matrix,
|
||||
"channels": make_channels_matrix
|
||||
}
|
||||
if action in type_matrix_mapping:
|
||||
function_to_call = type_matrix_mapping[action]
|
||||
# Create a matrix of values from the data
|
||||
matrice_valori = function_to_call(cfg, id)
|
||||
# Load the data into the database
|
||||
if load_data(cfg, matrice_valori):
|
||||
update_status(cfg, id, DATA_LOADED)
|
||||
else:
|
||||
logger.warning(f"Action '{action}' non riconosciuta.")
|
||||
1
utils/parsers/by_name/__init__.py
Normal file
1
utils/parsers/by_name/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Parser delle centraline"""
|
||||
1
utils/parsers/by_type/__init__.py
Normal file
1
utils/parsers/by_type/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Parser delle centraline"""
|
||||
4
utils/parsers/by_type/cr1000x_cr1000x.py
Normal file
4
utils/parsers/by_type/cr1000x_cr1000x.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
4
utils/parsers/by_type/d2w_d2w.py
Normal file
4
utils/parsers/by_type/d2w_d2w.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
4
utils/parsers/by_type/g301_g301.py
Normal file
4
utils/parsers/by_type/g301_g301.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
4
utils/parsers/by_type/g801_iptm.py
Normal file
4
utils/parsers/by_type/g801_iptm.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
4
utils/parsers/by_type/g801_loc.py
Normal file
4
utils/parsers/by_type/g801_loc.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as analog_dig_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return analog_dig_main_loader(cfg, id, "analogic_digital")
|
||||
4
utils/parsers/by_type/g801_mums.py
Normal file
4
utils/parsers/by_type/g801_mums.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
4
utils/parsers/by_type/g802_dsas.py
Normal file
4
utils/parsers/by_type/g802_dsas.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
4
utils/parsers/by_type/g802_loc.py
Normal file
4
utils/parsers/by_type/g802_loc.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as analog_dig_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return analog_dig_main_loader(cfg, id, "analogic_digital")
|
||||
4
utils/parsers/by_type/g802_modb.py
Normal file
4
utils/parsers/by_type/g802_modb.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
4
utils/parsers/by_type/g802_mums.py
Normal file
4
utils/parsers/by_type/g802_mums.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
@@ -1,4 +1,4 @@
|
||||
from .tlp_tlp import main_loader as tlp_tlp_main_loader
|
||||
from ..tlp_tlp import main_loader as tlp_tlp_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return tlp_tlp_main_loader(cfg, id)
|
||||
4
utils/parsers/by_type/hortus_hortus.py
Normal file
4
utils/parsers/by_type/hortus_hortus.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from utils.csv.loaders import main_loader as pipe_sep_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return pipe_sep_main_loader(cfg, id, "pipe_separator")
|
||||
@@ -1,15 +0,0 @@
|
||||
#!.venv/bin/python
|
||||
# Import necessary modules
|
||||
from utils.database.loader_action import load_data, update_status, DATA_LOADED
|
||||
from utils.csv.data_preparation import make_matrix
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Define the main function for loading data
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
# Create a matrix of values from the data
|
||||
matrice_valori = make_matrix(cfg, id)
|
||||
# Load the data into the database
|
||||
if load_data(cfg, matrice_valori):
|
||||
update_status(cfg, id, DATA_LOADED)
|
||||
@@ -1,15 +0,0 @@
|
||||
#!.venv/bin/python
|
||||
# Import necessary modules
|
||||
from utils.database.loader_action import load_data, update_status, DATA_LOADED
|
||||
from utils.csv.data_preparation import make_matrix
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Define the main function for loading data
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
# Create a matrix of values from the data
|
||||
matrice_valori = make_matrix(cfg, id)
|
||||
# Load the data into the database
|
||||
if load_data(cfg, matrice_valori):
|
||||
update_status(cfg, id, DATA_LOADED)
|
||||
@@ -1,15 +0,0 @@
|
||||
#!.venv/bin/python
|
||||
# Import necessary modules
|
||||
from utils.database.loader_action import load_data, update_status, DATA_LOADED
|
||||
from utils.csv.data_preparation import make_matrix
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Define the main function for loading data
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
# Create a matrix of values from the data
|
||||
matrice_valori = make_matrix(cfg, id)
|
||||
# Load the data into the database
|
||||
if load_data(cfg, matrice_valori):
|
||||
update_status(cfg, id, DATA_LOADED)
|
||||
@@ -1,4 +0,0 @@
|
||||
from .g801_mums import main_loader as g801_mums_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return g801_mums_main_loader(cfg, id)
|
||||
@@ -1,12 +0,0 @@
|
||||
#!.venv/bin/python
|
||||
from utils.database.loader_action import load_data
|
||||
from utils.csv.data_preparation import make_loc_matrix
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def main_loader(cfg, id):
|
||||
matrice_valori = make_loc_matrix(cfg, id)
|
||||
load_data(cfg, matrice_valori)
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#!.venv/bin/python
|
||||
# Import necessary modules
|
||||
from utils.database.loader_action import load_data, update_status, DATA_LOADED
|
||||
from utils.csv.data_preparation import make_matrix
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Define the main function for loading data
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
# Create a matrix of values from the data
|
||||
matrice_valori = make_matrix(cfg, id)
|
||||
# Load the data into the database
|
||||
if load_data(cfg, matrice_valori):
|
||||
update_status(cfg, id, DATA_LOADED)
|
||||
@@ -1,4 +0,0 @@
|
||||
from .g801_mums import main_loader as g801_mums_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return g801_mums_main_loader(cfg, id)
|
||||
@@ -1,4 +0,0 @@
|
||||
from .g801_loc import main_loader as g801_loc_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return g801_loc_main_loader(cfg, id)
|
||||
@@ -1,4 +0,0 @@
|
||||
from .g801_mums import main_loader as g801_mums_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return g801_mums_main_loader(cfg, id)
|
||||
@@ -1,4 +0,0 @@
|
||||
from .g801_mums import main_loader as g801_mums_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return g801_mums_main_loader(cfg, id)
|
||||
@@ -1,4 +0,0 @@
|
||||
from .cr1000x_cr1000x import main_loader as cr1000x_cr1000x_main_loader
|
||||
|
||||
async def main_loader(cfg: object, id: int) -> None:
|
||||
return cr1000x_cr1000x_main_loader(cfg, id)
|
||||
Reference in New Issue
Block a user