add function for getting value
This commit is contained in:
parent
afd6d4db58
commit
ab8c0702ef
1 changed files with 66 additions and 38 deletions
|
|
@ -2,7 +2,7 @@
|
|||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 56,
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 57,
|
||||
"execution_count": 26,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
|
|
@ -19,17 +19,19 @@
|
|||
},
|
||||
"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",
|
||||
" w.Text(placeholder=\"E.g. Workshop without masks\", description=\"Simulation name:\",\n",
|
||||
" style={'description_width': 'auto'}, layout=w.Layout(width='auto')),\n",
|
||||
" w.Text(placeholder=\"E.g. 17/R-033\", description=\"Room number:\",\n",
|
||||
" style={'description_width': 'auto'}, layout=w.Layout(width='auto'))),\n",
|
||||
" name_text,\n",
|
||||
" room_number_text),\n",
|
||||
" layout=w.Layout(padding='0px 0px 50px 0px'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 58,
|
||||
"execution_count": 27,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
|
|
@ -60,7 +62,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 59,
|
||||
"execution_count": 28,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
|
|
@ -83,18 +85,25 @@
|
|||
" 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",
|
||||
" w.Text(description='Number of windows:', style={'description_width': 'auto'}, layout=w.Layout(width='auto')),\n",
|
||||
" w.Text(description='Height of window:', placeholder='meters', style={'description_width': 'auto'},\n",
|
||||
" layout=w.Layout(width='auto')),\n",
|
||||
" w.Text(description='Width of window:', placeholder='meters', style={'description_width': 'auto'},\n",
|
||||
" layout=w.Layout(width='auto')),\n",
|
||||
" w.Text(description='Opening distance:', placeholder='centimeters', style={'description_width': 'auto'},\n",
|
||||
" layout=w.Layout(width='auto')),\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",
|
||||
" w.RadioButtons(options=('Always', '15 min / 2h'), layout=w.Layout(width='auto'))\n",
|
||||
" window_open_buttons\n",
|
||||
" ))\n",
|
||||
" ),\n",
|
||||
" layout=w.Layout(display='none', width='auto'),\n",
|
||||
|
|
@ -129,7 +138,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 60,
|
||||
"execution_count": 29,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
|
|
@ -165,8 +174,8 @@
|
|||
" 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",
|
||||
"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",
|
||||
|
|
@ -174,7 +183,8 @@
|
|||
"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",
|
||||
"\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",
|
||||
|
|
@ -243,25 +253,13 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 30,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "NameError",
|
||||
"evalue": "name 'w' is not defined",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
||||
"\u001B[0;31mNameError\u001B[0m Traceback (most recent call last)",
|
||||
"\u001B[0;32m<ipython-input-2-f8a4c8fcd133>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0mmask_label\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mw\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mLabel\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"Mask wearing:\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 2\u001B[0m \u001B[0mmask_buttons\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mw\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mToggleButtons\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0moptions\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m\"Continuous\"\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m\"Removed when seated >2m\"\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 3\u001B[0m \u001B[0mmask_box\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mw\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mVBox\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mchildren\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mmask_label\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mmask_buttons\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mlayout\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mw\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mLayout\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mpadding\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m'50px 0px 30px 0px'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 4\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 5\u001B[0m info_box = w.HTML(value='<style>p{font-size:0.875em; line-height:1.1}</style>'\n",
|
||||
"\u001B[0;31mNameError\u001B[0m: name 'w' is not defined"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"mask_label = w.Label(\"Mask wearing:\")\n",
|
||||
"mask_buttons = w.ToggleButtons(options=[\"Continuous\", \"Removed when seated >2m\"])\n",
|
||||
|
|
@ -292,20 +290,50 @@
|
|||
"\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%'))"
|
||||
"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": null,
|
||||
"execution_count": 31,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": "HBox(children=(VBox(children=(VBox(children=(HTML(value='<font size=\"+2\"><b>CARA</b> Covid Calculator</font>')…",
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"version_major": 2,
|
||||
"version_minor": 0,
|
||||
"model_id": "3bc5f376c4884148be482783a874120a"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"w.HBox(children=(left_column, middle_column, right_column))\n"
|
||||
"w.HBox(children=(left_column, middle_column, right_column))"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue