增加对产品信息的支持
This commit is contained in:
+17
-9
@@ -98,7 +98,7 @@ class ComputeService:
|
||||
}
|
||||
logger.info("Data buffer reset")
|
||||
|
||||
def csv_to_mat(self, csv_path: str, init: int = 0) -> Optional[str]:
|
||||
def csv_to_mat(self, csv_path: str, init: int = 0, metadata: Optional[Dict[str, Any]] = None) -> Optional[str]:
|
||||
"""将CSV文件转换为MAT文件
|
||||
|
||||
Args:
|
||||
@@ -157,11 +157,19 @@ class ComputeService:
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 0] = 4
|
||||
|
||||
# 设置其他参数
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 2] = 1.1
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 3] = 10.5
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 4] = 1.1
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 5] = 46
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 6] = 20.5
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 2] = 1.0 #内屏
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 3] = 10.5 #绝缘
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 4] = 1.0 #外屏
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 5] = 46 #总直径
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 6] = 20.5 #导体直径
|
||||
|
||||
if metadata and 'product_info' in metadata:
|
||||
try:
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 2] = metadata.get('product_info', {}).get('ISC', 1.0) #内屏
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 3] = metadata.get('product_info', {}).get('INS', 10.5) #绝缘
|
||||
mat_data['InStruct']['Settings'][0, 0][0, 4] = metadata.get('product_info', {}).get('OSC', 1.0) #外屏
|
||||
except:
|
||||
pass
|
||||
|
||||
# 设置初始化标志
|
||||
if init:
|
||||
@@ -398,7 +406,7 @@ class ComputeService:
|
||||
ret['EdgesB'].sort()
|
||||
|
||||
# 如果是direction_1,需要反转边缘数据
|
||||
if 'direction_1' in out_path:
|
||||
if 'direction_1' in out_path or 'UP' in out_path:
|
||||
rawDataLen = len(mat_data['OutStruct']['NormVideoX'][0, 0].flatten().tolist())
|
||||
width = rawDataLen * 0.04
|
||||
for i in range(len(ret['EdgesB'])):
|
||||
@@ -454,7 +462,7 @@ class ComputeService:
|
||||
logger.error(f"Compute failed: {e}")
|
||||
return None, None
|
||||
|
||||
def compute_file(self, csv_path: str, init: int = 0) -> Optional[str]:
|
||||
def compute_file(self, csv_path: str, init: int = 0, metadata: Optional[Dict[str, Any]] = None) -> Optional[str]:
|
||||
"""计算CSV文件
|
||||
|
||||
Args:
|
||||
@@ -472,7 +480,7 @@ class ComputeService:
|
||||
self.reset_buffer()
|
||||
|
||||
# 转换CSV到MAT
|
||||
mat_path = self.csv_to_mat(csv_path, init)
|
||||
mat_path = self.csv_to_mat(csv_path, init, metadata)
|
||||
|
||||
if not mat_path:
|
||||
return json.dumps({'error': 'Failed to convert CSV to MAT'})
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ class CpyServer:
|
||||
return
|
||||
|
||||
try:
|
||||
result_json = compute_service.compute_file(file_path, init)
|
||||
result_json = compute_service.compute_file(file_path, init, metadata)
|
||||
except Exception as e:
|
||||
self.mqtt_ack('calculate', dev_id, f'ComputeService error: {e}', 400, msg_uuid)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user