added InfluxDB v1 support
This commit is contained in:
parent
c977498afc
commit
961941bbc9
40
IsegGUI.py
40
IsegGUI.py
|
@ -20,10 +20,13 @@ except:
|
||||||
print("Error: ISEG_TOKEN.txt file not found.")
|
print("Error: ISEG_TOKEN.txt file not found.")
|
||||||
token = None # Or assign a default value if needed
|
token = None # Or assign a default value if needed
|
||||||
|
|
||||||
org = ""
|
useInfluxDBv1 = True
|
||||||
databaseIP="192.168.1.193"
|
databaseIP="192.168.1.193"
|
||||||
write_client = influxdb_client.InfluxDBClient(url=databaseIP, token=token, org=org)
|
org = ""
|
||||||
bucket = ""
|
bucket = ""
|
||||||
|
|
||||||
|
if useInfluxDBv1 == False :
|
||||||
|
write_client = influxdb_client.InfluxDBClient(url=databaseIP, token=token, org=org)
|
||||||
# write_api = write_client.write_api(write_options=ASYNCHRONOUS)
|
# write_api = write_client.write_api(write_options=ASYNCHRONOUS)
|
||||||
write_api = write_client.write_api(write_options=SYNCHRONOUS)
|
write_api = write_client.write_api(write_options=SYNCHRONOUS)
|
||||||
|
|
||||||
|
@ -122,9 +125,9 @@ class MyWindow(QMainWindow):
|
||||||
|
|
||||||
self.chkDB = QCheckBox("Enable", self)
|
self.chkDB = QCheckBox("Enable", self)
|
||||||
gLayout.addWidget(self.chkDB, 0, 2)
|
gLayout.addWidget(self.chkDB, 0, 2)
|
||||||
# if token == None:
|
if token == None and useInfluxDBv1 == False:
|
||||||
# self.txtIP.setEnabled(False)
|
self.txtIP.setEnabled(False)
|
||||||
# self.chkDB.setEnabled(False)
|
self.chkDB.setEnabled(False)
|
||||||
|
|
||||||
lb1 = QLabel("Refresh period [sec] :", self)
|
lb1 = QLabel("Refresh period [sec] :", self)
|
||||||
lb1.setAlignment(Qt.AlignmentFlag.AlignRight)
|
lb1.setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
|
@ -370,12 +373,12 @@ class MyWindow(QMainWindow):
|
||||||
|
|
||||||
def updateTimer(self):
|
def updateTimer(self):
|
||||||
# self.time += 1
|
# self.time += 1
|
||||||
# print(f'Time: {self.time}')
|
# print(f'Time: {time.time()}')
|
||||||
outVList = mpod.GetAllOutputHV()
|
outVList = mpod.GetAllOutputHV()
|
||||||
outIList = mpod.GetAllLC()
|
outIList = mpod.GetAllLC()
|
||||||
# print(outVList)
|
# print(outVList)
|
||||||
|
|
||||||
if self.chkDB.checkState() == Qt.CheckState.Checked:
|
if self.chkDB.checkState() == Qt.CheckState.Checked and useInfluxDBv1 == False:
|
||||||
points = []
|
points = []
|
||||||
|
|
||||||
for k in range(0, nMod):
|
for k in range(0, nMod):
|
||||||
|
@ -386,14 +389,31 @@ class MyWindow(QMainWindow):
|
||||||
self.txtVOut[k][i].setText("{:.2f}".format(vout))
|
self.txtVOut[k][i].setText("{:.2f}".format(vout))
|
||||||
self.txtIOut[k][i].setText("{:.2f}".format(iout * 1e6))
|
self.txtIOut[k][i].setText("{:.2f}".format(iout * 1e6))
|
||||||
|
|
||||||
if self.chkDB.checkState() == Qt.CheckState.Checked:
|
# print(f"{k}-{a},{vout:.2f}")
|
||||||
|
|
||||||
|
if useInfluxDBv1 == False and self.chkDB.checkState() == Qt.CheckState.Checked :
|
||||||
points.append(Point("Voltage").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outVList[sum(nChPerMod[:k]) + i])))
|
points.append(Point("Voltage").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outVList[sum(nChPerMod[:k]) + i])))
|
||||||
points.append(Point("LeakageCurrent").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outIList[sum(nChPerMod[:k]) + i])))
|
points.append(Point("LeakageCurrent").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outIList[sum(nChPerMod[:k]) + i])))
|
||||||
|
|
||||||
if self.chkDB.checkState() == Qt.CheckState.Checked:
|
if useInfluxDBv1 == False and self.chkDB.checkState() == Qt.CheckState.Checked :
|
||||||
|
|
||||||
write_api.write(bucket=bucket, org=org, record=points)
|
write_api.write(bucket=bucket, org=org, record=points)
|
||||||
|
|
||||||
|
if useInfluxDBv1 == True and self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||||
|
print("pushing data to influxDB")
|
||||||
|
with open("output.txt", "w") as f:
|
||||||
|
for i, ch in enumerate(chList):
|
||||||
|
det = ch % 100
|
||||||
|
module = ch // 100
|
||||||
|
line = f"HV,Det={det},Module={module} value={outVList[i]:.3f}\n"
|
||||||
|
f.write(line)
|
||||||
|
line = f"LC,Det={det},Module={module} value={outIList[i]*1e6:.3f}\n"
|
||||||
|
f.write(line)
|
||||||
|
|
||||||
|
DB_BashCommand_Mac='curl -sS -i -XPOST "http://%s:8086/write?db=testing" --data-binary @output.txt --speed-time 5 --speed-limit 1000' % databaseIP
|
||||||
|
os.system(DB_BashCommand_Mac)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = MyWindow()
|
window = MyWindow()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user