计算时附加电缆产品信息

This commit is contained in:
WIN-20230613SRA\Administrator
2026-07-06 18:06:55 +08:00
parent 98f47be9ff
commit 7e2b80aa3a
6 changed files with 79 additions and 23 deletions
+28
View File
@@ -1,8 +1,36 @@
from models import Product, Session from models import Product, Session
import uuid import uuid
from config import *
class ProductManager: class ProductManager:
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__() super().__init__()
self.cur_product_id = ""
config = read_config()
if config.get('product_id', '') == "":
try:
products = self.getInfo("all")
if products == []:
print("no product found in database")
else:
config.update(product_id = products[0]["id"])
save_config(config)
except:
pass
def setCurProductId(self, id):
self.cur_product_id = id
config = read_config()
if config.get('product_id', '') == id:
return
config.update(product_id = id)
save_config(config)
def getCurProductId(self):
return self.cur_product_id
def getCurrentProduct(self):
return self.getInfo(self.cur_product_id)
def create(self, info): def create(self, info):
data = { data = {
+13
View File
@@ -11,3 +11,16 @@ YSMODE = False
COREECTMODE = True COREECTMODE = True
def read_config():
config = {}
path = "/home/admin/.config/cpy/config.json"
with open(path, "r") as f:
config = json.load(f)
return config
return None
def save_config(config):
path = "/home/admin/.config/cpy/config.json"
with open(path, "w", encoding='utf-8') as f:
json.dump(config, f, indent=4)
+16 -1
View File
@@ -6,6 +6,7 @@ import os
import gzip import gzip
from io import BytesIO from io import BytesIO
from Manager.history_manager import historyManager from Manager.history_manager import historyManager
from Manager.product_manager import productManager
import json import json
from config import * from config import *
import logging import logging
@@ -406,7 +407,21 @@ class CpyMqttClient(QObject):
"row_count": str(row_count), "row_count": str(row_count),
"direction": direction "direction": direction
} }
try:
product_info = json.loads(productManager.getCurrentProduct().get("info", "{}"))
if product_info:
pinfo = {}
pinfo["OSC"] = float(product_info["WtOSC"]["bcz"])
pinfo["INS"] = float(product_info["WtINS"]["bcz"])
pinfo["ISC"] = float(product_info["WtISC"]["bcz"])
if pinfo["OSC"] > 0.1 or pinfo["INS"] > 0.1 or pinfo["ISC"] > 0.1:
info["product_info"] = pinfo
except Exception as e:
logger.error(f"Error in getCurrentProduct: {e}")
logger.info(f"info: {info}")
# 重置init标志 # 重置init标志
self.init = 0 self.init = 0
+2 -12
View File
@@ -14,6 +14,8 @@ import sqlite3
import sys import sys
import json import json
from Manager.product_manager import productManager
from x_ray_data_processor import processor from x_ray_data_processor import processor
def import_sql_to_database(db_path, table_bame): def import_sql_to_database(db_path, table_bame):
@@ -44,18 +46,6 @@ def get_cpu_serial():
return serial return serial
def read_config():
config = {}
path = "/home/admin/.config/cpy/config.json"
with open(path, "r") as f:
config = json.load(f)
return config
return None
def save_config(config):
path = "/home/admin/.config/cpy/config.json"
with open(path, "w", encoding='utf-8') as f:
json.dump(config, f, indent=4)
if __name__ == "__main__": if __name__ == "__main__":
app = QCoreApplication(sys.argv) app = QCoreApplication(sys.argv)
+10 -9
View File
@@ -4,7 +4,7 @@ import time
import base64 import base64
import socket import socket
import httpx import httpx
from config import *
from PySide6.QtCore import Signal, Slot,QObject,QMetaObject,Qt,QTimer from PySide6.QtCore import Signal, Slot,QObject,QMetaObject,Qt,QTimer
from Manager.product_manager import productManager from Manager.product_manager import productManager
from Manager.history_manager import historyManager from Manager.history_manager import historyManager
@@ -42,7 +42,7 @@ class MQTTClient(QObject):
self.remote_client = mqtt.Client(client_id=device_id) # 创建远程客户端 self.remote_client = mqtt.Client(client_id=device_id) # 创建远程客户端
self.device_client = mqtt.Client(client_id = 'controller_dev_' + self.random_string(6)) # 创建设备客户端 self.device_client = mqtt.Client(client_id = 'controller_dev_' + self.random_string(6)) # 创建设备客户端
self.m_clienttimestamp = 0 self.m_clienttimestamp = 0
self.cur_product_id = "C8111D73-F387-981D-18D5-849816E1793C"
# 设置回调函数 # 设置回调函数
self.local_client.on_connect = self.on_connect self.local_client.on_connect = self.on_connect
self.local_client.on_message = self.on_message self.local_client.on_message = self.on_message
@@ -246,7 +246,7 @@ class MQTTClient(QObject):
if json_obj.get("value") == "true": if json_obj.get("value") == "true":
cid = json_obj.get("cid") cid = json_obj.get("cid")
print("Follow,",cid) print("Follow,",cid)
self.send_current_product(self.cur_product_id) self.send_current_product(productManager.cur_product_id)
elif method == "input": elif method == "input":
key = json_obj.get("key") key = json_obj.get("key")
value = json_obj.get("value") value = json_obj.get("value")
@@ -303,10 +303,11 @@ class MQTTClient(QObject):
self.send_products() self.send_products()
elif method == "currentProduct": elif method == "currentProduct":
self.cur_product_id = json_obj.get("id") cur_product_id = json_obj.get("id")
print(f"Current product id: {self.cur_product_id}") print(f"Current product id: {cur_product_id}")
self.send_current_product(self.cur_product_id) self.send_current_product(cur_product_id)
self.send_current_product_id(self.cur_product_id) self.send_current_product_id(cur_product_id)
productManager.setCurProductId(cur_product_id)
elif method == "loadHistoryList": elif method == "loadHistoryList":
cid = json_obj.get("cid") cid = json_obj.get("cid")
@@ -571,10 +572,10 @@ class MQTTClient(QObject):
def send_products(self): def send_products(self):
"""发送产品信息""" """发送产品信息"""
data = dict() data = dict()
data["current_id"] = self.cur_product_id data["current_id"] = productManager.cur_product_id
data["method"] = "productList" data["method"] = "productList"
data["infos"] = productManager.getInfo() data["infos"] = productManager.getInfo()
print(f"Current product id: {self.cur_product_id}") print(f"Current product id: {productManager.cur_product_id}")
self.publish_cpy(TOPICPRODUCT, data, 1) # 发布设备信息 self.publish_cpy(TOPICPRODUCT, data, 1) # 发布设备信息
def start_ys(self, flag): def start_ys(self, flag):
+10 -1
View File
@@ -83,7 +83,10 @@ class XRayDataProcessor:
smoothed = gaussian_filter1d(data, sigma=sigma) smoothed = gaussian_filter1d(data, sigma=sigma)
# 2. 从头开始,若第data[k] - data[k + 50] > data[k] * 0.2,说明k是外侧极值点 # 2. 从头开始,若第data[k] - data[k + 50] > data[k] * 0.2,说明k是外侧极值点
outer_peaks = [100, len(data) - 100] if len(data) < 1000:
return [0, 0]
outer_peaks = [0, 0]
for k in range(len(data) - 50): for k in range(len(data) - 50):
if smoothed[k] - smoothed[k + 50] > smoothed[k] * peak_threshold: if smoothed[k] - smoothed[k + 50] > smoothed[k] * peak_threshold:
outer_peaks[0] = k outer_peaks[0] = k
@@ -150,6 +153,9 @@ class XRayDataProcessor:
# 为两个通道分别寻找区间 # 为两个通道分别寻找区间
ch1_spans = self._find_spans_for_channel('CH1') ch1_spans = self._find_spans_for_channel('CH1')
ch2_spans = self._find_spans_for_channel('CH2') ch2_spans = self._find_spans_for_channel('CH2')
if ch1_spans == [] or ch2_spans == []:
return False
# 为每个通道存储各自的区间 # 为每个通道存储各自的区间
success_count = 0 success_count = 0
@@ -185,6 +191,9 @@ class XRayDataProcessor:
# 至少有两个极值点,选择第一个和最后一个 # 至少有两个极值点,选择第一个和最后一个
p1 = potential_extremes[0] p1 = potential_extremes[0]
p2 = potential_extremes[-1] p2 = potential_extremes[-1]
if p1 == 0 and p2 == 0:
return []
# 计算区间边界: [p1*0.2, p1*0.9], [(n-p2)*0.1+p2, (n-p2)*0.7+p2] # 计算区间边界: [p1*0.2, p1*0.9], [(n-p2)*0.1+p2, (n-p2)*0.7+p2]
left_start_idx = max(0, int(p1 * 0.01)) left_start_idx = max(0, int(p1 * 0.01))