Skip to content

Commit 73ccf92

Browse files
authored
Merge pull request #37 from pythonhealthdatascience/dev
Dev
2 parents 08d20d3 + d4c0717 commit 73ccf92

22 files changed

+556
-427
lines changed

.github/workflows/lint.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ name: lint
55
on:
66
push:
77
branches: [main]
8-
pull_request:
98
workflow_dispatch:
109

1110
jobs:

docs/hsma_changes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Patient:
7373
self.time_with_nurse = np.nan
7474
```
7575

76-
This enables metrics like `count_unseen` and `mean_q_time_unseen`, which can show backlog in the system at the end of the simulation.
76+
This enables metrics like `count_nurse_unseen` and `mean_q_time_nurse_unseen`, which can show backlog in the system at the end of the simulation.
7777

7878
## Seeds
7979

notebooks/analysis.ipynb

Lines changed: 169 additions & 344 deletions
Large diffs are not rendered by default.

notebooks/choosing_cores.ipynb

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

notebooks/choosing_replications.ipynb

Lines changed: 9 additions & 9 deletions
Large diffs are not rendered by default.

notebooks/choosing_warmup.ipynb

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

notebooks/generate_exp_results.ipynb

Lines changed: 233 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"import time\n",
5757
"from IPython.display import display\n",
5858
"\n",
59-
"from simulation.model import Param, Runner\n",
59+
"from simulation.model import Param, Runner, run_scenarios\n",
6060
"from simulation.replications import confidence_interval_method"
6161
]
6262
},
@@ -156,7 +156,7 @@
156156
" <th>q_time_nurse</th>\n",
157157
" <th>time_with_nurse</th>\n",
158158
" <th>run</th>\n",
159-
" <th>q_time_unseen</th>\n",
159+
" <th>q_time_unseen_nurse</th>\n",
160160
" </tr>\n",
161161
" </thead>\n",
162162
" <tbody>\n",
@@ -278,18 +278,18 @@
278278
"1888 368 1988.648731 0.0 24.898160 4 \n",
279279
"1889 369 1993.658168 0.0 3.353385 4 \n",
280280
"\n",
281-
" q_time_unseen \n",
282-
"0 NaN \n",
283-
"1 NaN \n",
284-
"2 NaN \n",
285-
"3 NaN \n",
286-
"4 NaN \n",
287-
"... ... \n",
288-
"1885 NaN \n",
289-
"1886 NaN \n",
290-
"1887 NaN \n",
291-
"1888 NaN \n",
292-
"1889 NaN \n",
281+
" q_time_unseen_nurse \n",
282+
"0 NaN \n",
283+
"1 NaN \n",
284+
"2 NaN \n",
285+
"3 NaN \n",
286+
"4 NaN \n",
287+
"... ... \n",
288+
"1885 NaN \n",
289+
"1886 NaN \n",
290+
"1887 NaN \n",
291+
"1888 NaN \n",
292+
"1889 NaN \n",
293293
"\n",
294294
"[1890 rows x 6 columns]"
295295
]
@@ -339,8 +339,8 @@
339339
" <th>mean_nurse_utilisation</th>\n",
340340
" <th>mean_nurse_utilisation_tw</th>\n",
341341
" <th>mean_nurse_q_length</th>\n",
342-
" <th>count_unseen</th>\n",
343-
" <th>mean_q_time_unseen</th>\n",
342+
" <th>count_nurse_unseen</th>\n",
343+
" <th>mean_q_time_nurse_unseen</th>\n",
344344
" </tr>\n",
345345
" </thead>\n",
346346
" <tbody>\n",
@@ -428,12 +428,12 @@
428428
"3 0.639573 0.639573 0.544915 \n",
429429
"4 0.601042 0.601042 0.406760 \n",
430430
"\n",
431-
" count_unseen mean_q_time_unseen \n",
432-
"0 0 NaN \n",
433-
"1 0 NaN \n",
434-
"2 0 NaN \n",
435-
"3 0 NaN \n",
436-
"4 0 NaN "
431+
" count_nurse_unseen mean_q_time_nurse_unseen \n",
432+
"0 0 NaN \n",
433+
"1 0 NaN \n",
434+
"2 0 NaN \n",
435+
"3 0 NaN \n",
436+
"4 0 NaN "
437437
]
438438
},
439439
"metadata": {},
@@ -659,8 +659,8 @@
659659
" <th>mean_nurse_utilisation</th>\n",
660660
" <th>mean_nurse_utilisation_tw</th>\n",
661661
" <th>mean_nurse_q_length</th>\n",
662-
" <th>count_unseen</th>\n",
663-
" <th>mean_q_time_unseen</th>\n",
662+
" <th>count_nurse_unseen</th>\n",
663+
" <th>mean_q_time_nurse_unseen</th>\n",
664664
" </tr>\n",
665665
" </thead>\n",
666666
" <tbody>\n",
@@ -725,11 +725,11 @@
725725
"lower_95_ci 0.609435 0.609435 \n",
726726
"upper_95_ci 0.669667 0.669667 \n",
727727
"\n",
728-
" mean_nurse_q_length count_unseen mean_q_time_unseen \n",
729-
"mean 0.531240 0.0 NaN \n",
730-
"std_dev 0.195914 0.0 NaN \n",
731-
"lower_95_ci 0.287981 0.0 NaN \n",
732-
"upper_95_ci 0.774500 0.0 NaN "
728+
" mean_nurse_q_length count_nurse_unseen mean_q_time_nurse_unseen \n",
729+
"mean 0.531240 0.0 NaN \n",
730+
"std_dev 0.195914 0.0 NaN \n",
731+
"lower_95_ci 0.287981 0.0 NaN \n",
732+
"upper_95_ci 0.774500 0.0 NaN "
733733
]
734734
},
735735
"metadata": {},
@@ -743,6 +743,203 @@
743743
" os.path.join(TESTS, 'overall.csv'), index=True)"
744744
]
745745
},
746+
{
747+
"cell_type": "markdown",
748+
"metadata": {},
749+
"source": [
750+
"## Scenario analysis"
751+
]
752+
},
753+
{
754+
"cell_type": "code",
755+
"execution_count": 10,
756+
"metadata": {},
757+
"outputs": [
758+
{
759+
"name": "stdout",
760+
"output_type": "stream",
761+
"text": [
762+
"There are 4 scenarios. Running:\n",
763+
"{'patient_inter': 3, 'number_of_nurses': 6}\n",
764+
"{'patient_inter': 3, 'number_of_nurses': 7}\n",
765+
"{'patient_inter': 4, 'number_of_nurses': 6}\n",
766+
"{'patient_inter': 4, 'number_of_nurses': 7}\n"
767+
]
768+
},
769+
{
770+
"data": {
771+
"text/html": [
772+
"<div>\n",
773+
"<style scoped>\n",
774+
" .dataframe tbody tr th:only-of-type {\n",
775+
" vertical-align: middle;\n",
776+
" }\n",
777+
"\n",
778+
" .dataframe tbody tr th {\n",
779+
" vertical-align: top;\n",
780+
" }\n",
781+
"\n",
782+
" .dataframe thead th {\n",
783+
" text-align: right;\n",
784+
" }\n",
785+
"</style>\n",
786+
"<table border=\"1\" class=\"dataframe\">\n",
787+
" <thead>\n",
788+
" <tr style=\"text-align: right;\">\n",
789+
" <th></th>\n",
790+
" <th>run_number</th>\n",
791+
" <th>scenario</th>\n",
792+
" <th>arrivals</th>\n",
793+
" <th>mean_q_time_nurse</th>\n",
794+
" <th>mean_time_with_nurse</th>\n",
795+
" <th>mean_nurse_utilisation</th>\n",
796+
" <th>mean_nurse_utilisation_tw</th>\n",
797+
" <th>mean_nurse_q_length</th>\n",
798+
" <th>count_nurse_unseen</th>\n",
799+
" <th>mean_q_time_nurse_unseen</th>\n",
800+
" <th>patient_inter</th>\n",
801+
" <th>number_of_nurses</th>\n",
802+
" </tr>\n",
803+
" </thead>\n",
804+
" <tbody>\n",
805+
" <tr>\n",
806+
" <th>0</th>\n",
807+
" <td>0</td>\n",
808+
" <td>0</td>\n",
809+
" <td>2004</td>\n",
810+
" <td>0.486680</td>\n",
811+
" <td>9.925934</td>\n",
812+
" <td>0.553955</td>\n",
813+
" <td>0.553955</td>\n",
814+
" <td>0.162551</td>\n",
815+
" <td>0</td>\n",
816+
" <td>NaN</td>\n",
817+
" <td>3</td>\n",
818+
" <td>6</td>\n",
819+
" </tr>\n",
820+
" <tr>\n",
821+
" <th>1</th>\n",
822+
" <td>1</td>\n",
823+
" <td>0</td>\n",
824+
" <td>1993</td>\n",
825+
" <td>0.746175</td>\n",
826+
" <td>10.377197</td>\n",
827+
" <td>0.573874</td>\n",
828+
" <td>0.573874</td>\n",
829+
" <td>0.247854</td>\n",
830+
" <td>0</td>\n",
831+
" <td>NaN</td>\n",
832+
" <td>3</td>\n",
833+
" <td>6</td>\n",
834+
" </tr>\n",
835+
" <tr>\n",
836+
" <th>2</th>\n",
837+
" <td>2</td>\n",
838+
" <td>0</td>\n",
839+
" <td>2017</td>\n",
840+
" <td>0.386324</td>\n",
841+
" <td>9.856724</td>\n",
842+
" <td>0.553419</td>\n",
843+
" <td>0.553419</td>\n",
844+
" <td>0.129869</td>\n",
845+
" <td>0</td>\n",
846+
" <td>NaN</td>\n",
847+
" <td>3</td>\n",
848+
" <td>6</td>\n",
849+
" </tr>\n",
850+
" <tr>\n",
851+
" <th>0</th>\n",
852+
" <td>0</td>\n",
853+
" <td>1</td>\n",
854+
" <td>2004</td>\n",
855+
" <td>0.121476</td>\n",
856+
" <td>9.925934</td>\n",
857+
" <td>0.474819</td>\n",
858+
" <td>0.474819</td>\n",
859+
" <td>0.040573</td>\n",
860+
" <td>0</td>\n",
861+
" <td>NaN</td>\n",
862+
" <td>3</td>\n",
863+
" <td>7</td>\n",
864+
" </tr>\n",
865+
" <tr>\n",
866+
" <th>1</th>\n",
867+
" <td>1</td>\n",
868+
" <td>1</td>\n",
869+
" <td>1993</td>\n",
870+
" <td>0.226682</td>\n",
871+
" <td>10.377197</td>\n",
872+
" <td>0.491892</td>\n",
873+
" <td>0.491892</td>\n",
874+
" <td>0.075296</td>\n",
875+
" <td>0</td>\n",
876+
" <td>NaN</td>\n",
877+
" <td>3</td>\n",
878+
" <td>7</td>\n",
879+
" </tr>\n",
880+
" </tbody>\n",
881+
"</table>\n",
882+
"</div>"
883+
],
884+
"text/plain": [
885+
" run_number scenario arrivals mean_q_time_nurse mean_time_with_nurse \\\n",
886+
"0 0 0 2004 0.486680 9.925934 \n",
887+
"1 1 0 1993 0.746175 10.377197 \n",
888+
"2 2 0 2017 0.386324 9.856724 \n",
889+
"0 0 1 2004 0.121476 9.925934 \n",
890+
"1 1 1 1993 0.226682 10.377197 \n",
891+
"\n",
892+
" mean_nurse_utilisation mean_nurse_utilisation_tw mean_nurse_q_length \\\n",
893+
"0 0.553955 0.553955 0.162551 \n",
894+
"1 0.573874 0.573874 0.247854 \n",
895+
"2 0.553419 0.553419 0.129869 \n",
896+
"0 0.474819 0.474819 0.040573 \n",
897+
"1 0.491892 0.491892 0.075296 \n",
898+
"\n",
899+
" count_nurse_unseen mean_q_time_nurse_unseen patient_inter \\\n",
900+
"0 0 NaN 3 \n",
901+
"1 0 NaN 3 \n",
902+
"2 0 NaN 3 \n",
903+
"0 0 NaN 3 \n",
904+
"1 0 NaN 3 \n",
905+
"\n",
906+
" number_of_nurses \n",
907+
"0 6 \n",
908+
"1 6 \n",
909+
"2 6 \n",
910+
"0 7 \n",
911+
"1 7 "
912+
]
913+
},
914+
"metadata": {},
915+
"output_type": "display_data"
916+
}
917+
],
918+
"source": [
919+
"# Run scenarios\n",
920+
"param = Param(\n",
921+
" patient_inter=4,\n",
922+
" mean_n_consult_time=10,\n",
923+
" number_of_nurses=5,\n",
924+
" warm_up_period=2000,\n",
925+
" data_collection_period=6000,\n",
926+
" number_of_runs=3,\n",
927+
" audit_interval=120,\n",
928+
" cores=1\n",
929+
")\n",
930+
"scenario_results = run_scenarios(\n",
931+
" scenarios={'patient_inter': [3, 4],\n",
932+
" 'number_of_nurses': [6, 7]},\n",
933+
" param=param\n",
934+
")\n",
935+
"\n",
936+
"# Preview\n",
937+
"display(scenario_results.head())\n",
938+
"\n",
939+
"# Save to csv\n",
940+
"scenario_results.to_csv(os.path.join(TESTS, 'scenario.csv'), index=True)"
941+
]
942+
},
746943
{
747944
"cell_type": "markdown",
748945
"metadata": {},
@@ -777,7 +974,7 @@
777974
},
778975
{
779976
"cell_type": "code",
780-
"execution_count": 10,
977+
"execution_count": 11,
781978
"metadata": {},
782979
"outputs": [
783980
{
@@ -1009,7 +1206,7 @@
10091206
},
10101207
{
10111208
"cell_type": "code",
1012-
"execution_count": 11,
1209+
"execution_count": 12,
10131210
"metadata": {},
10141211
"outputs": [
10151212
{
@@ -1031,6 +1228,11 @@
10311228
}
10321229
],
10331230
"metadata": {
1231+
"kernelspec": {
1232+
"display_name": "template-des",
1233+
"language": "python",
1234+
"name": "python3"
1235+
},
10341236
"language_info": {
10351237
"codemirror_mode": {
10361238
"name": "ipython",

0 commit comments

Comments
 (0)