SIENTIAPDE-1110
Refactor OPC activity and OpcRepository to include metadata parameter in write_data methods, improving error handling and logging capabilities for better traceability.
This commit is contained in:
@@ -23,7 +23,6 @@ class OPC(BaseActivity):
|
||||
self.opc_servers = opc_servers
|
||||
|
||||
self.opc_repository = {}
|
||||
self.logger.debug(f"OPC servers: {opc_servers}")
|
||||
for id, server in opc_servers.items():
|
||||
self.opc_repository[id] = OpcRepository(
|
||||
id=server['id'],
|
||||
@@ -41,7 +40,7 @@ class OPC(BaseActivity):
|
||||
BaseActivity.__init__(self, logger, notification_handler)
|
||||
|
||||
def write_data(self, server_id: str, tag: str, data: Any,
|
||||
data_type: str, tag_type: str) -> bool:
|
||||
data_type: str, tag_type: str, metadata: dict[str, Any]) -> bool:
|
||||
"""
|
||||
Write data to OPC server.
|
||||
|
||||
@@ -58,8 +57,7 @@ class OPC(BaseActivity):
|
||||
|
||||
try:
|
||||
return self.opc_repository[server_id].write_data(
|
||||
tag, data, data_type)
|
||||
self.logger.debug(f"Wrote {tag_type} to {tag}")
|
||||
tag, data, data_type, self, metadata)
|
||||
except Exception as e:
|
||||
trace = traceback.format_exc()
|
||||
self.notification_handler.build_and_send_notification(
|
||||
@@ -98,8 +96,6 @@ class OPC(BaseActivity):
|
||||
|
||||
success = True
|
||||
|
||||
self.logger.debug(f"OPC output config: {opc_output_config}")
|
||||
self.logger.debug(f"OPC servers: {self.opc_repository}")
|
||||
for server_id, config in opc_output_config.items():
|
||||
if self.opc_repository.get(server_id) is None:
|
||||
self.error(f"OPC server {server_id} not found", metadata)
|
||||
@@ -112,7 +108,8 @@ class OPC(BaseActivity):
|
||||
tag=tag,
|
||||
data=data.head(1)['prediction'].values[0],
|
||||
data_type=tag_config['data_type'],
|
||||
tag_type='prediction'
|
||||
tag_type='prediction',
|
||||
metadata=metadata
|
||||
)
|
||||
|
||||
if 'confidence_tags' in config:
|
||||
@@ -122,7 +119,8 @@ class OPC(BaseActivity):
|
||||
tag=tag,
|
||||
data=data.head(1)['prediction_confidence'].values[0],
|
||||
data_type=tag_config['data_type'],
|
||||
tag_type='confidence'
|
||||
tag_type='confidence',
|
||||
metadata=metadata
|
||||
)
|
||||
|
||||
return self.process_confidence(data, success, metadata)
|
||||
|
||||
Reference in New Issue
Block a user