修复切换其他工程后历史趋势无法显示问题

main
zcwBit 3 months ago
parent 42ff71796c
commit da5d22bb68

@ -299,6 +299,7 @@ class TrendWidgets(QWidget):
def exchangeProject(self): def exchangeProject(self):
# 项目切换时调用 # 项目切换时调用
# self.historyDB = None
self.historyDB = Globals.getValue('historyDBManage') self.historyDB = Globals.getValue('historyDBManage')
self.refreshVarList() self.refreshVarList()
@ -306,9 +307,9 @@ class TrendWidgets(QWidget):
# 刷新变量列表 # 刷新变量列表
self.varListWidget.clear() self.varListWidget.clear()
self.statusLabel.setText("正在加载变量列表...") self.statusLabel.setText("正在加载变量列表...")
if not self.historyDB or not hasattr(self.historyDB, 'getAllVarNames'): if not self.historyDB:
self.statusLabel.setText("未连接历史数据库,无法获取变量列表") self.statusLabel.setText("未连接历史数据库,无法获取变量列表")
return self.historyDB = Globals.getValue('historyDBManage')
varNames = self.historyDB.getAllVarNames() varNames = self.historyDB.getAllVarNames()
# print(varNames) # print(varNames)
# 对变量名称进行排序 # 对变量名称进行排序
@ -760,7 +761,7 @@ class TrendWidgets(QWidget):
if len(data_lines) == 0: if len(data_lines) == 0:
# 没有数据线时不创建十字标线 # 没有数据线时不创建十字标线
print("没有数据线,跳过十字标线创建") # print("没有数据线,跳过十字标线创建")
return return
try: try:
@ -830,12 +831,12 @@ class TrendWidgets(QWidget):
va='bottom' va='bottom'
) )
print("✅ 十字标线组件创建完成") # print("✅ 十字标线组件创建完成")
except Exception as e: except Exception as e:
# 如果创建失败,清理并重置引用 # 如果创建失败,清理并重置引用
self._cleanupCrosshair() self._cleanupCrosshair()
print(f"❌ 创建十字标线失败: {e}") # print(f"❌ 创建十字标线失败: {e}")
def _cleanupCrosshair(self): def _cleanupCrosshair(self):
"""清理十字标线组件""" """清理十字标线组件"""
@ -867,7 +868,7 @@ class TrendWidgets(QWidget):
# 如果十字标线组件不存在,直接返回 # 如果十字标线组件不存在,直接返回
if (self.crosshair_v is None or self.crosshair_h is None or if (self.crosshair_v is None or self.crosshair_h is None or
self.crosshair_point is None or self.crosshair_text is None): self.crosshair_point is None or self.crosshair_text is None):
print("十字标线组件不存在,无法更新") # print("十字标线组件不存在,无法更新")
return return
try: try:

@ -26,6 +26,7 @@ class HistoryDBManage:
self.host = host self.host = host
self.token = token self.token = token
self.org = org self.org = org
# print(self.table, 1111111111111111)
# 写入回调 # 写入回调
def onSuccess(conf, data, exception=None): def onSuccess(conf, data, exception=None):
@ -119,7 +120,7 @@ class HistoryDBManage:
if isinstance(df, pd.DataFrame): if isinstance(df, pd.DataFrame):
data = df["value"].tolist() if "value" in df.columns else [] data = df["value"].tolist() if "value" in df.columns else []
timeList = df["time"].tolist() if "time" in df.columns else [] timeList = df["time"].tolist() if "time" in df.columns else []
print(f"查询到 {len(data)} 个数据点") # print(f"查询到 {len(data)} 个数据点")
else: else:
# print(f"查询结果不是DataFrame: {type(df)}") # print(f"查询结果不是DataFrame: {type(df)}")
data, timeList = [], [] data, timeList = [], []
@ -150,7 +151,9 @@ class HistoryDBManage:
"""获取所有去重后的变量名列表""" """获取所有去重后的变量名列表"""
sql = f'SELECT DISTINCT("varName") FROM "{self.table}"' sql = f'SELECT DISTINCT("varName") FROM "{self.table}"'
try: try:
# print(self.table, 2222222222222222)
df = self.client.query(sql, mode="pandas") df = self.client.query(sql, mode="pandas")
# print(df)
import pandas as pd import pandas as pd
if isinstance(df, pd.DataFrame) and 'varName' in df.columns: if isinstance(df, pd.DataFrame) and 'varName' in df.columns:
return df['varName'].tolist() return df['varName'].tolist()
@ -195,17 +198,17 @@ class HistoryDBManage:
self.stopWriteThread() self.stopWriteThread()
self.client.close() self.client.close()
if __name__ == '__main__': # if __name__ == '__main__':
db = HistoryDBManage( # db = HistoryDBManage(
database="dcs", # database="dcs",
table="p1", # table="p1",
host="http://localhost:8181", # host="http://localhost:8181",
token="apiv3_ynlNTgq_OX164srSzjYXetWZJGOpgokFJbp_JaToWYlzwIPAZboPxKt4ss6vD1_4jj90QOIDnRDodQSJ66m3_g", # token="apiv3_ynlNTgq_OX164srSzjYXetWZJGOpgokFJbp_JaToWYlzwIPAZboPxKt4ss6vD1_4jj90QOIDnRDodQSJ66m3_g",
org="dcs" # org="dcs"
) # )
data, times = db.queryVarHistory("有源/无源4-20mA输入通道1") # data, times = db.queryVarHistory("有源/无源4-20mA输入通道1")
print(data, times) # print(data, times)
db.close() # db.close()

@ -279,17 +279,6 @@ class ProjectManage(object):
popenBeat = subprocess.Popen('celery -A HARTTask beat', stdout=subprocess.PIPE, cwd = 'protocol/Celery/HARTCelery') popenBeat = subprocess.Popen('celery -A HARTTask beat', stdout=subprocess.PIPE, cwd = 'protocol/Celery/HARTCelery')
Globals.setValue('beatPopen', popenBeat) Globals.setValue('beatPopen', popenBeat)
@classmethod
def recordingHistory(self, projectName, cursor):
# 记录打开通讯的时间 并创建INFLUXDB表
curTime = time.time()
# influxMem = InfluxMem()
# influxMem.createMem(time)
curTime = float("{:.5f}".format(curTime))
cursor.execute('insert into InfluxMem (mem) values ({})'.format(str(curTime)))
historyDB = HistoryDBManage(mem = curTime, bucket = projectName, isCelery = True)
return historyDB
@classmethod @classmethod
def editProject(self, name, Nname, des): def editProject(self, name, Nname, des):

Loading…
Cancel
Save