-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add percentages dto and endpoint (#177)
* feat: added last_n percentages endpoint and percentages DTO * feat: merged main into branch * feat: alembic migration * feat: updated fastapi * feat: fixed orderby and limit and alembic
- Loading branch information
1 parent
9a66dc7
commit 5e61425
Showing
16 changed files
with
944 additions
and
1,030 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
api/alembic/versions/dccb82489f4d_add_percentage_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""add percentage column | ||
Revision ID: dccb82489f4d | ||
Revises: 6edab3f23907 | ||
Create Date: 2024-10-17 09:03:48.063883 | ||
""" | ||
from typing import Sequence, Union, Text | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from app.db.tables.commons.json_encoded_dict import JSONEncodedDict | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'dccb82489f4d' | ||
down_revision: Union[str, None] = '6edab3f23907' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('current_dataset_metrics', sa.Column('PERCENTAGES', JSONEncodedDict(astext_type=Text()), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('current_dataset_metrics', 'PERCENTAGES') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from typing import Dict, List, Optional | ||
|
||
from pydantic import BaseModel, ConfigDict | ||
from pydantic.alias_generators import to_camel | ||
|
||
from app.models.job_status import JobStatus | ||
|
||
|
||
class DetailPercentage(BaseModel): | ||
feature_name: str | ||
score: float | ||
|
||
|
||
class MetricPercentage(BaseModel): | ||
value: float | ||
details: List[Optional[DetailPercentage]] = None | ||
|
||
|
||
class Percentages(BaseModel): | ||
data_quality: MetricPercentage | ||
model_quality: MetricPercentage | ||
drift: MetricPercentage | ||
|
||
model_config = ConfigDict( | ||
populate_by_name=True, alias_generator=to_camel, protected_namespaces=() | ||
) | ||
|
||
|
||
class PercentagesDTO(BaseModel): | ||
job_status: JobStatus | ||
percentages: Optional[Percentages] | ||
|
||
model_config = ConfigDict( | ||
arbitrary_types_allowed=True, | ||
populate_by_name=True, | ||
alias_generator=to_camel, | ||
) | ||
|
||
@staticmethod | ||
def from_dict( | ||
job_status: JobStatus, | ||
percentages_data: Optional[Dict], | ||
) -> 'PercentagesDTO': | ||
"""Create a PercentagesDTO from a dictionary of data.""" | ||
percentages = PercentagesDTO._create_percentages( | ||
percentages_data=percentages_data | ||
) | ||
|
||
return percentages_data( | ||
job_status=job_status, | ||
percentages=percentages, | ||
) | ||
|
||
@staticmethod | ||
def _create_percentages( | ||
percentages_data: Optional[Dict], | ||
) -> Optional[Percentages]: | ||
"""Create a specific percentages instance from a dictionary of data.""" | ||
if not percentages_data: | ||
return None | ||
return Percentages(**percentages_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.