-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
140 additions
and
58 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
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,15 @@ | ||
from flask.testing import FlaskClient | ||
from http import HTTPStatus | ||
|
||
from trailblazer.store.models import Analysis | ||
|
||
|
||
def test_get_summaries(client: FlaskClient, analysis: Analysis): | ||
# GIVEN an order with an analysis | ||
order_id: int = analysis.order_id | ||
|
||
# WHEN requesting a summary for the analyses in the order | ||
response = client.get(f"/api/v1/summary?orderIds={order_id}") | ||
|
||
# THEN it gives a success response | ||
assert response.status_code == HTTPStatus.OK |
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,10 @@ | ||
from typing_extensions import Annotated | ||
from pydantic import BaseModel, BeforeValidator, Field, ValidationInfo | ||
|
||
|
||
def parse_order_ids(v: str) -> list[str]: | ||
return v[0].split(",") if v else [] | ||
|
||
|
||
class SummariesRequest(BaseModel): | ||
order_ids: Annotated[list[int], BeforeValidator(parse_order_ids)] = Field(alias="orderIds") |
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,14 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class Summary(BaseModel): | ||
order_id: int | ||
total: int | ||
delivered: int | ||
running: int | ||
cancelled: int | ||
failed: int | ||
|
||
|
||
class SummariesResponse(BaseModel): | ||
summaries: list[Summary] |
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
Empty file.
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,41 @@ | ||
from trailblazer.constants import TrailblazerStatus | ||
from trailblazer.dto.analyses_response import UpdateAnalysesResponse | ||
from trailblazer.dto.analysis_response import AnalysisResponse | ||
from trailblazer.dto.summaries_response import Summary | ||
from trailblazer.store.models import Analysis | ||
|
||
|
||
def get_status_count(analyses: list[Analysis], status: TrailblazerStatus) -> int: | ||
return len([a for a in analyses if a.status == status]) | ||
|
||
|
||
def create_summary(analyses: list[Analysis], order_id: int) -> Summary: | ||
total: int = len(analyses) | ||
delivered: int = get_status_count(analyses=analyses, status=TrailblazerStatus.COMPLETED) | ||
running: int = get_status_count(analyses=analyses, status=TrailblazerStatus.RUNNING) | ||
cancelled: int = get_status_count(analyses=analyses, status=TrailblazerStatus.CANCELLED) | ||
failed = get_status_count(analyses=analyses, status=TrailblazerStatus.FAILED) | ||
return Summary( | ||
order_id=order_id, | ||
total=total, | ||
delivered=delivered, | ||
running=running, | ||
cancelled=cancelled, | ||
failed=failed, | ||
) | ||
|
||
|
||
def create_analysis_response(analysis: Analysis) -> AnalysisResponse: | ||
analysis_data: dict = analysis.to_dict() | ||
analysis_data["jobs"] = [job.to_dict() for job in analysis.analysis_jobs] | ||
analysis_data["upload_jobs"] = [job.to_dict() for job in analysis.upload_jobs] | ||
analysis_data["user"] = analysis.user.to_dict() if analysis.user else None | ||
return AnalysisResponse.model_validate(analysis_data) | ||
|
||
|
||
def create_update_analyses_response(analyses: list[Analysis]) -> UpdateAnalysesResponse: | ||
response_data: list[dict] = [] | ||
for analysis in analyses: | ||
analysis_data = analysis.to_dict() | ||
response_data.append(analysis_data) | ||
return UpdateAnalysesResponse(analyses=response_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from trailblazer.services.job_service.job_service import JobService |
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,13 @@ | ||
from trailblazer.dto.failed_jobs_response import FailedJobsResponse | ||
from trailblazer.dto.job_response import JobResponse | ||
from trailblazer.store.models import Job | ||
|
||
|
||
def create_job_response(job: Job) -> JobResponse: | ||
return JobResponse( | ||
slurm_id=job.slurm_id, analysis_id=job.analysis_id, status=job.status, id=job.id | ||
) | ||
|
||
|
||
def create_failed_jobs_response(failed_job_statistics: list[dict]) -> FailedJobsResponse: | ||
return FailedJobsResponse(jobs=failed_job_statistics) |
This file was deleted.
Oops, something went wrong.
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