Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated alerts #186

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions api/app/models/alert_dto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Dict, List, Optional
from typing import List, Optional
from uuid import UUID

from pydantic import BaseModel, ConfigDict
Expand All @@ -9,10 +9,11 @@
class AnomalyType(str, Enum):
DATA_QUALITY = 'DATA_QUALITY'
MODEL_QUALITY = 'MODEL_QUALITY'
DRIFT = 'DRIFT'
DRIFT = 'DATA_DRIFT'


class AlertDTO(BaseModel):
model_name: str
model_uuid: UUID
reference_uuid: Optional[UUID]
current_uuid: Optional[UUID]
Expand All @@ -24,11 +25,3 @@ class AlertDTO(BaseModel):
populate_by_name=True,
alias_generator=to_camel,
)

@staticmethod
def from_dict(
alert_data: Optional[Dict],
) -> 'AlertDTO':
"""Create a AlertDTO from a dictionary of data."""

return AlertDTO.model_validate(alert_data)
39 changes: 19 additions & 20 deletions api/app/services/model_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,25 @@ def get_last_n_alerts(self, n_alerts) -> List[AlertDTO]:
return res
if 0 <= metrics.percentages[perc]['value'] < 1:
res.append(
AlertDTO.from_dict(
{
'model_uuid': model.uuid,
'reference_uuid': latest_reference_dataset.uuid
if latest_reference_dataset
else None,
'current_uuid': latest_current_dataset.uuid
if latest_current_dataset
else None,
'anomaly_type': AnomalyType[perc.upper()],
'anomaly_features': [
x['feature_name']
for x in sorted(
metrics.percentages[perc]['details'],
key=lambda e: e['score'],
reverse=True,
)
if x['score'] > 0
],
}
AlertDTO(
model_name=model.name,
model_uuid=model.uuid,
reference_uuid=latest_reference_dataset.uuid
if latest_reference_dataset
else None,
current_uuid=latest_current_dataset.uuid
if latest_current_dataset
else None,
anomaly_type=AnomalyType[perc.upper()],
anomaly_features=[
x['feature_name']
for x in sorted(
metrics.percentages[perc]['details'],
key=lambda e: e['score'],
reverse=True,
)
if x['score'] > 0
],
)
)
count_alerts += 1
Expand Down
30 changes: 14 additions & 16 deletions api/tests/routes/model_route_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,21 @@ def test_get_last_n_alerts(self):
)

sample_alerts_out = [
AlertDTO.from_dict(
{
'model_uuid': model1.uuid,
'reference_uuid': None,
'current_uuid': current1.uuid,
'anomaly_type': AnomalyType.DRIFT,
'anomaly_features': ['num1', 'num2'],
}
AlertDTO(
model_name=model1.name,
model_uuid=model1.uuid,
reference_uuid=None,
current_uuid=current1.uuid,
anomaly_type=AnomalyType.DRIFT,
anomaly_features=['num1', 'num2'],
),
AlertDTO.from_dict(
{
'model_uuid': model0.uuid,
'reference_uuid': None,
'current_uuid': current0.uuid,
'anomaly_type': AnomalyType.DRIFT,
'anomaly_features': ['num1', 'num2'],
}
AlertDTO(
model_name=model0.name,
model_uuid=model0.uuid,
reference_uuid=None,
current_uuid=current0.uuid,
anomaly_type=AnomalyType.DRIFT,
anomaly_features=['num1', 'num2'],
),
]

Expand Down