Skip to content

Commit dc1c64a

Browse files
committed
style(lint): linting notebooks
1 parent 10b022d commit dc1c64a

File tree

2 files changed

+62
-27
lines changed

2 files changed

+62
-27
lines changed

notebooks/analysis.ipynb

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,9 +3850,8 @@
38503850
"outputs": [],
38513851
"source": [
38523852
"def make_delay_table(\n",
3853-
" scenario, scenario_name, base=base_overall, base_name=\"current\",\n",
3854-
" asu_beds=list(range(9,15)), rehab_beds=list(range(10,17))\n",
3855-
" ):\n",
3853+
" scenario, scenario_name, base, base_name, asu_beds, rehab_beds\n",
3854+
"):\n",
38563855
" \"\"\"\n",
38573856
" Create table with the probability of delay and 1 in n patients delayed,\n",
38583857
" for the base case and a provided scenario.\n",
@@ -3884,17 +3883,17 @@
38843883
" tab_segment = []\n",
38853884
"\n",
38863885
" # Loop over base case and scenario...\n",
3887-
" for scenario_name, df in {base_name: base[unit_name],\n",
3888-
" scenario_name: scenario[unit_name]}.items():\n",
3886+
" for name, df in {base_name: base[unit_name],\n",
3887+
" scenario_name: scenario[unit_name]}.items():\n",
38893888
"\n",
38903889
" # Extract results for specified beds\n",
38913890
" df = df[df[\"beds\"].isin(unit_beds)][\n",
38923891
" [\"beds\", \"prob_delay\", \"1_in_n_delay\"]]\n",
38933892
"\n",
38943893
" # Rename column to be specific to scenario\n",
38953894
" df = df.rename(columns={\n",
3896-
" \"prob_delay\": f\"prob_delay_{scenario_name}\",\n",
3897-
" \"1_in_n_delay\": f\"1_in_n_delay_{scenario_name}\"})\n",
3895+
" \"prob_delay\": f\"prob_delay_{name}\",\n",
3896+
" \"1_in_n_delay\": f\"1_in_n_delay_{name}\"})\n",
38983897
"\n",
38993898
" # Save dataframe to list\n",
39003899
" tab_segment.append(df)\n",
@@ -4100,14 +4099,16 @@
41004099
"12 37.0 "
41014100
]
41024101
},
4103-
"execution_count": 11,
41044102
"metadata": {},
4105-
"output_type": "execute_result"
4103+
"output_type": "display_data"
41064104
}
41074105
],
41084106
"source": [
4109-
"full_tab2 = make_delay_table(scenario=s1_overall, scenario_name=\"5%\")\n",
4110-
"full_tab2"
4107+
"full_tab2 = make_delay_table(\n",
4108+
" scenario=s1_overall, scenario_name=\"5%\", base=base_overall,\n",
4109+
" base_name=\"current\", asu_beds=list(range(9,15)),\n",
4110+
" rehab_beds=list(range(10,17)))\n",
4111+
"display(full_tab2)"
41114112
]
41124113
},
41134114
{
@@ -4546,6 +4547,8 @@
45464547
"# Make table\n",
45474548
"sup_tab1 = make_delay_table(scenario=s4_overall,\n",
45484549
" scenario_name=\"no_complex_neuro\",\n",
4550+
" base=base_overall,\n",
4551+
" base_name=\"current\",\n",
45494552
" asu_beds=list(range(10,16)),\n",
45504553
" rehab_beds=list(range(12,17)))\n",
45514554
"\n",
@@ -4993,9 +4996,8 @@
49934996
"37 40 2 0.000007 1.000000 0.000007 136875.0"
49944997
]
49954998
},
4996-
"execution_count": 16,
49974999
"metadata": {},
4998-
"output_type": "execute_result"
5000+
"output_type": "display_data"
49995001
}
50005002
],
50015003
"source": [
@@ -5007,7 +5009,7 @@
50075009
"\n",
50085010
"# Hijack the get_occupancy_freq() method from runner to calculate stats\n",
50095011
"pooled_results = base_runner.get_occupancy_freq(combined_audit, unit=\"pooled\")\n",
5010-
"pooled_results"
5012+
"display(pooled_results)"
50115013
]
50125014
},
50135015
{
@@ -5075,8 +5077,27 @@
50755077
"outputs": [],
50765078
"source": [
50775079
"class PooledDelay:\n",
5080+
" \"\"\"\n",
5081+
" Class to calculate probability of delays in scenarios with partial pooling\n",
5082+
" of acute and rehab beds.\n",
5083+
"\n",
5084+
" Attributes\n",
5085+
" ----------\n",
5086+
" asu : pd.Series\n",
5087+
" Frequency distribution of ASU bed occupancies.\n",
5088+
" rehab : pd.Series\n",
5089+
" Frequency distribution of rehab bed occupancies.\n",
5090+
" asu_beds : int or float\n",
5091+
" Number of dedicated ASU beds (excluding pooled beds).\n",
5092+
" rehab_beds : int or float\n",
5093+
" Number of dedicated rehab beds (excluding pooled beds).\n",
5094+
" pooled_beds : int or float\n",
5095+
" Number of beds that can be used by either unit.\n",
5096+
" \"\"\"\n",
50785097
" def __init__(self, base_results):\n",
50795098
" \"\"\"\n",
5099+
" Initialise the PooledDelay object with base simulation results.\n",
5100+
"\n",
50805101
" Parameters\n",
50815102
" ----------\n",
50825103
" base_results: dict\n",
@@ -5103,8 +5124,6 @@
51035124
" occ_freq : pd.Series\n",
51045125
" Frequencies of each number of beds, with the index representing the\n",
51055126
" occupancy.\n",
5106-
" min_occ : int\n",
5107-
" The minimum number of beds for which we want to check probability.\n",
51085127
" threshold : int\n",
51095128
" The threshold number of beds for comparison.\n",
51105129
" comparison : str\n",
@@ -5114,7 +5133,8 @@
51145133
" Returns\n",
51155134
" -------\n",
51165135
" float\n",
5117-
" The probability of an occupancy greater than or equal to min_occ.\n",
5136+
" Probability that the occupancy meets the specified comparison\n",
5137+
" condition.\n",
51185138
" \"\"\"\n",
51195139
" # Calculate total frequency\n",
51205140
" total_freq = occ_freq.sum()\n",
@@ -5129,6 +5149,8 @@
51295149
" elif comparison == \"lt\":\n",
51305150
" # Less than\n",
51315151
" filtered_freq = occ_freq[occ_freq.index < threshold].sum()\n",
5152+
" else:\n",
5153+
" raise ValueError(f\"Comparison '{comparison}' not valid.\")\n",
51325154
"\n",
51335155
" # Calculate and return the probability\n",
51345156
" return filtered_freq / total_freq\n",
@@ -5141,6 +5163,11 @@
51415163
" ----------\n",
51425164
" unit: str\n",
51435165
" Name of unit to investigate (\"asu\", \"rehab\").\n",
5166+
"\n",
5167+
" Returns\n",
5168+
" -------\n",
5169+
" float\n",
5170+
" Probability that only the specified unit has delays.\n",
51445171
" \"\"\"\n",
51455172
" # Determine name of other unit, depending on which you are focussing on\n",
51465173
" other_unit = \"rehab\" if unit == \"asu\" else \"asu\"\n",
@@ -5262,6 +5289,13 @@
52625289
" Number of dedicated rehabilitation beds (excluding pooled beds).\n",
52635290
" pooled_beds: int\n",
52645291
" Number of beds that can be used by either unit.\n",
5292+
"\n",
5293+
" Returns\n",
5294+
" -------\n",
5295+
" pool_results: dict\n",
5296+
" Dictionary containing number of dedicated and pooled beds,\n",
5297+
" probability of delay for each unit, and 1 in n patients delayed\n",
5298+
" for each unit.\n",
52655299
" \"\"\"\n",
52665300
" # Get counts of dedicated and pooled beds\n",
52675301
" self.asu_beds = asu_beds\n",

notebooks/parameters_csv.ipynb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16+
"# pylint: disable=missing-module-docstring\n",
17+
"from IPython.display import display\n",
1618
"import pandas as pd\n",
1719
"\n",
1820
"from simulation.parameters import (\n",
@@ -126,28 +128,27 @@
126128
{
127129
"data": {
128130
"text/plain": [
129-
"{'asu_arrivals': <simulation.parameters.ASUArrivals at 0x74dbb0272850>,\n",
130-
" 'rehab_arrivals': <simulation.parameters.RehabArrivals at 0x74dbb0272990>,\n",
131-
" 'asu_los': <simulation.parameters.ASULOS at 0x74dae09ca710>,\n",
132-
" 'rehab_los': <simulation.parameters.RehabLOS at 0x74dae08f0f50>,\n",
133-
" 'asu_routing': <simulation.parameters.ASURouting at 0x74dae08f1090>,\n",
134-
" 'rehab_routing': <simulation.parameters.RehabRouting at 0x74dae085c2d0>,\n",
131+
"{'asu_arrivals': <simulation.parameters.ASUArrivals at 0x7435cc4a6850>,\n",
132+
" 'rehab_arrivals': <simulation.parameters.RehabArrivals at 0x7435cc4a6990>,\n",
133+
" 'asu_los': <simulation.parameters.ASULOS at 0x7434fc38a710>,\n",
134+
" 'rehab_los': <simulation.parameters.RehabLOS at 0x7434fc2c8f50>,\n",
135+
" 'asu_routing': <simulation.parameters.ASURouting at 0x7434fc2c9090>,\n",
136+
" 'rehab_routing': <simulation.parameters.RehabRouting at 0x7434fc2382d0>,\n",
135137
" 'warm_up_period': 1095,\n",
136138
" 'data_collection_period': 1825,\n",
137139
" 'number_of_runs': 150,\n",
138140
" 'audit_interval': 1,\n",
139141
" 'cores': 1,\n",
140-
" 'logger': <simulation.logging.SimLogger at 0x74dae06c4980>,\n",
142+
" 'logger': <simulation.logging.SimLogger at 0x7434fc090ad0>,\n",
141143
" '_initialised': True}"
142144
]
143145
},
144-
"execution_count": 3,
145146
"metadata": {},
146-
"output_type": "execute_result"
147+
"output_type": "display_data"
147148
}
148149
],
149150
"source": [
150-
"setup_param_from_csv(csv_path=\"../inputs/parameters.csv\").__dict__"
151+
"display(setup_param_from_csv(csv_path=\"../inputs/parameters.csv\").__dict__)"
151152
]
152153
}
153154
],

0 commit comments

Comments
 (0)