Merge branch 'feature/html-form-calculator' into 'master'
Remove the wireframe notebook now that we use a vanilla HTML form instead. Closes #27 See merge request cara/cara!82
This commit is contained in:
commit
c303c9d349
1 changed files with 0 additions and 370 deletions
|
|
@ -1,370 +0,0 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 182,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import ipywidgets as w"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 183,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"name_text = w.Text(placeholder=\"E.g. Workshop without masks\", description=\"Simulation name:\",\n",
|
||||
" style={'description_width': 'auto'}, layout=w.Layout(width='auto'))\n",
|
||||
"room_number_text = w.Text(placeholder=\"E.g. 17/R-033\", description=\"Room number:\",\n",
|
||||
" style={'description_width': 'auto'}, layout=w.Layout(width='auto'))\n",
|
||||
"intro_box = w.VBox(children=(w.HTML(value='<font size=\"+2\"><b>CARA</b> Covid Calculator</font>'),\n",
|
||||
" name_text,\n",
|
||||
" room_number_text),\n",
|
||||
" layout=w.Layout(padding='0px 0px 50px 0px'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 184,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"volume_text = w.Text(placeholder=\"Room volume (m³)\", description=\"Room volume\", layout=w.Layout(width='auto'))\n",
|
||||
"area_text = w.Text(placeholder=\"Room floor area (m²)\", description=\"Floor area\", layout=w.Layout(width='auto'))\n",
|
||||
"height_text = w.Text(placeholder=\"Room ceiling height (m²)\", description=\"Ceiling height\", layout=w.Layout(width='auto'))\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": 185,
|
||||
"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'}, layout=w.Layout(width='auto'))\n",
|
||||
"asfr_text = w.Text(description=\"Air supply flow rate\", style={'description_width': 'auto'}, layout=w.Layout(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', width='auto')\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"number_of_windows_text = w.Text(description='Number of windows:', style={'description_width': 'auto'},\n",
|
||||
" layout=w.Layout(width='auto'))\n",
|
||||
"height_of_window_text = w.Text(description='Height of window:', placeholder='meters',\n",
|
||||
" style={'description_width': 'auto'}, layout=w.Layout(width='auto'))\n",
|
||||
"width_of_window_text = w.Text(description='Width of window:', placeholder='meters', style={'description_width': 'auto'},\n",
|
||||
" layout=w.Layout(width='auto'))\n",
|
||||
"opening_distance_text = w.Text(description='Opening distance:', placeholder='centimeters', style={'description_width': 'auto'},\n",
|
||||
" layout=w.Layout(width='auto'))\n",
|
||||
"window_open_buttons = w.RadioButtons(options=('Always', '15 min / 2h'), layout=w.Layout(width='auto'))\n",
|
||||
"\n",
|
||||
"nat_vent_box = w.VBox(\n",
|
||||
" children=(\n",
|
||||
" number_of_windows_text,\n",
|
||||
" opening_distance_text,\n",
|
||||
" width_of_window_text,\n",
|
||||
" opening_distance_text,\n",
|
||||
" w.HBox(children=(\n",
|
||||
" w.Label('Windows open', layout=w.Layout(width='auto')),\n",
|
||||
" window_open_buttons\n",
|
||||
" ))\n",
|
||||
" ),\n",
|
||||
" layout=w.Layout(display='none', width='auto'),\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 = 'contents'\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 = 'contents'\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)\n",
|
||||
"left_column = w.VBox(children=(intro_box, room_dimensions_box, ventilation_box),\n",
|
||||
" layout=w.Layout(width='25%', padding=\"0px 20px 0px 0px\"))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 186,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
},
|
||||
"scrolled": false
|
||||
},
|
||||
"outputs": [],
|
||||
"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",
|
||||
" layout=w.Layout(width='auto'))\n",
|
||||
"infected_people_text = w.Text(description=\"Number of infected people:\", style={'description_width': 'auto'},\n",
|
||||
" layout=w.Layout(width='auto'))\n",
|
||||
"activity_dropdown = w.Dropdown(description=\"Activity type:\", options=[\"Training\", \"Workshop\", \"Office\"], value=None,\n",
|
||||
" layout=w.Layout(width='auto'))\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), layout=w.Layout(width='auto'))\n",
|
||||
"\n",
|
||||
"event_intro_box = w.VBox(children=(event_data_label,\n",
|
||||
" attendees_label,\n",
|
||||
" total_people_text,\n",
|
||||
" infected_people_text,\n",
|
||||
" activity_dropdown,\n",
|
||||
" event_time_box),\n",
|
||||
" layout=w.Layout(padding=\"50px 0px 20px 0px\"))\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), layout=w.Layout(width='auto'), style={'description_width': 'auto'})\n",
|
||||
"month_dropdown = w.Dropdown(options=months, value=None, description=\"Month:\", layout=w.Layout(width='auto'), style={'description_width': 'auto'})\n",
|
||||
"day_dropdown = w.Dropdown(options=[i for i in range(1, 32)], value=None, description=\"Day:\", layout=w.Layout(width='auto'))\n",
|
||||
"date_selector = w.HBox(children=(month_dropdown, day_dropdown), layout=w.Layout(display='none', width='auto'))\n",
|
||||
"\n",
|
||||
"months_bar = w.HBox(children=[w.ToggleButton(value=False, description=month[0].upper()) 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",
|
||||
" layout=w.Layout(padding=\"0px 0px 30px 0px\"))\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_hour, lunch_finish_minute))))\n",
|
||||
"lunch_time_box = w.HBox(children=(lunch_start_box, lunch_finish_box), layout=w.Layout(width='auto'))\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",
|
||||
"lunch_break_box = w.VBox(children=(lunch_button, lunch_time_box), layout=w.Layout(padding='0px 0px 20px 0px'))\n",
|
||||
"\n",
|
||||
"coffee_button = w.ToggleButton(value=False, description=\"Coffee breaks\")\n",
|
||||
"coffee_breaks_text = w.Text(description=\"Number of breaks:\", disabled=True, style={'description_width': 'auto'},\n",
|
||||
" layout=w.Layout(width='auto'))\n",
|
||||
"coffee_duration = w.Dropdown(description=\"Duration:\", options=[\"MM\"] + [str(i) for i in range(1, 31)], value=\"MM\",\n",
|
||||
" disabled=True, style={'description_width': 'auto'}, layout=w.Layout(width='auto'))\n",
|
||||
"regular_breaks_label = w.Label(\"Regular breaks are spread evenly throughout the day\")\n",
|
||||
"coffee_break_box = w.VBox(children=(coffee_button, coffee_breaks_text, coffee_duration, regular_breaks_label))\n",
|
||||
"def handle_coffee_button(_):\n",
|
||||
" coffee_duration.disabled = not coffee_button.value\n",
|
||||
" coffee_breaks_text.disabled = not coffee_button.value\n",
|
||||
"\n",
|
||||
"coffee_button.observe(handle_coffee_button)\n",
|
||||
"break_box = w.VBox(children=(lunch_break_box, coffee_break_box))\n",
|
||||
"\n",
|
||||
"middle_column = w.VBox(children=(event_intro_box, date_box, break_box),\n",
|
||||
" layout=w.Layout(width='40%', padding='0px 20px 0px 0px'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 187,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"mask_label = w.Label(\"Mask wearing:\")\n",
|
||||
"mask_buttons = w.ToggleButtons(options=[\"Continuous\", \"Removed when seated >2m\"])\n",
|
||||
"mask_box = w.VBox(children=(mask_label, mask_buttons), layout=w.Layout(padding='50px 0px 30px 0px'))\n",
|
||||
"\n",
|
||||
"info_box = w.HTML(value='<style>p{font-size:0.875em; line-height:1.2}</style>'\n",
|
||||
" '<p>This tool estimates the risk of COVID-19 spread. It is based on current scientific data and '\n",
|
||||
" 'can be used to provide an illustration for different real world scenarios.</p><p><br></p>'\n",
|
||||
" '<p style=\"text-align: center;\"><strong>How to use this tool:</strong></p>'\n",
|
||||
" '<p style=\"text-align: center;\"><strong>Room data</strong></p>'\n",
|
||||
" '<p>Enter the data about the area you wish to study. You can find these in GIS, or by measuring '\n",
|
||||
" 'them yourself.</p><p>For mechanical ventilation, you should check with a specialist for the '\n",
|
||||
" 'air flow or air change rate.</p><p><br></p>'\n",
|
||||
" '<p style=\"text-align: center;\"><strong>Event data</strong></p>'\n",
|
||||
" '<p>Enter the total number of people and how many you assume are infected.</p><p><br></p>'\n",
|
||||
" '<p style=\"text-align: center;\"><strong>Activity types:</strong></p>'\n",
|
||||
" '<p>Office = typical scenario all persons seated, talking quietly.</p>'\n",
|
||||
" '<p>Workshop = assembly workshop environment, all persons doing light exercise, talking.</p>'\n",
|
||||
" '<p>Training = one person standing, talking, all others seated, breathing normally.</p>'\n",
|
||||
" '<p>Seminar = As training, but all participants take turns in standing and talking.</p>'\n",
|
||||
" '<p>You should specify if the event is a one off (give date) or recurrent use of the same space '\n",
|
||||
" 'for the same activity, in which case tick the months when the activity takes place.</p>'\n",
|
||||
" '<p>Specify if a lunch break should be included, and when it starts/stops.</p>'\n",
|
||||
" '<p>If you will take coffee breaks, they are spread out evenly throughout the day, '\n",
|
||||
" 'in addition to lunch.</p><p>Mask wearing: Specify if they are worn all the time, '\n",
|
||||
" 'or only when less than 2 meters apart.</p>',\n",
|
||||
" layout=w.Layout(padding='0px 0px 30px 0px'))\n",
|
||||
"\n",
|
||||
"report_button = w.Button(description=\"Generate report\")\n",
|
||||
"\n",
|
||||
"right_column = w.VBox(children=(mask_box, info_box, report_button), layout=w.Layout(width='35%'))\n",
|
||||
"\n",
|
||||
"components = {'name_text', 'room_number_text', 'volume_text', 'area_text', 'height_text', 'mechanical_button',\n",
|
||||
" 'acph_text', 'asfr_text', 'natural_button', 'number_of_windows_text', 'height_of_window_text',\n",
|
||||
" 'width_of_window_text', 'opening_distance_text', 'opening_distance_text', 'window_open_buttons',\n",
|
||||
" 'total_people_text', 'infected_people_text', 'activity_dropdown', 'start_hour', 'start_minute',\n",
|
||||
" 'finish_hour', 'finish_minute', 'single_button', 'recurrent_button', 'month_dropdown', 'day_dropdown',\n",
|
||||
" 'lunch_button', 'lunch_start_hour', 'lunch_start_minute', 'lunch_finish_hour', 'lunch_finish_minute',\n",
|
||||
" 'coffee_button', 'coffee_breaks_text', 'coffee_duration', 'mask_buttons'}\n",
|
||||
"components.update(set(months))\n",
|
||||
"\n",
|
||||
"def get_value(component_name: str):\n",
|
||||
" assert component_name in components, f\"{component_name} is not the name of any UI-element with a value-attribute. \" \\\n",
|
||||
" \"Valid names are:\\n\" + '\\n'.join(sorted(components))\n",
|
||||
" if component_name in months:\n",
|
||||
" return months_bar.children[months.index(component_name)].value\n",
|
||||
"\n",
|
||||
" return globals()[component_name].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 188,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "ed8a32168798491b94b149a42af469a2",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"HBox(children=(VBox(children=(VBox(children=(HTML(value='<font size=\"+2\"><b>CARA</b> Covid Calculator</font>')…"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"w.HBox(children=(left_column, middle_column, right_column))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
||||
Loading…
Reference in a new issue