updated expert app notebook and tests

This commit is contained in:
Luis Aleixo 2023-03-23 12:02:19 +01:00
parent 1f6b3dd96e
commit 8a72d27fb1
3 changed files with 16 additions and 110 deletions

View file

@ -883,6 +883,9 @@ class CAIMIRAStateBuilder(state.StateBuilder):
# Note: The methods in this class must correspond to the *type* of the data classes.
# For example, build_type__VentilationBase is called when dealing with ConcentrationModel
# types as it has a ventilation: _VentilationBase field.
def __init__(self, selected_ventilation: str):
self.selected_ventilation = selected_ventilation
def build_type_Mask(self, _: dataclasses.Field):
return state.DataclassStatePredefined(
@ -901,6 +904,7 @@ class CAIMIRAStateBuilder(state.StateBuilder):
'HEPAFilter': self.build_generic(models.HEPAFilter),
},
base_type=self.selected_ventilation,
state_builder=self,
)
#Initialise the "Hinged window" state
@ -955,10 +959,10 @@ class ExpertApplication(Controller):
)
self.add_scenario('Scenario 1')
def build_new_model(self) -> state.DataclassInstanceState[models.ExposureModel]:
def build_new_model(self, vent: str) -> state.DataclassInstanceState[models.ExposureModel]:
default_model = state.DataclassInstanceState(
models.ExposureModel,
state_builder=CAIMIRAStateBuilder(),
state_builder=CAIMIRAStateBuilder(selected_ventilation=vent),
)
default_model.dcs_update_from(baseline_model)
# For the time-being, we have to initialise the select states. Careful
@ -967,9 +971,13 @@ class ExpertApplication(Controller):
return default_model
def add_scenario(self, name, copy_from_model: typing.Optional[state.DataclassInstanceState] = None):
model = self.build_new_model()
if copy_from_model is not None:
model = self.build_new_model(vent=copy_from_model.concentration_model.ventilation._selected)
model.dcs_update_from(copy_from_model.dcs_instance())
else:
model = self.build_new_model(vent='Natural') # Default
model.dcs_update_from(baseline_model)
self._model_scenarios.append((name, model))
self._active_scenario = len(self._model_scenarios) - 1
model.dcs_observe(self.notify_model_values_changed)

View file

@ -167,11 +167,14 @@ def test_DCS_predefined():
def test_DCS_named():
opt1 = DCSimpleSubclass('a', 1, 3.14)
opt2 = DCAnother(4.2)
s = state.DataclassStateNamed({
s = state.DataclassStateNamed(
states={
# Entirely different types possible.
'option 1': state.DataclassInstanceState(DCSimple),
'option 2': state.DataclassInstanceState(DCAnother),
})
},
base_type='option 1'
)
assert s._selected == 'option 1'
with pytest.raises(ValueError):

View file

@ -1,105 +0,0 @@
anyio==3.6.2
appnope==0.1.3
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asttokens==2.2.1
attrs==22.2.0
Babel==2.11.0
backcall==0.2.0
beautifulsoup4==4.11.2
bleach==6.0.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.0.1
cloudpickle==2.2.1
comm==0.1.2
contourpy==1.0.7
cycler==0.11.0
debugpy==1.6.6
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
executing==1.2.0
fastjsonschema==2.16.2
fonttools==4.38.0
h3==3.7.6
idna==3.4
importlib-metadata==6.0.0
importlib-resources==5.12.0
ipykernel==6.21.2
ipympl==0.9.3
ipython==8.10.0
ipython-genutils==0.2.0
ipywidgets==7.7.3
jedi==0.18.2
Jinja2==3.1.2
joblib==1.2.0
json5==0.9.11
jsonschema==4.17.3
jupyter-client==7.4.1
jupyter-core==5.2.0
jupyter-server==1.23.6
jupyterlab-pygments==0.2.2
jupyterlab-server==2.19.0
jupyterlab-widgets==1.1.2
kiwisolver==1.4.4
loky==3.3.0
MarkupSafe==2.1.2
matplotlib==3.7.0
matplotlib-inline==0.1.6
memoization==0.4.0
mistune==2.0.5
nbclassic==0.5.2
nbclient==0.7.2
nbconvert==7.2.9
nbformat==5.7.3
nest-asyncio==1.5.6
notebook==6.5.2
notebook-shim==0.2.2
numpy==1.24.2
packaging==23.0
pandas==1.5.3
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.4.0
platformdirs==3.0.0
prometheus-client==0.16.0
prompt-toolkit==3.0.37
psutil==5.9.4
ptyprocess==0.7.0
pure-eval==0.2.2
py==1.11.0
pycparser==2.21
Pygments==2.14.0
pyparsing==3.0.9
pyrsistent==0.19.3
python-dateutil==2.8.2
pytz==2022.7.1
pyzmq==25.0.0
requests==2.28.2
retry==0.9.2
scikit-learn==1.2.1
scipy==1.10.1
Send2Trash==1.8.0
six==1.16.0
sniffio==1.3.0
soupsieve==2.4
stack-data==0.6.2
terminado==0.17.1
threadpoolctl==3.1.0
timezonefinder==6.1.9
tinycss2==1.2.1
tornado==6.2
traitlets==5.9.0
types-retry==0.9.9.2
urllib3==1.26.14
voila==0.4.0
wcwidth==0.2.6
webencodings==0.5.1
websocket-client==1.5.1
websockets==10.4
wheel==0.36.2
widgetsnbextension==3.6.2
zipp==3.14.0