fix: sent partial results
All checks were successful
Build Worker Base and Application Images / check-base-changes (push) Successful in 7s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 3m40s
Build Worker Base and Application Images / deploy-stack (push) Successful in 15s

This commit is contained in:
ziesorx 2025-10-20 17:54:50 +07:00
parent 10c54bc6e0
commit 0dd1b9f5c2
2 changed files with 155 additions and 19 deletions

View file

@ -445,6 +445,78 @@ class DetectionPipeline:
except Exception as e:
logger.error(f"Error sending initial detection imageDetection message: {e}", exc_info=True)
async def _send_classification_results(self, subscription_id: str, session_id: str, branch_results: Dict[str, Any]):
"""
Send imageDetection message with classification results (without license plate).
Called after processing phase completes to send partial results immediately.
Args:
subscription_id: Subscription identifier to send message to
session_id: Session identifier
branch_results: Dictionary of branch execution results
"""
try:
if not self.message_sender:
logger.warning("No message sender configured, cannot send imageDetection")
return
# Import here to avoid circular imports
from ..communication.models import ImageDetectionMessage, DetectionData
# Extract classification fields from branch results
extracted_fields = self._extract_fields_from_branches(branch_results)
car_brand = extracted_fields.get('brand')
body_type = extracted_fields.get('body_type')
# Log what we're sending
fields_status = []
if car_brand is not None:
fields_status.append(f"brand={car_brand}")
else:
fields_status.append("brand=null")
if body_type is not None:
fields_status.append(f"bodyType={body_type}")
else:
fields_status.append("bodyType=null")
logger.info(f"[CLASSIFICATION] Sending partial results for session {session_id}: {', '.join(fields_status)}")
# Create detection data with classification results (license plate still pending)
detection_data_obj = DetectionData(
detection={
"carBrand": car_brand,
"carModel": None, # Not implemented yet
"bodyType": body_type,
"licensePlateText": None, # Will be sent later via license plate callback
"licensePlateConfidence": None
},
modelId=self.model_id,
modelName=self.pipeline_parser.pipeline_config.model_id if self.pipeline_parser.pipeline_config else "detection_model"
)
# Create imageDetection message
detection_message = ImageDetectionMessage(
subscriptionIdentifier=subscription_id,
data=detection_data_obj
)
# Send message
await self.message_sender(detection_message)
# Log with indication of partial results
null_fields = []
if car_brand is None:
null_fields.append('brand')
if body_type is None:
null_fields.append('bodyType')
if null_fields:
logger.info(f"[PARTIAL RESULTS] Sent imageDetection with PARTIAL results (null: {', '.join(null_fields)}) - brand='{car_brand}', bodyType='{body_type}' to '{subscription_id}'")
else:
logger.info(f"[CLASSIFICATION COMPLETE] Sent imageDetection with brand='{car_brand}', bodyType='{body_type}' to '{subscription_id}'")
except Exception as e:
logger.error(f"Error sending classification results imageDetection message: {e}", exc_info=True)
async def execute_detection_phase(self,
frame: np.ndarray,
display_id: str,
@ -693,6 +765,13 @@ class DetectionPipeline:
self.session_processing_results[session_id] = result['branch_results']
logger.info(f"[PROCESSING RESULTS] Stored results for session {session_id} for later combination")
# Send classification results immediately (license plate will come later via callback)
await self._send_classification_results(
subscription_id=subscription_id,
session_id=session_id,
branch_results=result['branch_results']
)
logger.info(f"Processing phase completed for session {session_id}: "
f"{len(result['branch_results'])} branches, {len(result['actions_executed'])} actions")