64 lines
2.6 KiB
Python
Executable File
64 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import os
|
|
from mysql.connector import MySQLConnection, Error
|
|
from dbconfig import read_db_config
|
|
from decimal import Decimal
|
|
from datetime import datetime
|
|
import ezodf
|
|
|
|
def getDataFromCsv(pathFile):
|
|
try:
|
|
folder_path, file_with_extension = os.path.split(pathFile)
|
|
unit_name = os.path.basename(folder_path)#unitname
|
|
tool_name, _ = os.path.splitext(file_with_extension)#toolname
|
|
tool_name = tool_name.replace("HIRPINIA_", "")
|
|
tool_name = tool_name.split("_")[0]
|
|
print(unit_name, tool_name)
|
|
datiRaw = []
|
|
doc = ezodf.opendoc(pathFile)
|
|
for sheet in doc.sheets:
|
|
node_num = sheet.name.replace("S-", "")
|
|
print(f"Sheet Name: {sheet.name}")
|
|
rows_to_skip = 2
|
|
for i, row in enumerate(sheet.rows()):
|
|
if i < rows_to_skip:
|
|
continue
|
|
row_data = [cell.value for cell in row]
|
|
date_time = datetime.strptime(row_data[0], "%Y-%m-%dT%H:%M:%S").strftime("%Y-%m-%d %H:%M:%S").split(" ")
|
|
date = date_time[0]
|
|
time = date_time[1]
|
|
val0 = row_data[2]
|
|
val1 = row_data[4]
|
|
val2 = row_data[6]
|
|
val3 = row_data[8]
|
|
datiRaw.append((unit_name, tool_name, node_num, date, time, -1, -273, val0, val1, val2, val3))
|
|
try:
|
|
db_config = read_db_config()
|
|
conn = MySQLConnection(**db_config)
|
|
cursor = conn.cursor(dictionary=True)
|
|
queryRaw = "insert ignore into RAWDATACOR(UnitName,ToolNameID,NodeNum,EventDate,EventTime,BatLevel,Temperature,Val0,Val1,Val2,Val3) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
|
cursor.executemany(queryRaw, datiRaw)
|
|
conn.commit()
|
|
except Error as e:
|
|
print('Error:', e)
|
|
finally:
|
|
queryMatlab = "select m.matcall from tools as t join units as u on u.id=t.unit_id join matfuncs as m on m.id=t.matfunc where u.name=%s and t.name=%s"
|
|
cursor.execute(queryMatlab, [unit_name, tool_name])
|
|
resultMatlab = cursor.fetchall()
|
|
if(resultMatlab):
|
|
print("Avvio "+str(resultMatlab[0]["matcall"]))
|
|
os.system("cd /usr/local/matlab_func/; ./run_"+str(resultMatlab[0]["matcall"])+".sh /usr/local/MATLAB/MATLAB_Runtime/v93/ "+str(unit_name)+" "+str(tool_name)+"")
|
|
cursor.close()
|
|
conn.close()
|
|
except Exception as e:
|
|
print(f"An unexpected error occurred: {str(e)}\n")
|
|
|
|
def main():
|
|
print("Avviato.")
|
|
getDataFromCsv(sys.argv[1])
|
|
print("Finito.")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|