cara/app/covid-calculator.ipynb

254 lines
No EOL
11 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as w"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"intro_box = w.VBox(children=(w.HTML(value='<font size=\"+2\"><b>CARA</b> Covid Calculator</font>'),\n",
" w.Text(placeholder=\"E.g. Workshop without masks\", description=\"Simulation name:\",\n",
" style={'description_width': '35%'}),\n",
" w.Text(placeholder=\"E.g. 17/R-033\", description=\"Room number:\",\n",
" style={'description_width': '35%'})),\n",
" layout=w.Layout(padding='0px 0px 50px 0px'))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"volume_text = w.Text(placeholder=\"Room volume (m³)\", description=\"Room volume\")\n",
"area_text = w.Text(placeholder=\"Room floor area (m²)\", description=\"Floor area\")\n",
"height_text = w.Text(placeholder=\"Room ceiling height (m²)\", description=\"Ceiling height\")\n",
"\n",
"room_dimensions_box = w.VBox(children=(volume_text, w.Label(value=\"------- OR -------\"),area_text, height_text),\n",
" layout=w.Layout(padding='0px 0px 50px 0px'))\n",
"\n",
"def manage_room_text_fields(_):\n",
" volume_text.disabled = bool(area_text.value) or bool(height_text.value)\n",
" area_text.disabled = bool(volume_text.value)\n",
" height_text.disabled = bool(volume_text.value)\n",
"\n",
"for text in [volume_text, area_text, height_text]:\n",
" text.observe(manage_room_text_fields)\n",
" text.style.description_width = \"auto\"\n",
"\n",
"volume_text.observe(manage_room_text_fields)\n",
"area_text.observe(manage_room_text_fields)\n",
"height_text.observe(manage_room_text_fields)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"ventilation_label = w.Label(\"Ventilation type:\")\n",
"mechanical_button = w.ToggleButton(value=False, description='Mechanical', layout={'width': 'auto'})\n",
"natural_button = w.ToggleButton(value=False, description='Natural', layout={'width': 'auto'})\n",
"\n",
"acph_text = w.Text(description=\"Air changes per hour\", style={'description_width': 'auto'})\n",
"asfr_text = w.Text(description=\"Air supply flow rate\", style={'description_width': 'auto'})\n",
"\n",
"w.jsdlink((acph_text, 'value'), (asfr_text, 'disabled'))\n",
"w.jsdlink((asfr_text, 'value'), (acph_text, 'disabled'))\n",
"\n",
"mech_vent_box = w.VBox(\n",
" children=(acph_text, w.Label(value=\"------- OR -------\"), asfr_text),\n",
" layout=w.Layout(display='none')\n",
")\n",
"\n",
"nat_vent_box = w.VBox(\n",
" children=(\n",
" w.Text(description='Number of windows:', style={'description_width': 'auto'}),\n",
" w.Text(description='Height of window:', placeholder='meters', style={'description_width': 'auto'}),\n",
" w.Text(description='Width of window:', placeholder='meters', style={'description_width': 'auto'}),\n",
" w.Text(description='Opening distance:', placeholder='centimeters', style={'description_width': 'auto'}),\n",
" w.HBox(children=(\n",
" w.Label('Windows open'),\n",
" w.RadioButtons(options=('Always', '15 min / 2h'))\n",
" ))\n",
" ),\n",
" layout=w.Layout(display='none'),\n",
")\n",
"\n",
"\n",
"\n",
"tab_bar = w.HBox(children=(mechanical_button, natural_button))\n",
"ventilation_type_menu = w.VBox(children=(ventilation_label, tab_bar), layout=w.Layout(padding='0px 0px 20px 0px'))\n",
"ventilation_box = w.VBox(children=(ventilation_type_menu, mech_vent_box, nat_vent_box),\n",
" layout=w.Layout(padding='0px 0px 50px 0px'))\n",
"\n",
"def handle_natural_toggle(_):\n",
" if natural_button.value:\n",
" mechanical_button.value = False\n",
" ventilation_box.children[2].layout.display = 'block'\n",
" else:\n",
" ventilation_box.children[2].layout.display = 'none'\n",
"\n",
"def handle_mechanical_toggle(_):\n",
" if mechanical_button.value:\n",
" natural_button.value = False\n",
" ventilation_box.children[1].layout.display = 'block'\n",
" else:\n",
" ventilation_box.children[1].layout.display = 'none'\n",
"\n",
"natural_button.observe(handle_natural_toggle)\n",
"mechanical_button.observe(handle_mechanical_toggle)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": "VBox(children=(ToggleButton(value=False, description='Lunch break'), HBox(children=(VBox(children=(Label(value…",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "5998e5c52baa48b4af05c6c65acef726"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"event_data_label = w.Label(\"Event data:\")\n",
"attendees_label = w.Label(\"Attendees:\")\n",
"total_people_text = w.Text(description=\"Total number of people:\", style={'description_width': 'auto'})\n",
"infected_people_text = w.Text(description=\"Number of infected people:\", style={'description_width': 'auto'})\n",
"activity_dropdown = w.Dropdown(description=\"Activity type:\", options=[\"Training\", \"Workshop\", \"Office\"], value=None)\n",
"start_hour = w.Dropdown(options=[\"HH\"] + [(\"0\" + str(i)) if len(str(i)) == 1 else str(i) for i in range(24)], value=\"HH\")\n",
"start_minute = w.Dropdown(options=[\"MM\"] + [(\"0\" + str(i)) if len(str(i)) == 1 else str(i) for i in range(60)], value=\"MM\")\n",
"finish_hour = w.Dropdown(options=[\"HH\"] + [(\"0\" + str(i)) if len(str(i)) == 1 else str(i) for i in range(24)], value=\"HH\")\n",
"finish_minute = w.Dropdown(options=[\"MM\"] + [(\"0\" + str(i)) if len(str(i)) == 1 else str(i) for i in range(60)], value=\"MM\")\n",
"start_box = w.VBox(children=(w.Label(\"Start:\"),\n",
" w.HBox(children=(start_hour, start_minute))),\n",
" layout=w.Layout(padding=\"0px 20px 0px 0px\"))\n",
"finish_box = w.VBox(children=(w.Label(\"Finish:\"),\n",
" w.HBox(children=(finish_hour, finish_minute))))\n",
"event_time_box = w.HBox(children=(start_box, finish_box))\n",
"\n",
"event_intro_box = w.VBox(children=(\n",
" event_data_label,\n",
" attendees_label,\n",
" total_people_text,\n",
" infected_people_text,\n",
" activity_dropdown,\n",
" event_time_box\n",
"))\n",
"\n",
"months = (\"January\", \"February\", \"March\", \"April\", \"May\", \"June\",\n",
" \"July\", \"August\", \"September\", \"October\", \"November\", \"December\")\n",
"\n",
"single_button = w.ToggleButton(value=False, description='Single event', layout={'width': 'auto'})\n",
"recurrent_button = w.ToggleButton(value=False, description='Recurrent usage', layout={'width': 'auto'})\n",
"single_recurrent_selection_bar = w.HBox(children=(single_button, recurrent_button))\n",
"month_dropdown = w.Dropdown(options=months, value=None, description=\"Month:\", layout=w.Layout(padding=\"0px 20px 0px 0px\"))\n",
"day_dropdown = w.Dropdown(options=[i for i in range(1, 32)], value=None, description=\"Day:\")\n",
"date_selector = w.HBox(children=(month_dropdown, day_dropdown), layout=w.Layout(display='none'))\n",
"months_bar = w.HBox(children=[w.ToggleButton(value=False, description=month[0]) for month in months],\n",
" layout = w.Layout(display='none'))\n",
"\n",
"def handle_single_click(_):\n",
" if single_button.value:\n",
" date_selector.layout.display = 'contents'\n",
" recurrent_button.value = False\n",
" else:\n",
" date_selector.layout.display = 'none'\n",
"\n",
"def handle_recurrent_click(_):\n",
" if recurrent_button.value:\n",
" months_bar.layout.display = 'contents'\n",
" single_button.value = False\n",
" else:\n",
" months_bar.layout.display = 'none'\n",
"\n",
"single_button.observe(handle_single_click)\n",
"recurrent_button.observe(handle_recurrent_click)\n",
"\n",
"date_box = w.VBox(children=(w.HBox(children=(single_button, recurrent_button)),\n",
" w.HBox(children=(date_selector, months_bar))))\n",
"\n",
"lunch_start_hour = w.Dropdown(options=[\"HH\"] + [(\"0\" + str(i)) if len(str(i)) == 1 else str(i) for i in range(24)],\n",
" value=\"HH\", disabled=True)\n",
"lunch_start_minute = w.Dropdown(options=[\"MM\"] + [(\"0\" + str(i)) if len(str(i)) == 1 else str(i) for i in range(60)],\n",
" value=\"MM\", disabled=True)\n",
"lunch_finish_hour = w.Dropdown(options=[\"HH\"] + [(\"0\" + str(i)) if len(str(i)) == 1 else str(i) for i in range(24)],\n",
" value=\"HH\", disabled=True)\n",
"lunch_finish_minute = w.Dropdown(options=[\"MM\"] + [(\"0\" + str(i)) if len(str(i)) == 1 else str(i) for i in range(60)],\n",
" value=\"MM\", disabled=True)\n",
"lunch_start_box = w.VBox(children=(w.Label(\"Start:\"),\n",
" w.HBox(children=(lunch_start_hour, lunch_start_minute))),\n",
" layout=w.Layout(padding=\"0px 20px 0px 0px\"))\n",
"lunch_finish_box = w.VBox(children=(w.Label(\"Finish:\"),\n",
" w.HBox(children=(lunch_finish_minute, lunch_finish_minute))))\n",
"lunch_time_box = w.HBox(children=(lunch_start_box, lunch_finish_box))\n",
"\n",
"lunch_button = w.ToggleButton(value=False, description=\"Lunch break\")\n",
"\n",
"def handle_lunch(_):\n",
" for dropdown in (lunch_start_hour, lunch_start_minute, lunch_finish_hour, lunch_finish_minute):\n",
" dropdown.disabled = not lunch_button.value\n",
"\n",
"lunch_button.observe(handle_lunch)\n",
"\n",
"break_box = w.VBox(children=(lunch_button, lunch_time_box))\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}