ToggleButtons options and import errors solved

This commit is contained in:
Luis Aleixo 2021-11-24 10:09:52 +01:00
parent 440e022152
commit 214ee14c42
3 changed files with 14 additions and 28 deletions

View file

@ -13,7 +13,6 @@ from cara import models
from cara import state from cara import state
from cara import data from cara import data
from IPython.display import display, Markdown
def collapsible(widgets_to_collapse: typing.List, title: str, start_collapsed=False): def collapsible(widgets_to_collapse: typing.List, title: str, start_collapsed=False):
collapsed = widgets.Accordion([widgets.VBox(widgets_to_collapse)]) collapsed = widgets.Accordion([widgets.VBox(widgets_to_collapse)])
@ -354,7 +353,7 @@ class ModelWidgets(View):
# TODO: Link the state back to the widget, not just the other way around. # TODO: Link the state back to the widget, not just the other way around.
q_air_mech.observe(q_air_mech_change, names=['value']) q_air_mech.observe(q_air_mech_change, names=['value'])
return q_air_mech return widgets.HBox([q_air_mech, widgets.Label('m³/h')])
def _build_ach(self, node): def _build_ach(self, node):
air_exch = widgets.IntSlider(value=node.air_exch, min=0, max=50, step=5) air_exch = widgets.IntSlider(value=node.air_exch, min=0, max=50, step=5)
@ -365,20 +364,20 @@ class ModelWidgets(View):
# TODO: Link the state back to the widget, not just the other way around. # TODO: Link the state back to the widget, not just the other way around.
air_exch.observe(air_exch_change, names=['value']) air_exch.observe(air_exch_change, names=['value'])
return air_exch return widgets.HBox([air_exch, widgets.Label('h⁻¹')])
def _build_mechanical(self, node): def _build_mechanical(self, node):
mechanical_widgets = { mechanical_widgets = {
'Mechanical': self._build_q_air_mech(node._states['Mechanical']), 'HVACMechanical': self._build_q_air_mech(node._states['HVACMechanical']),
'Air changes per hour': self._build_ach(node._states['Air changes per hour']), 'AirChange': self._build_ach(node._states['AirChange']),
} }
for name, widget in mechanical_widgets.items(): for name, widget in mechanical_widgets.items():
widget.layout.visible = False widget.layout.visible = False
mechanival_w = widgets.ToggleButtons( mechanival_w = widgets.RadioButtons(
options=mechanical_widgets.keys(), options=list(zip(['Air supply flow rate (m³/h)', 'Air changes per hour (h⁻¹)'], mechanical_widgets.keys())),
button_style='info', # button_style='info',
) )
def toggle_mechanical(value): def toggle_mechanical(value):
@ -467,13 +466,13 @@ class ModelWidgets(View):
) -> widgets.Widget: ) -> widgets.Widget:
ventilation_widgets = { ventilation_widgets = {
'Natural': self._build_window(node._states['Natural']).build(), 'Natural': self._build_window(node._states['Natural']).build(),
'Mechanical': self._build_mechanical(node), 'HVACMechanical': self._build_mechanical(node),
} }
for name, widget in ventilation_widgets.items(): for name, widget in ventilation_widgets.items():
widget.layout.visible = False widget.layout.visible = False
ventilation_w = widgets.Dropdown( ventilation_w = widgets.Dropdown(
options=['Natural', 'Mechanical', 'No ventilation'], options=[('Natural', 'Natural'), ('Mechanical', 'HVACMechanical'), ('No ventilation', 'No ventilation')],
button_style='info', button_style='info',
style={'button_width':'100px'} style={'button_width':'100px'}
# tooltips=[], # tooltips=[],
@ -571,18 +570,18 @@ class CARAStateBuilder(state.StateBuilder):
s: state.DataclassStateNamed = state.DataclassStateNamed( s: state.DataclassStateNamed = state.DataclassStateNamed(
states={ states={
'Natural': self.build_generic(models.WindowOpening), 'Natural': self.build_generic(models.WindowOpening),
'Mechanical': self.build_generic(models.HVACMechanical), 'HVACMechanical': self.build_generic(models.HVACMechanical),
'Air changes per hour': self.build_generic(models.AirChange), 'AirChange': self.build_generic(models.AirChange),
'No ventilation': self.build_generic(models.AirChange), 'No ventilation': self.build_generic(models.AirChange),
}, },
state_builder=self, state_builder=self,
) )
# Initialise the HVAC state # Initialise the HVAC state
s._states['Mechanical'].dcs_update_from( s._states['HVACMechanical'].dcs_update_from(
models.HVACMechanical(models.PeriodicInterval(period=24*60, duration=24*60), 500.) models.HVACMechanical(models.PeriodicInterval(period=24*60, duration=24*60), 500.)
) )
# Initialise the HVAC state # Initialise the AirChange state
s._states['Air changes per hour'].dcs_update_from( s._states['AirChange'].dcs_update_from(
models.AirChange(models.PeriodicInterval(period=24*60, duration=24*60), 10.) models.AirChange(models.PeriodicInterval(period=24*60, duration=24*60), 10.)
) )
# Initialise the No ventilation state # Initialise the No ventilation state

View file

@ -1,18 +1,5 @@
{ {
"cells": [ "cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- <div style=\"text-align: center;\" align=\"center\">\n",
"<img src=\"../files/static/images/cara_logo_text_cern.png\" align=\"center\" style=\"text-align: center; height: 12em;\" /></div>\n",
"<p style=\"color: blue; font-weight: bold; font-size: x-large; text-align: center;\" align=\"center\">\n",
"Airborne Transmission of SARS-CoV-2\n",
"</p>\n",
"<p style=\"text-align: center;\">\n",
"Please see the <a href=\"https://cara.web.cern.ch/\">CARA homepage</a> for details on the methodology, assumptions and limitations of CARA.</p> -->"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB