SIENTIAPDE-1231

Enhance type hinting and code structure in orchestrator activities

- Added type hints for better code clarity in `formatters.py`, `mongo_db.py`, `temporal_manager.py`, and `email_builder.py`.
- Updated `.gitignore` to include `coverage.xml` for improved coverage reporting.
- Improved readability by restructuring variable declarations and method signatures.
This commit is contained in:
vitor-aignosi
2025-10-16 08:52:38 -03:00
parent f3a6af5603
commit 6b826863f4
5 changed files with 51 additions and 20 deletions

View File

@@ -1,3 +1,5 @@
from typing import Any
from jinja2 import Template
from sientia_do.observability.logger import Logger
@@ -75,12 +77,12 @@ class EmailBuilder:
else '',
}
def build_email(self, report_data: list[dict], mail_type: str) -> str:
def build_email(self, report_data: list[dict[str, Any]], mail_type: str) -> str:
"""
Builds the email HTML by organizing report data by notification level and model.
Args:
report_data (list[dict]): List of notification reports, each containing:
report_data (List[Dict[str, Any]]): List of notification reports, each containing:
- level (str): Notification level (ERROR, WARNING, INFO)
- model_name (str): Name of the model
- Additional notification details
@@ -88,7 +90,7 @@ class EmailBuilder:
Returns:
str: Complete HTML email content ready for sending.
"""
general_events = {}
general_events: dict[str, dict[str, Any]] = {}
for report in report_data:
level = report['level']
@@ -100,13 +102,17 @@ class EmailBuilder:
'models': {},
}
if model_name not in general_events[level]['models']:
general_events[level]['models'][model_name] = {
# Type assertion to help the type checker understand the structure
level_data = general_events[level]
models_dict = level_data['models']
if model_name not in models_dict:
models_dict[model_name] = {
'model_name': model_name,
'events': [],
}
general_events[level]['models'][model_name]['events'].append(report)
models_dict[model_name]['events'].append(report)
for _type, content in general_events.items():
content['models'] = list(content['models'].values())