578 lines
24 KiB
Python
578 lines
24 KiB
Python
|
|
import json
|
||
|
|
import subprocess
|
||
|
|
import openpyxl
|
||
|
|
import os
|
||
|
|
import psutil
|
||
|
|
import ast
|
||
|
|
import xlwings as xw
|
||
|
|
from grafana import grafana
|
||
|
|
from influxDB import influxdb
|
||
|
|
from datetime import datetime
|
||
|
|
import csv
|
||
|
|
from PyQt6 import *
|
||
|
|
from PyQt6.QtCore import *
|
||
|
|
|
||
|
|
class Calibrate(QObject):
|
||
|
|
def __init__(self):
|
||
|
|
super().__init__()
|
||
|
|
self.kill_processes("shimadenserver")
|
||
|
|
self.kill_processes("wps")
|
||
|
|
|
||
|
|
@pyqtSlot(str)
|
||
|
|
def startShima(self,path):
|
||
|
|
|
||
|
|
self.shimaName = path+'shimadenServer.exe'
|
||
|
|
self.shima = self.shimaName
|
||
|
|
process = subprocess.Popen(
|
||
|
|
self.shima,
|
||
|
|
creationflags=subprocess.CREATE_NO_WINDOW,
|
||
|
|
stdout=subprocess.DEVNULL,
|
||
|
|
stderr=subprocess.DEVNULL
|
||
|
|
)
|
||
|
|
def kill_processes(self, name):
|
||
|
|
for proc in psutil.process_iter(['pid', 'name']):
|
||
|
|
try:
|
||
|
|
if name in proc.info['name'].lower():
|
||
|
|
proc.kill()
|
||
|
|
print(f"Process {proc.info['pid']} (shimadenServer) has been killed.")
|
||
|
|
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
||
|
|
pass
|
||
|
|
@pyqtSlot(str, QVariant)
|
||
|
|
def setJson(self,path,data):
|
||
|
|
try:
|
||
|
|
data = data.toVariant()
|
||
|
|
# filePath = os.path.join(path, appId)
|
||
|
|
with open(path, 'w',encoding='utf-8') as file:
|
||
|
|
json.dump(data, file, ensure_ascii=False, indent=4)
|
||
|
|
except Exception as e:
|
||
|
|
print(e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, str)
|
||
|
|
def writeCsv(self, path, data):
|
||
|
|
try:
|
||
|
|
with open(path, 'w', encoding='utf-8', newline='') as file:
|
||
|
|
writer = csv.writer(file)
|
||
|
|
reader = csv.reader(data.splitlines())
|
||
|
|
for row in reader:
|
||
|
|
writer.writerow(row)
|
||
|
|
except IOError as e:
|
||
|
|
print("Error writing to CSV file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, result=list)
|
||
|
|
def readFCsv(self, path):
|
||
|
|
with open(path, newline='', encoding='utf-8') as csvfile:
|
||
|
|
reader = csv.reader(csvfile)
|
||
|
|
data = list(reader)
|
||
|
|
result = [row[1:4] for row in data[1:4]]
|
||
|
|
print(result)
|
||
|
|
return result
|
||
|
|
|
||
|
|
@pyqtSlot(str, result=list)
|
||
|
|
def readDXlsx(self, path):
|
||
|
|
result = []
|
||
|
|
with open(path, newline='', encoding='utf-8') as csvfile:
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
workbook = app.books.open(path)
|
||
|
|
worksheet = workbook.sheets[0]
|
||
|
|
for i in range(0, 12):
|
||
|
|
result.append({'x_Avalue': worksheet.range(f'B{5+i}').value, 'y_Avalue': worksheet.range(f'C{5+i}').value, 'z_Avalue': worksheet.range(f'D{5+i}').value,
|
||
|
|
'x_Atemp': worksheet.range('B17').value, 'y_Atemp': worksheet.range('C17').value, 'z_Atemp': worksheet.range('D17').value})
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
print("data:", result)
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
@pyqtSlot(str, str, str)
|
||
|
|
def overWriteXlsx(self,templatePath, path, data_str):
|
||
|
|
try:
|
||
|
|
workbook = openpyxl.load_workbook(templatePath)
|
||
|
|
sheet = workbook.active
|
||
|
|
data_arr = [row.split(',') for row in data_str.split('\n')]
|
||
|
|
print(data_arr)
|
||
|
|
for row in range(5, 18):
|
||
|
|
if row != 17:
|
||
|
|
for col in range(2, 8):
|
||
|
|
|
||
|
|
sheet.cell(row=row, column=col, value=data_arr[row - 5][col - 2])
|
||
|
|
else:
|
||
|
|
for col in range(2, 6):
|
||
|
|
|
||
|
|
sheet.cell(row=row, column=col, value=data_arr[row - 5][col - 2])
|
||
|
|
workbook.save(path)
|
||
|
|
except IOError as e:
|
||
|
|
print("Error writing to xlsx file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, str, list)
|
||
|
|
def writeALogCsv(self, logFilePath, exportPath,titles):
|
||
|
|
try:
|
||
|
|
if os.path.exists(logFilePath):
|
||
|
|
with open(logFilePath, "r", encoding="utf-8") as f:
|
||
|
|
file_content = f.read()
|
||
|
|
log_entries = file_content.strip().split("---END")
|
||
|
|
|
||
|
|
with open(exportPath, 'w', encoding='utf-8', newline='') as file:
|
||
|
|
writer = csv.writer(file)
|
||
|
|
writer.writerow(titles)
|
||
|
|
for entry in log_entries:
|
||
|
|
try:
|
||
|
|
log_entry = json.loads(entry)
|
||
|
|
time = log_entry["time"]
|
||
|
|
if "msg" in log_entry:
|
||
|
|
data = ast.literal_eval(log_entry["msg"])
|
||
|
|
if "x_Avalue" in data:
|
||
|
|
writer.writerow([time, data["x_Avalue"], data["y_Avalue"], data["z_Avalue"], data["x_Atemp"], data["y_Atemp"], data["z_Atemp"], data["x_Mvalue"], data["y_Mvalue"], data["z_Mvalue"], data["m_temp"], data["a_tempb"]])
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
except IOError as e:
|
||
|
|
print("Error writing to CSV file:", e)
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@pyqtSlot(str, str, QVariant)
|
||
|
|
def exportXlsx(self, templatePath, path, data):
|
||
|
|
try:
|
||
|
|
if not isinstance(data, dict):
|
||
|
|
data = data.toVariant()
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
workbook = app.books.open(templatePath)
|
||
|
|
worksheet1 = workbook.sheets[0]
|
||
|
|
worksheet2 = workbook.sheets[1]
|
||
|
|
worksheet3 = workbook.sheets[2]
|
||
|
|
worksheet5 = workbook.sheets[4]
|
||
|
|
worksheet6 = workbook.sheets[5]
|
||
|
|
|
||
|
|
a_Digital = 'a_Digital' in data and data['a_Digital'] or None
|
||
|
|
|
||
|
|
m_Digital = 'm_Digital' in data and data['m_Digital'] or None
|
||
|
|
xtemp = 0
|
||
|
|
ytemp = 0
|
||
|
|
ztemp = 0
|
||
|
|
m_temp = 0
|
||
|
|
sn = 'sn' in data and data['sn'] or None
|
||
|
|
user = 'user' in data and data['user'] or None
|
||
|
|
startTime = 'startTime' in data and data['startTime'] or None
|
||
|
|
endTime = 'endTime' in data and data['endTime'] or None
|
||
|
|
worksheet1.range('E1').value = sn
|
||
|
|
worksheet1.range('N1').value = user
|
||
|
|
worksheet1.range('E2').value = startTime
|
||
|
|
worksheet1.range('N2').value = endTime
|
||
|
|
|
||
|
|
worksheet1.range('E49').value = sn
|
||
|
|
worksheet1.range('N49').value = user
|
||
|
|
worksheet1.range('E50').value = startTime
|
||
|
|
worksheet1.range('N50').value = endTime
|
||
|
|
if a_Digital is not None:
|
||
|
|
for i in range(len(a_Digital)):
|
||
|
|
try:
|
||
|
|
worksheet2.range(f'B{i+5}').value = a_Digital[i]['x_Avalue']
|
||
|
|
worksheet2.range(f'C{i+5}').value = a_Digital[i]['y_Avalue']
|
||
|
|
worksheet2.range(f'D{i+5}').value = a_Digital[i]['z_Avalue']
|
||
|
|
xtemp += float(a_Digital[i]['x_Atemp'])
|
||
|
|
ytemp += float(a_Digital[i]['y_Atemp'])
|
||
|
|
ztemp += float(a_Digital[i]['z_Atemp'])
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
worksheet2.range(f'B17').value = xtemp / len(a_Digital)
|
||
|
|
worksheet2.range(f'C17').value = ytemp / len(a_Digital)
|
||
|
|
worksheet2.range(f'D17').value = ztemp / len(a_Digital)
|
||
|
|
|
||
|
|
if m_Digital is not None:
|
||
|
|
for i in range(len(m_Digital)):
|
||
|
|
try:
|
||
|
|
worksheet2.range(f'E{i+5}').value = m_Digital[i]['x_Mvalue']
|
||
|
|
worksheet2.range(f'F{i+5}').value = m_Digital[i]['y_Mvalue']
|
||
|
|
worksheet2.range(f'G{i+5}').value = m_Digital[i]['z_Mvalue']
|
||
|
|
m_temp += float(m_Digital[i]['m_temp'])
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
worksheet2.range(f'E17').value = m_temp / len(m_Digital)
|
||
|
|
|
||
|
|
a_DigitalYz = 'a_DigitalYz' in data and data['a_DigitalYz'] or None
|
||
|
|
if a_DigitalYz is not None:
|
||
|
|
for i in range(len(a_DigitalYz)):
|
||
|
|
try:
|
||
|
|
worksheet3.range(f'E{i+12}').value = a_DigitalYz[i]['x_Atemp']
|
||
|
|
worksheet3.range(f'F{i+12}').value = a_DigitalYz[i]['x_Avalue']
|
||
|
|
worksheet3.range(f'G{i+12}').value = a_DigitalYz[i]['y_Avalue']
|
||
|
|
worksheet3.range(f'H{i+12}').value = a_DigitalYz[i]['z_Avalue']
|
||
|
|
worksheet3.range(f'I{i+12}').value = a_DigitalYz[i]['x_Mvalue']
|
||
|
|
worksheet3.range(f'J{i+12}').value = a_DigitalYz[i]['y_Mvalue']
|
||
|
|
worksheet3.range(f'K{i+12}').value = a_DigitalYz[i]['z_Mvalue']
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
m_DigitalYz = 'm_DigitalYz' in data and data['m_DigitalYz'] or None
|
||
|
|
if m_DigitalYz is not None:
|
||
|
|
for i in range(len(m_DigitalYz)):
|
||
|
|
try:
|
||
|
|
worksheet3.range(f'E{i+20}').value = m_DigitalYz[i]['x_Atemp']
|
||
|
|
worksheet3.range(f'F{i+20}').value = m_DigitalYz[i]['x_Avalue']
|
||
|
|
worksheet3.range(f'G{i+20}').value = m_DigitalYz[i]['y_Avalue']
|
||
|
|
worksheet3.range(f'H{i+20}').value = m_DigitalYz[i]['z_Avalue']
|
||
|
|
worksheet3.range(f'I{i+20}').value = m_DigitalYz[i]['x_Mvalue']
|
||
|
|
worksheet3.range(f'J{i+20}').value = m_DigitalYz[i]['y_Mvalue']
|
||
|
|
worksheet3.range(f'K{i+20}').value = m_DigitalYz[i]['z_Mvalue']
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
worksheet3.range('F18').value = m_DigitalYz[len(m_DigitalYz)-1]['x_Avalue']
|
||
|
|
worksheet3.range('G18').value = m_DigitalYz[len(m_DigitalYz)-1]['y_Avalue']
|
||
|
|
worksheet3.range('H18').value = m_DigitalYz[len(m_DigitalYz)-1]['z_Avalue']
|
||
|
|
|
||
|
|
aw_Digital1 = 'aw_Digital1' in data and data['aw_Digital1'] or None
|
||
|
|
aw_Digital2 = 'aw_Digital2' in data and data['aw_Digital2'] or None
|
||
|
|
tempArr = []
|
||
|
|
tempMap = {}
|
||
|
|
filtered_tempMap = {}
|
||
|
|
if aw_Digital1 is not None:
|
||
|
|
for i in range(len(aw_Digital1)):
|
||
|
|
try:
|
||
|
|
if aw_Digital1[i]['x_Atemp'] in tempMap:
|
||
|
|
tempMap[aw_Digital1[i]['x_Atemp']] += 1
|
||
|
|
else:
|
||
|
|
tempMap[aw_Digital1[i]['x_Atemp']] = 1
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
tempMap = {key: value for key, value in tempMap.items() if value >= 10}
|
||
|
|
prev_key = None
|
||
|
|
prev_value = None
|
||
|
|
start_key = None
|
||
|
|
index = 0
|
||
|
|
for key, value in tempMap.items():
|
||
|
|
if prev_key is not None and prev_value is not None:
|
||
|
|
if start_key is None:
|
||
|
|
start_key = prev_key
|
||
|
|
if abs(key - start_key) <=1:
|
||
|
|
if value > prev_value:
|
||
|
|
filtered_tempMap[index] = f"{key}"
|
||
|
|
else:
|
||
|
|
filtered_tempMap[index] = f"{prev_key}"
|
||
|
|
else:
|
||
|
|
start_key = key
|
||
|
|
filtered_tempMap[index] = f"{prev_key}"
|
||
|
|
# print("skip:", key, value)
|
||
|
|
index += 1
|
||
|
|
prev_key = key
|
||
|
|
prev_value = value
|
||
|
|
|
||
|
|
|
||
|
|
for key, value in filtered_tempMap.items():
|
||
|
|
tempArr.append(float(value))
|
||
|
|
tempMap = {}
|
||
|
|
filtered_tempMap2 = {}
|
||
|
|
tempArr2 = []
|
||
|
|
if aw_Digital2 is not None:
|
||
|
|
for i in range(len(aw_Digital2)):
|
||
|
|
try:
|
||
|
|
if aw_Digital2[i]['x_Atemp'] in tempMap:
|
||
|
|
tempMap[aw_Digital2[i]['x_Atemp']] += 1
|
||
|
|
else:
|
||
|
|
tempMap[aw_Digital2[i]['x_Atemp']] = 1
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
tempMap = {key: value for key, value in tempMap.items() if value >= 10}
|
||
|
|
|
||
|
|
prev_key = None
|
||
|
|
prev_value = None
|
||
|
|
start_key = None
|
||
|
|
index = 0
|
||
|
|
for key, value in tempMap.items():
|
||
|
|
try:
|
||
|
|
if prev_key is not None and prev_value is not None:
|
||
|
|
if start_key is None:
|
||
|
|
start_key = prev_key
|
||
|
|
if abs(key - start_key) <=1:
|
||
|
|
if value > prev_value:
|
||
|
|
filtered_tempMap2[index] = f"{key}"
|
||
|
|
else:
|
||
|
|
filtered_tempMap2[index] = f"{prev_key}"
|
||
|
|
else:
|
||
|
|
start_key = key
|
||
|
|
filtered_tempMap2[index] = f"{prev_key}"
|
||
|
|
# print("skip:", key, value)
|
||
|
|
index += 1
|
||
|
|
prev_key = key
|
||
|
|
prev_value = value
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
for key, value in filtered_tempMap2.items():
|
||
|
|
tempArr2.append(float(value))
|
||
|
|
|
||
|
|
if aw_Digital1 is not None and aw_Digital2 is not None:
|
||
|
|
aw_DigitalMap = {}
|
||
|
|
|
||
|
|
for i in range(len(aw_Digital1)):
|
||
|
|
try:
|
||
|
|
if aw_Digital1[i]['x_Atemp'] in tempArr:
|
||
|
|
aw_DigitalMap[aw_Digital1[i]['x_Atemp']] = aw_Digital1[i]
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
index = 0
|
||
|
|
for key,value in aw_DigitalMap.items():
|
||
|
|
try:
|
||
|
|
worksheet6.range(f'C{index+4}').value = value['x_Atemp']
|
||
|
|
worksheet6.range(f'D{index+4}').value = value['x_Avalue']
|
||
|
|
worksheet6.range(f'E{index+4}').value = value['y_Avalue']
|
||
|
|
worksheet6.range(f'F{index+4}').value = value['z_Avalue']
|
||
|
|
index += 1
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
aw_DigitalMap = {}
|
||
|
|
for i in range(len(aw_Digital2)):
|
||
|
|
try:
|
||
|
|
if aw_Digital2[i]['x_Atemp'] in tempArr2:
|
||
|
|
aw_DigitalMap[aw_Digital2[i]['x_Atemp']] = aw_Digital2[i]
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
index = 0
|
||
|
|
for value in aw_DigitalMap.items():
|
||
|
|
try:
|
||
|
|
worksheet6.range(f'H{index+4}').value = value['x_Atemp']
|
||
|
|
worksheet6.range(f'I{index+4}').value = value['x_Avalue']
|
||
|
|
worksheet6.range(f'J{index+4}').value = value['y_Avalue']
|
||
|
|
worksheet6.range(f'K{index+4}').value = value['z_Avalue']
|
||
|
|
index += 1
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
mw_Digital = 'mw_Digital' in data and data['mw_Digital'] or None
|
||
|
|
realTemps = 'realTemps' in data and data['realTemps'] or None
|
||
|
|
if mw_Digital is not None and realTemps is not None:
|
||
|
|
if len(mw_Digital) == (len(realTemps) * 2):
|
||
|
|
# for i in range(len(realTemps)):
|
||
|
|
# worksheet5.range(f'A{i+4}').value = realTemps[i]
|
||
|
|
for i in range(len(realTemps)):
|
||
|
|
try:
|
||
|
|
worksheet5.range(f'A{i+4}').value = mw_Digital[i*2]['m_temp']
|
||
|
|
worksheet5.range(f'B{i+4}').value = mw_Digital[i*2]['x_Mvalue']
|
||
|
|
worksheet5.range(f'C{i+4}').value = mw_Digital[i*2]['y_Mvalue']
|
||
|
|
worksheet5.range(f'D{i+4}').value = mw_Digital[i*2]['z_Mvalue']
|
||
|
|
worksheet5.range(f'E{i+4}').value = mw_Digital[(i*2)+1]['x_Mvalue']
|
||
|
|
worksheet5.range(f'F{i+4}').value = mw_Digital[(i*2)+1]['y_Mvalue']
|
||
|
|
worksheet5.range(f'G{i+4}').value = mw_Digital[(i*2)+1]['z_Mvalue']
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
workbook.save(path)
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
except IOError as e:
|
||
|
|
print("Error writing to xlsx file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, list)
|
||
|
|
def setAModel(self, path, a_Digital):
|
||
|
|
try:
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
workbook = app.books.open(path)
|
||
|
|
worksheet = workbook.sheets[1]
|
||
|
|
xtemp = 0
|
||
|
|
ytemp = 0
|
||
|
|
ztemp = 0
|
||
|
|
if a_Digital is not None:
|
||
|
|
for i in range(len(a_Digital)):
|
||
|
|
try:
|
||
|
|
worksheet.range(f'B{i+5}').value = a_Digital[i]['x_Avalue']
|
||
|
|
worksheet.range(f'C{i+5}').value = a_Digital[i]['y_Avalue']
|
||
|
|
worksheet.range(f'D{i+5}').value = a_Digital[i]['z_Avalue']
|
||
|
|
xtemp += float(a_Digital[i]['x_Atemp'])
|
||
|
|
ytemp += float(a_Digital[i]['y_Atemp'])
|
||
|
|
ztemp += float(a_Digital[i]['z_Atemp'])
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
worksheet.range(f'B17').value = xtemp / len(a_Digital)
|
||
|
|
worksheet.range(f'C17').value = ytemp / len(a_Digital)
|
||
|
|
worksheet.range(f'D17').value = ztemp / len(a_Digital)
|
||
|
|
workbook.save()
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
except IOError as e:
|
||
|
|
# workbook.close()
|
||
|
|
# app.kill()
|
||
|
|
print("Error writing to xlsx file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, list)
|
||
|
|
def setMModel(self, path, m_Digital):
|
||
|
|
try:
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
workbook = app.books.open(path)
|
||
|
|
worksheet = workbook.sheets[1]
|
||
|
|
m_temp = 0
|
||
|
|
if m_Digital is not None:
|
||
|
|
for i in range(len(m_Digital)):
|
||
|
|
worksheet.range(f'E{i+5}').value = m_Digital[i]['x_Mvalue']
|
||
|
|
worksheet.range(f'F{i+5}').value = m_Digital[i]['y_Mvalue']
|
||
|
|
worksheet.range(f'G{i+5}').value = m_Digital[i]['z_Mvalue']
|
||
|
|
m_temp += float(m_Digital[i]['m_temp'])
|
||
|
|
worksheet.range(f'E17').value = m_temp / len(m_Digital)
|
||
|
|
workbook.save()
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
except IOError as e:
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
print("Error writing to xlsx file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, QVariant)
|
||
|
|
def setAValue(self, path, data):
|
||
|
|
try:
|
||
|
|
if not isinstance(data, dict):
|
||
|
|
data = data.toVariant()
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
workbook = app.books.open(path)
|
||
|
|
worksheet = workbook.sheets[2]
|
||
|
|
worksheet.range('E12').value = data['tx']
|
||
|
|
worksheet.range('F12').value = data['ax']
|
||
|
|
worksheet.range('G12').value = data['ay']
|
||
|
|
worksheet.range('H12').value = data['az']
|
||
|
|
workbook.save()
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
except IOError as e:
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
print("Error writing to xlsx file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, QVariant)
|
||
|
|
def setMValue(self, path, data):
|
||
|
|
try:
|
||
|
|
if not isinstance(data, dict):
|
||
|
|
data = data.toVariant()
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
workbook = app.books.open(path)
|
||
|
|
worksheet = workbook.sheets[2]
|
||
|
|
worksheet.range('E12').value = data['th']
|
||
|
|
worksheet.range('I12').value = data['hx']
|
||
|
|
worksheet.range('J12').value = data['hy']
|
||
|
|
worksheet.range('K12').value = data['hz']
|
||
|
|
workbook.save()
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
except IOError as e:
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
print("Error writing to xlsx file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, result=QVariant)
|
||
|
|
def getMWD(self, path):
|
||
|
|
try:
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
workbook = app.books.open(path)
|
||
|
|
worksheet = workbook.sheets[2]
|
||
|
|
data = { 'gtf': worksheet.range('AR12').value, 'inc': worksheet.range('AS12').value, 'zai': worksheet.range('AV12').value }
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
print("data:", data)
|
||
|
|
return data
|
||
|
|
except IOError as e:
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
print("Error reading xlsx file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, QVariant)
|
||
|
|
def setHmhzParams(self, path, data):
|
||
|
|
try:
|
||
|
|
if not isinstance(data, dict):
|
||
|
|
data = data.toVariant()
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
print(path, data)
|
||
|
|
workbook = app.books.open(path)
|
||
|
|
worksheet = workbook.sheets['PCM-SDIM']
|
||
|
|
worksheet.range('A4').value = data['inc']
|
||
|
|
worksheet.range('B4').value = data['gtf']
|
||
|
|
print(data['inc'], data['gtf'])
|
||
|
|
workbook.save()
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
|
||
|
|
except IOError as e:
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
print("Error writing to xlsx file:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str, result=list)
|
||
|
|
def getHmhzList(self, path):
|
||
|
|
try:
|
||
|
|
self.kill_processes("wps")
|
||
|
|
app = xw.App(visible = False, add_book=False)
|
||
|
|
workbook = app.books.open(path)
|
||
|
|
worksheet = workbook.sheets['PCM-SDIM']
|
||
|
|
list = []
|
||
|
|
for i in range(4, 41):
|
||
|
|
if ((i-4) % 3) == 0:
|
||
|
|
data = {"azi":worksheet.range(f'C{i}').value,"v1": 600, "v2": worksheet.range(f'AI{i}').value, "v3": worksheet.range(f'AJ{i}').value, "v4": worksheet.range(f'AK{i}').value}
|
||
|
|
list.append(data)
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
return list
|
||
|
|
|
||
|
|
except IOError as e:
|
||
|
|
workbook.close()
|
||
|
|
app.kill()
|
||
|
|
print("Error reading xlsx file:", e)
|
||
|
|
return []
|
||
|
|
|
||
|
|
|
||
|
|
@pyqtSlot(str,result=QVariant)
|
||
|
|
def getJson(self, path):
|
||
|
|
try:
|
||
|
|
with open(path, 'r',encoding='utf-8') as file:
|
||
|
|
data = json.load(file)
|
||
|
|
return data
|
||
|
|
except IOError as e:
|
||
|
|
print("Error getJson:", e)
|
||
|
|
|
||
|
|
@pyqtSlot(str,str,str, result=bool)
|
||
|
|
def csvToInfluxdb(self, mea='undefine', ts='0', fp=None):
|
||
|
|
lastTime = None
|
||
|
|
if not fp or not os.path.exists(fp):
|
||
|
|
return False, fp
|
||
|
|
with open(fp) as f:
|
||
|
|
f_csv = csv.reader(f)
|
||
|
|
headings = next(f_csv)
|
||
|
|
if len(headings) % 2 != 0:
|
||
|
|
return False, lastTime
|
||
|
|
for r in f_csv:
|
||
|
|
data_points = []
|
||
|
|
for i in range(0, len(r), 2):
|
||
|
|
if r[i] == '':
|
||
|
|
continue
|
||
|
|
lastTime = float(r[i]) + float(ts)
|
||
|
|
_time = datetime.utcfromtimestamp(lastTime/1000)
|
||
|
|
_field = headings[i + 1]
|
||
|
|
_value = float(r[i + 1])
|
||
|
|
data_points.append({"measurement": mea, "time": _time, "fields": {_field: _value}})
|
||
|
|
ok = influxdb.write_points(data_points)
|
||
|
|
return True
|
||
|
|
|
||
|
|
@pyqtSlot(str, str, str, result=QVariant)
|
||
|
|
def get_dashboard_uid(self, base_url, token, name):
|
||
|
|
ok, res = grafana.getUid(base_url, token, name)
|
||
|
|
if ok:
|
||
|
|
return res
|
||
|
|
return None
|
||
|
|
|
||
|
|
@pyqtSlot(str,str,str, result=QVariant)
|
||
|
|
def update_dashboard_data(self, uid, base_url, token):
|
||
|
|
ok, res = grafana.update(uid, base_url, token)
|
||
|
|
if ok:
|
||
|
|
return res
|
||
|
|
return None
|
||
|
|
|
||
|
|
@pyqtSlot(str,str,str, str, str, result=QVariant)
|
||
|
|
def update_dashboard_time(self, uid, base_url, token , start, stop):
|
||
|
|
ok, res = grafana.updateTime(uid, base_url, token , start, stop)
|
||
|
|
if ok:
|
||
|
|
return res
|
||
|
|
return None
|
||
|
|
|
||
|
|
calibrate = Calibrate()
|