增加对产品信息的支持
This commit is contained in:
+18
-10
@@ -98,7 +98,7 @@ class ComputeService:
|
|||||||
}
|
}
|
||||||
logger.info("Data buffer reset")
|
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文件
|
"""将CSV文件转换为MAT文件
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -157,12 +157,20 @@ class ComputeService:
|
|||||||
mat_data['InStruct']['Settings'][0, 0][0, 0] = 4
|
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, 2] = 1.0 #内屏
|
||||||
mat_data['InStruct']['Settings'][0, 0][0, 3] = 10.5
|
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, 4] = 1.0 #外屏
|
||||||
mat_data['InStruct']['Settings'][0, 0][0, 5] = 46
|
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, 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:
|
if init:
|
||||||
mat_data['InStruct']['Settings'][0, 0][0, 9] = 1
|
mat_data['InStruct']['Settings'][0, 0][0, 9] = 1
|
||||||
@@ -398,7 +406,7 @@ class ComputeService:
|
|||||||
ret['EdgesB'].sort()
|
ret['EdgesB'].sort()
|
||||||
|
|
||||||
# 如果是direction_1,需要反转边缘数据
|
# 如果是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())
|
rawDataLen = len(mat_data['OutStruct']['NormVideoX'][0, 0].flatten().tolist())
|
||||||
width = rawDataLen * 0.04
|
width = rawDataLen * 0.04
|
||||||
for i in range(len(ret['EdgesB'])):
|
for i in range(len(ret['EdgesB'])):
|
||||||
@@ -454,7 +462,7 @@ class ComputeService:
|
|||||||
logger.error(f"Compute failed: {e}")
|
logger.error(f"Compute failed: {e}")
|
||||||
return None, None
|
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文件
|
"""计算CSV文件
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -472,7 +480,7 @@ class ComputeService:
|
|||||||
self.reset_buffer()
|
self.reset_buffer()
|
||||||
|
|
||||||
# 转换CSV到MAT
|
# 转换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:
|
if not mat_path:
|
||||||
return json.dumps({'error': 'Failed to convert CSV to MAT'})
|
return json.dumps({'error': 'Failed to convert CSV to MAT'})
|
||||||
|
|||||||
+1
-1
@@ -127,7 +127,7 @@ class CpyServer:
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result_json = compute_service.compute_file(file_path, init)
|
result_json = compute_service.compute_file(file_path, init, metadata)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.mqtt_ack('calculate', dev_id, f'ComputeService error: {e}', 400, msg_uuid)
|
self.mqtt_ack('calculate', dev_id, f'ComputeService error: {e}', 400, msg_uuid)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user