add alias for tools and units types and names

This commit is contained in:
2025-08-03 21:46:15 +02:00
parent fdefd0a430
commit 5fc40093e2
11 changed files with 739 additions and 12 deletions

View File

@@ -57,7 +57,7 @@ class Config:
self.tools_name = [part for part in c.get("tool", "Names").split('|')]
self.tools_type = [part for part in c.get("tool", "Types").split('|')]
self.tools_alias = {
key: value
key: key if value == '=' else value
for item in c.get("tool", "Alias").split('|')
for key, value in [item.split(':', 1)]
}

View File

@@ -32,7 +32,15 @@ def on_file_received(self: object, file: str) -> None:
tool_type = extract_value(cfg.tools_type, filename, str(lines[0:10]))
tool_info = "{}"
unit_type = cfg.units_alias.get(unit_type.upper(), unit_type)
# se esiste l'alias in alias_unit_type, allora prende il valore dell'alias... verifica sia lo unit_type completo che i primi 3 caratteri per CO_xxxxx
upper_unit_type = unit_type.upper()
unit_type = cfg.units_alias.get(upper_unit_type) or \
cfg.units_alias.get(upper_unit_type[:3]) or \
upper_unit_type
upper_tool_type = tool_type.upper()
tool_type = cfg.tools_alias.get(upper_tool_type) or \
cfg.tools_alias.get(upper_tool_type[:3]) or \
upper_tool_type
try:
conn = connetti_db(cfg)

View File

@@ -0,0 +1,45 @@
import asyncio
import tempfile
import os
from utils.database import WorkflowFlags
from utils.database.loader_action import update_status, unlock
from utils.csv.data_preparation import get_data
import logging
logger = logging.getLogger(__name__)
async def main_loader(cfg: object, id: int, pool: object) -> None:
filename, UnitName, ToolNameID, ToolData = await get_data(cfg, id, pool)
# Creare un file temporaneo
with tempfile.NamedTemporaryFile(mode='w', prefix= filename, suffix='.csv', delete=False) as temp_file:
temp_file.write(ToolData)
temp_filename = temp_file.name
try:
# Usa asyncio.subprocess per vero async
process = await asyncio.create_subprocess_exec(
'python3', 'old_script/hirpiniaLoadScript.py', temp_filename,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
result_stdout = stdout.decode('utf-8')
result_stderr = stderr.decode('utf-8')
finally:
# Pulire il file temporaneo
os.unlink(temp_filename)
if process.returncode != 0:
logger.error(f"Errore nell'esecuzione del programma hirpiniaLoadScript.py: {result_stderr}")
raise Exception(f"Errore nel programma: {result_stderr}")
else:
logger.info("Programma hirpiniaLoadScript.py eseguito con successo.")
logger.debug(f"Stdout: {result_stdout}")
await update_status(cfg, id, WorkflowFlags.DATA_LOADED, pool)
await update_status(cfg, id, WorkflowFlags.DATA_ELABORATED, pool)
await unlock(cfg, id, pool)

View File

@@ -21,7 +21,7 @@ async def main_loader(cfg: object, id: int, pool: object) -> None:
try:
# Usa asyncio.subprocess per vero async
process = await asyncio.create_subprocess_exec(
'python3', 'old_script/TS_PiniScript.py', temp_filename,
'python3', 'old_script/sisgeoLoadScript.py', temp_filename,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
@@ -35,10 +35,10 @@ async def main_loader(cfg: object, id: int, pool: object) -> None:
os.unlink(temp_filename)
if process.returncode != 0:
logger.error(f"Errore nell'esecuzione del programma TS_PiniScript.py: {result_stderr}")
logger.error(f"Errore nell'esecuzione del programma sisgeoLoadScript.py: {result_stderr}")
raise Exception(f"Errore nel programma: {result_stderr}")
else:
logger.info("Programma TS_PiniScript.py eseguito con successo.")
logger.info("Programma sisgeoLoadScript.py eseguito con successo.")
logger.debug(f"Stdout: {result_stdout}")
await update_status(cfg, id, WorkflowFlags.DATA_LOADED, pool)
await update_status(cfg, id, WorkflowFlags.DATA_ELABORATED, pool)

View File

@@ -21,7 +21,7 @@ async def main_loader(cfg: object, id: int, pool: object) -> None:
try:
# Usa asyncio.subprocess per vero async
process = await asyncio.create_subprocess_exec(
'python3', 'old_script/TS_PiniScript.py', temp_filename,
'python3', 'old_script/sisgeoLoadScript.py', temp_filename,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
@@ -35,10 +35,10 @@ async def main_loader(cfg: object, id: int, pool: object) -> None:
os.unlink(temp_filename)
if process.returncode != 0:
logger.error(f"Errore nell'esecuzione del programma TS_PiniScript.py: {result_stderr}")
logger.error(f"Errore nell'esecuzione del programma sisgeoLoadScript.py: {result_stderr}")
raise Exception(f"Errore nel programma: {result_stderr}")
else:
logger.info("Programma TS_PiniScript.py eseguito con successo.")
logger.info("Programma sisgeoLoadScript.py eseguito con successo.")
logger.debug(f"Stdout: {result_stdout}")
await update_status(cfg, id, WorkflowFlags.DATA_LOADED, pool)
await update_status(cfg, id, WorkflowFlags.DATA_ELABORATED, pool)

View File

@@ -21,7 +21,7 @@ async def main_loader(cfg: object, id: int, pool: object) -> None:
try:
# Usa asyncio.subprocess per vero async
process = await asyncio.create_subprocess_exec(
'python3', 'old_script/TS_PiniScript.py', temp_filename,
'python3', 'old_script/sorotecPini.py', temp_filename,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
@@ -35,10 +35,10 @@ async def main_loader(cfg: object, id: int, pool: object) -> None:
os.unlink(temp_filename)
if process.returncode != 0:
logger.error(f"Errore nell'esecuzione del programma TS_PiniScript.py: {result_stderr}")
logger.error(f"Errore nell'esecuzione del programma sorotecPini.py: {result_stderr}")
raise Exception(f"Errore nel programma: {result_stderr}")
else:
logger.info("Programma TS_PiniScript.py eseguito con successo.")
logger.info("Programma sorotecPini.py eseguito con successo.")
logger.debug(f"Stdout: {result_stdout}")
await update_status(cfg, id, WorkflowFlags.DATA_LOADED, pool)
await update_status(cfg, id, WorkflowFlags.DATA_ELABORATED, pool)