refresh script
This commit is contained in:
55
gflowScript.py
Executable file
55
gflowScript.py
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
from mysql.connector import MySQLConnection, Error
|
||||
from dbconfig import read_db_config
|
||||
|
||||
def insertData(dati):
|
||||
if dati != "null":
|
||||
query = "INSERT INTO ELABDATAGFLOW(unit_name, tool_name, EventDateTime, xacc, yacc, zacc, cacc, battery_level, wifi_signal) " \
|
||||
"VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
||||
|
||||
try:
|
||||
db_config = read_db_config()
|
||||
conn = MySQLConnection(**db_config)
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.executemany(query, dati)
|
||||
|
||||
conn.commit()
|
||||
except Error as e:
|
||||
print('Error:', e)
|
||||
|
||||
finally:
|
||||
os.system("cd /usr/local/matlab_func/; ./run_RSN_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93/ "+dati[0][0]+" "+dati[0][1]+"")
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
def getDataFromFile(pathFile):
|
||||
with open(pathFile, 'r') as file:
|
||||
data = file.readlines()
|
||||
data = [row.rstrip() for row in data]
|
||||
header = data[0].split(",")
|
||||
unitName = header[0]
|
||||
if unitName.startswith('ID'):
|
||||
toolName = header[1]
|
||||
batteryLevel = header[2].replace("V","")
|
||||
wifiSignal = header[3].replace("dBm","")
|
||||
data.pop(0)
|
||||
dati = []
|
||||
for row in data:
|
||||
row = row.split(",")
|
||||
if row[5] != "0.00":
|
||||
row[0] = row[0].replace("/","-",2).split("-")
|
||||
dateTime = row[0][2] + "-" + row[0][1] + "-" + row[0][0] + " " + row[1]
|
||||
dati.append((unitName,toolName,dateTime,row[2],row[3],row[4],row[5],batteryLevel,wifiSignal))
|
||||
|
||||
return dati
|
||||
else:
|
||||
return "null"
|
||||
|
||||
def main():
|
||||
insertData(getDataFromFile(sys.argv[1]))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user