This commit is contained in:
2025-05-01 00:58:07 +02:00
parent cc7a136cf3
commit fd5429ee0d
23 changed files with 190 additions and 57 deletions

View File

@@ -25,6 +25,7 @@ class Config:
# LOADER setting
self.elablog = c.get("csvelab", "logFilename")
self.max_threads = c.getint("csvelab", "max_threads")
# DB setting
self.dbhost = c.get("db", "hostname")
@@ -35,7 +36,7 @@ class Config:
self.dbschema = c.get("db", "dbSchema")
self.dbusertable = c.get("db", "userTableName")
self.dbrectable = c.get("db", "recTableName")
self.dbdataraw = c.get("db", "rawTableName")
self.dbrawdata = c.get("db", "rawTableName")
# unit setting
self.units_name = [part for part in c.get("unit", "Names").split('|')]

32
utils/database/loader.py Normal file
View File

@@ -0,0 +1,32 @@
#!.venv/bin/python
from utils.database.connection import connetti_db
import logging
logger = logging.getLogger(__name__)
def load_data(cfg, matrice_valori):
sql_insert_RAWDATA = f'''
INSERT IGNORE INTO {cfg.dbname}.{cfg.dbrawdata} (
`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,
`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,
`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`,
`BatLevelModule`,`TemperatureModule`, `RssiModule`
)
VALUES (
%s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s
)
'''
with connetti_db(cfg) as conn:
cur = conn.cursor()
try:
cur.executemany(sql_insert_RAWDATA, matrice_valori)
conn.commit()
except Exception as e:
conn.rollback()
print(f'Error: {e}')
finally:
cur.close()
conn.close()

View File

@@ -0,0 +1,3 @@
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
return f'{__name__}: {unit} - {tool}'

3
utils/parsers/d2w_d2w.py Normal file
View File

@@ -0,0 +1,3 @@
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,28 @@
#!.venv/bin/python
from utils.database.connection import connetti_db
import utils.timestamp.date_check as date_check
import logging
logger = logging.getLogger(__name__)
def get_data(cfg, id):
with connetti_db(cfg) as conn:
cur = conn.cursor()
cur.execute(f'select unit_name, tool_name, tool_data from {cfg.dbname}.{cfg.dbrectable} where id = {id}')
unit_name, tool_name, tool_data = cur.fetchone()
cur.close()
conn.close()
return unit_name, tool_name, tool_data
def make_matrix(cfg, id):
UnitName, ToolNameID, ToolData = get_data(cfg, id)
righe = ToolData.splitlines()
matrice_valori = []
for riga in [riga for riga in righe if ';|;' in riga]:
timestamp, batlevel, temperature, rilevazioni = riga.split(';',3)
EventDate, EventTime = timestamp.split(' ')
valori_nodi = rilevazioni.lstrip('|;').rstrip(';').split(';|;') # Toglie '|;' iniziali, toglie eventuali ';' finali, dividi per ';|;'
for num_nodo, valori_nodo in enumerate(valori_nodi, start=1):
valori = valori_nodo.split(';')
matrice_valori.append([UnitName, ToolNameID, num_nodo, date_check.conforma_data(EventDate), EventTime, batlevel, temperature] + valori + ([None] * (19 - len(valori))))
return matrice_valori

View File

@@ -0,0 +1,3 @@
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,3 @@
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,3 @@
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

View File

@@ -1,3 +1,10 @@
def chi_sono(unit, tool):
print(f'g801_mums: {unit} - {tool}')
return f'g801_mums: {unit} - {tool}'
#!.venv/bin/python
from utils.database.loader import load_data
from utils.parsers.data_preparation import make_matrix
import logging
logger = logging.getLogger(__name__)
def main_loader(cfg, id):
matrice_valori = make_matrix(cfg, id)
load_data(cfg, matrice_valori)

View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

View File

@@ -1,3 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'g801_mux: {unit} - {tool}')
return f'g801_mux: {unit} - {tool}'
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

5
utils/parsers/g802_gd.py Normal file
View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

5
utils/parsers/gs1_gs1.py Normal file
View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

5
utils/parsers/tlp_loc.py Normal file
View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'

5
utils/parsers/tlp_tlp.py Normal file
View File

@@ -0,0 +1,5 @@
import time
def chi_sono(unit, tool):
print(f'{__name__}: {unit} - {tool}')
time.sleep(20)
return f'{__name__}: {unit} - {tool}'