Skip to content
Draft
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
6 changes: 4 additions & 2 deletions api/src/api/app/apis/scenarios_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ async def import_scenario_data(
tags=["Scenarios"],
response_model_by_alias=True,
)
async def list_scenarios() -> List[ReducedScenario]:
async def list_scenarios(
simulatedFilter: Annotated[Optional[bool], Field(description="Filter for scenario query; None - no filter, return all scenarios, True - only return simulated, False - only return unsimulated")] = Query(None, description="Return only simulated scenarios; if False, only return unsimulated scenarios", alias="simulated")
) -> List[ReducedScenario]:
"""List all available scenarios."""
return await controller.list_scenarios()
return await controller.list_scenarios(simulatedFilter)

# a toy endpoint to test authorization
@router.post(
Expand Down
3 changes: 2 additions & 1 deletion api/src/api/app/controller/scenario_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ async def get_scenario(

async def list_scenarios(
self,
simulatedFilter: bool | None,
) -> List[ReducedScenario]:
"""List all available scenarios."""
return scenario_get_all()
return scenario_get_all(simulatedFilter)

async def get_infection_data(
self,
Expand Down
2 changes: 2 additions & 0 deletions api/src/api/app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Scenario(SQLModel, table=True):
creatorUserId: Optional[uuid.UUID] = Field(default=None, nullable=True)
creatorOrgId: Optional[str] = Field(default=None, nullable=True)

whitelist: Optional[str] = Field(default=None, nullable=True)

class ParameterDefinition(SQLModel, table=True):
id: Optional[uuid.UUID] = Field(default_factory=uuid.uuid4, primary_key=True, nullable=False)
name: Optional[str] = Field(nullable=False)
Expand Down
10 changes: 9 additions & 1 deletion api/src/api/app/db/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,16 @@ def scenario_get_by_id(id: StrictStr) -> Scenario:
creator_org_id=scenario.creatorOrgId
)

def scenario_get_all() -> List[ReducedScenario]:
def scenario_get_all(simulatedFilter: bool | None) -> List[ReducedScenario]:
query = select(db.Scenario)
# Check simulated filter and add where if filter is present
if simulatedFilter is None:
pass
elif simulatedFilter:
query = query.where(db.Scenario.timestampSimulated is not None)
else:
query = query.where(db.Scenario.timestampSimulated is None)

with next(get_session()) as session:
scenarios: List[db.Scenario] = session.exec(query).all()
return [ReducedScenario(
Expand Down
4 changes: 3 additions & 1 deletion api/src/api/app/models/reduced_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class ReducedScenario(BaseModel):
percentiles: Optional[List[StrictInt]] = Field(default=None, alias="percentiles", description="List of available percentiles for this scenario")
timestamp_submitted: Optional[datetime] = Field(default=None, alias="timestampSubmitted", description="Timestamp when the scenario was added/created")
timestamp_simulated: Optional[datetime] = Field(default=None, alias="timestampSimulated", description="Timestamp when the scenario was finished simulating and data is available")
__properties: ClassVar[List[str]] = ["id", "name", "description", "startDate", "endDate", "timestamp_submitted", "timestamp_simulated"]
whitelist: Optional[List[StrictStr]] = Field(default=None, alias="whitelist", description="Whitelist of Organizations with access to this scenario")
__properties: ClassVar[List[str]] = ["id", "name", "description", "startDate", "endDate", "percentiles", "timestamp_submitted", "timestamp_simulated", "whitelist"]

model_config = {
"populate_by_name": True,
Expand Down Expand Up @@ -101,6 +102,7 @@ def from_dict(cls, obj: Dict) -> Self:
"percentiles": obj.get("percentiles"),
"timestamp_submitted": obj.get("timestamp_submitted"),
"timestamp_simulated": obj.get("timestamp_simulated"),
"whitelist": obj.get("whitelist"),
})
return _obj

Expand Down
6 changes: 4 additions & 2 deletions api/src/api/app/models/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class Scenario(BaseModel):
timestamp_simulated: Optional[datetime] = Field(default=None, alias="timestampSimulated", description="Timestamp when the scenario was finished simulating and data is available")
creator_user_id: Optional[str] = Field(default=None, alias="creatorUserId", description="ID of the user who submitted the scenario")
creator_org_id: Optional[str] = Field(default=None, alias="creatorOrgId", description="ID of the organization the submitting user belongs to")
__properties: ClassVar[List[str]] = ["id", "name", "description", "startDate", "endDate", "modelId", "modelParameters", "nodeListId", "linkedInterventions", "percentiles", "timestampSubmitted", "timestampSimulated", "creatorUserId", "creatorOrgId"]
whitelist: Optional[List[StrictStr]] = Field(default=None, alias="whitelist", description="Whitelist of Organizations with access to this scenario")
__properties: ClassVar[List[str]] = ["id", "name", "description", "startDate", "endDate", "modelId", "modelParameters", "nodeListId", "linkedInterventions", "percentiles", "timestampSubmitted", "timestampSimulated", "creatorUserId", "creatorOrgId", "whitelist"]
model_config = {
"populate_by_name": True,
"validate_assignment": True,
Expand Down Expand Up @@ -130,6 +131,7 @@ def from_dict(cls, obj: Dict) -> Self:
"linkedInterventions": [InterventionImplementation.from_dict(_item) for _item in obj.get("linkedInterventions")] if obj.get("linkedInterventions") is not None else None,
"percentiles": obj.get("percentiles"),
"timestampSubmitted": obj.get("timestampSubmitted"),
"timestampSimulated": obj.get("timestampSimulated")
"timestampSimulated": obj.get("timestampSimulated"),
"whitelist": obj.get("whitelist"),
})
return _obj