-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscenario.py
More file actions
137 lines (116 loc) · 6.26 KB
/
scenario.py
File metadata and controls
137 lines (116 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# coding: utf-8
"""
Pandemos
API for visualization of Infection Models
The version of the OpenAPI document: 1
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from datetime import date, datetime
import uuid
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from app.models.intervention_implementation import InterventionImplementation
from app.models.parameter_value import ParameterValue
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class Scenario(BaseModel):
"""
Scenario
""" # noqa: E501
id: Optional[StrictStr] = Field(default_factory=uuid.uuid4)
name: StrictStr = Field(description="Display Name of the object")
description: Optional[StrictStr] = Field(default=None, description="(Tooltip) Description of the object")
start_date: date = Field(alias="startDate", description="First date of the scenario")
end_date: date = Field(alias="endDate", description="Last date of the scenario")
model_id: StrictStr = Field(description="UUID of the model this scenario belongs to", alias="modelId")
model_parameters: List[ParameterValue] = Field(description="List of (available) model parameters (UUIDs & values)", alias="modelParameters")
node_list_id: StrictStr = Field(description="UUID of the node list (districts etc.) of this scenario", alias="nodeListId")
linked_interventions: Optional[List[InterventionImplementation]] = Field(default=None, description="List of intervention implementations used in this scenario", alias="linkedInterventions")
percentiles: Optional[List[StrictInt]] = Field(default=[50], description="List of available percentiles for this scenario", alias="percentiles")
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")
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")
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,
"protected_namespaces": (),
}
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Self:
"""Create an instance of Scenario from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
"""
_dict = self.model_dump(
by_alias=True,
exclude={
"id",
"timestamp_submitted",
"timestamp_simulated",
},
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of each item in model_parameters (list)
_items = []
if self.model_parameters:
for _item in self.model_parameters:
if _item:
_items.append(_item.to_dict())
_dict['modelParameters'] = _items
# override the default output from pydantic by calling `to_dict()` of each item in linked_interventions (list)
_items = []
if self.linked_interventions:
for _item in self.linked_interventions:
if _item:
_items.append(_item.to_dict())
_dict['linkedInterventions'] = _items
return _dict
@classmethod
def from_dict(cls, obj: Dict) -> Self:
"""Create an instance of Scenario from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"id": obj.get("id"),
"name": obj.get("name"),
"description": obj.get("description"),
"startDate": obj.get("startDate"),
"endDate": obj.get("endDate"),
"modelId": obj.get("modelId"),
"modelParameters": [ParameterValue.from_dict(_item) for _item in obj.get("modelParameters")] if obj.get("modelParameters") is not None else None,
"nodeListId": obj.get("nodeListId"),
"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"),
"whitelist": obj.get("whitelist"),
})
return _obj