diff --git a/compute_service.py b/compute_service.py index ecfcb60..67eb75e 100644 --- a/compute_service.py +++ b/compute_service.py @@ -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,12 +157,20 @@ 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: mat_data['InStruct']['Settings'][0, 0][0, 9] = 1 @@ -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'}) diff --git a/cpy_server.py b/cpy_server.py index 9f56ff7..bbe3dc8 100644 --- a/cpy_server.py +++ b/cpy_server.py @@ -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