diff --git a/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.drawio b/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.drawio new file mode 100644 index 0000000..f339809 --- /dev/null +++ b/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.drawio @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.drawio.png b/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.drawio.png new file mode 100644 index 0000000..aa1b68d Binary files /dev/null and b/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.drawio.png differ diff --git a/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.png b/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.png new file mode 100644 index 0000000..aa1b68d Binary files /dev/null and b/examples/example_5_simplest_case_wrapped_resources/Simplest Model Background Image - larger treatment area - Horizontal Layout.png differ diff --git a/examples/example_5_simplest_case_wrapped_resources/__init__.py b/examples/example_5_simplest_case_wrapped_resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/example_5_simplest_case_wrapped_resources/ex_5_simplest_case_wrapped_resource.ipynb b/examples/example_5_simplest_case_wrapped_resources/ex_5_simplest_case_wrapped_resource.ipynb new file mode 100644 index 0000000..6015286 --- /dev/null +++ b/examples/example_5_simplest_case_wrapped_resources/ex_5_simplest_case_wrapped_resource.ipynb @@ -0,0 +1,979 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example 1: Simplest Case" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "from examples.example_1_simplest_case.ex_1_model_classes import Trial, g\n", + "from vidigi.animation import animate_activity_log\n", + "import pandas as pd\n", + "import plotly.io as pio\n", + "pio.renderers.default = \"notebook\"" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "g.n_cubicles = 30\n", + "g.trauma_treat_mean = 120\n", + "g.trauma_treat_var = 20\n", + "g.arrival_rate = 3" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "30 nurses\n", + "\n" + ] + } + ], + "source": [ + "my_trial = Trial()\n", + "\n", + "my_trial.run_trial()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
patientpathwayevent_typeeventtimeresource_idrun
01Simplestarrival_departurearrival0.000000NaN0
11Simplestqueuetreatment_wait_begins0.000000NaN0
21Simplestresource_usetreatment_begins0.0000001.00
32Simplestarrival_departurearrival2.039796NaN0
42Simplestqueuetreatment_wait_begins2.039796NaN0
52Simplestresource_usetreatment_begins2.0397962.00
63Simplestarrival_departurearrival5.098587NaN0
73Simplestqueuetreatment_wait_begins5.098587NaN0
83Simplestresource_usetreatment_begins5.0985873.00
94Simplestarrival_departurearrival5.158007NaN0
104Simplestqueuetreatment_wait_begins5.158007NaN0
114Simplestresource_usetreatment_begins5.1580074.00
125Simplestarrival_departurearrival5.164815NaN0
135Simplestqueuetreatment_wait_begins5.164815NaN0
145Simplestresource_usetreatment_begins5.1648155.00
156Simplestarrival_departurearrival6.815844NaN0
166Simplestqueuetreatment_wait_begins6.815844NaN0
176Simplestresource_usetreatment_begins6.8158446.00
187Simplestarrival_departurearrival11.705665NaN0
197Simplestqueuetreatment_wait_begins11.705665NaN0
207Simplestresource_usetreatment_begins11.7056657.00
218Simplestarrival_departurearrival13.726414NaN0
228Simplestqueuetreatment_wait_begins13.726414NaN0
238Simplestresource_usetreatment_begins13.7264148.00
249Simplestarrival_departurearrival15.992318NaN0
259Simplestqueuetreatment_wait_begins15.992318NaN0
269Simplestresource_usetreatment_begins15.9923189.00
2710Simplestarrival_departurearrival24.442676NaN0
2810Simplestqueuetreatment_wait_begins24.442676NaN0
2910Simplestresource_usetreatment_begins24.44267610.00
3011Simplestarrival_departurearrival42.615935NaN0
3111Simplestqueuetreatment_wait_begins42.615935NaN0
3211Simplestresource_usetreatment_begins42.61593511.00
3312Simplestarrival_departurearrival52.475220NaN0
3412Simplestqueuetreatment_wait_begins52.475220NaN0
3512Simplestresource_usetreatment_begins52.47522012.00
3613Simplestarrival_departurearrival52.479083NaN0
3713Simplestqueuetreatment_wait_begins52.479083NaN0
3813Simplestresource_usetreatment_begins52.47908313.00
3914Simplestarrival_departurearrival59.286367NaN0
4014Simplestqueuetreatment_wait_begins59.286367NaN0
4114Simplestresource_usetreatment_begins59.28636714.00
4215Simplestarrival_departurearrival59.503860NaN0
4315Simplestqueuetreatment_wait_begins59.503860NaN0
4415Simplestresource_usetreatment_begins59.50386015.00
4516Simplestarrival_departurearrival62.712061NaN0
4616Simplestqueuetreatment_wait_begins62.712061NaN0
4716Simplestresource_usetreatment_begins62.71206116.00
4817Simplestarrival_departurearrival65.258860NaN0
4917Simplestqueuetreatment_wait_begins65.258860NaN0
\n", + "
" + ], + "text/plain": [ + " patient pathway event_type event time \n", + "0 1 Simplest arrival_departure arrival 0.000000 \\\n", + "1 1 Simplest queue treatment_wait_begins 0.000000 \n", + "2 1 Simplest resource_use treatment_begins 0.000000 \n", + "3 2 Simplest arrival_departure arrival 2.039796 \n", + "4 2 Simplest queue treatment_wait_begins 2.039796 \n", + "5 2 Simplest resource_use treatment_begins 2.039796 \n", + "6 3 Simplest arrival_departure arrival 5.098587 \n", + "7 3 Simplest queue treatment_wait_begins 5.098587 \n", + "8 3 Simplest resource_use treatment_begins 5.098587 \n", + "9 4 Simplest arrival_departure arrival 5.158007 \n", + "10 4 Simplest queue treatment_wait_begins 5.158007 \n", + "11 4 Simplest resource_use treatment_begins 5.158007 \n", + "12 5 Simplest arrival_departure arrival 5.164815 \n", + "13 5 Simplest queue treatment_wait_begins 5.164815 \n", + "14 5 Simplest resource_use treatment_begins 5.164815 \n", + "15 6 Simplest arrival_departure arrival 6.815844 \n", + "16 6 Simplest queue treatment_wait_begins 6.815844 \n", + "17 6 Simplest resource_use treatment_begins 6.815844 \n", + "18 7 Simplest arrival_departure arrival 11.705665 \n", + "19 7 Simplest queue treatment_wait_begins 11.705665 \n", + "20 7 Simplest resource_use treatment_begins 11.705665 \n", + "21 8 Simplest arrival_departure arrival 13.726414 \n", + "22 8 Simplest queue treatment_wait_begins 13.726414 \n", + "23 8 Simplest resource_use treatment_begins 13.726414 \n", + "24 9 Simplest arrival_departure arrival 15.992318 \n", + "25 9 Simplest queue treatment_wait_begins 15.992318 \n", + "26 9 Simplest resource_use treatment_begins 15.992318 \n", + "27 10 Simplest arrival_departure arrival 24.442676 \n", + "28 10 Simplest queue treatment_wait_begins 24.442676 \n", + "29 10 Simplest resource_use treatment_begins 24.442676 \n", + "30 11 Simplest arrival_departure arrival 42.615935 \n", + "31 11 Simplest queue treatment_wait_begins 42.615935 \n", + "32 11 Simplest resource_use treatment_begins 42.615935 \n", + "33 12 Simplest arrival_departure arrival 52.475220 \n", + "34 12 Simplest queue treatment_wait_begins 52.475220 \n", + "35 12 Simplest resource_use treatment_begins 52.475220 \n", + "36 13 Simplest arrival_departure arrival 52.479083 \n", + "37 13 Simplest queue treatment_wait_begins 52.479083 \n", + "38 13 Simplest resource_use treatment_begins 52.479083 \n", + "39 14 Simplest arrival_departure arrival 59.286367 \n", + "40 14 Simplest queue treatment_wait_begins 59.286367 \n", + "41 14 Simplest resource_use treatment_begins 59.286367 \n", + "42 15 Simplest arrival_departure arrival 59.503860 \n", + "43 15 Simplest queue treatment_wait_begins 59.503860 \n", + "44 15 Simplest resource_use treatment_begins 59.503860 \n", + "45 16 Simplest arrival_departure arrival 62.712061 \n", + "46 16 Simplest queue treatment_wait_begins 62.712061 \n", + "47 16 Simplest resource_use treatment_begins 62.712061 \n", + "48 17 Simplest arrival_departure arrival 65.258860 \n", + "49 17 Simplest queue treatment_wait_begins 65.258860 \n", + "\n", + " resource_id run \n", + "0 NaN 0 \n", + "1 NaN 0 \n", + "2 1.0 0 \n", + "3 NaN 0 \n", + "4 NaN 0 \n", + "5 2.0 0 \n", + "6 NaN 0 \n", + "7 NaN 0 \n", + "8 3.0 0 \n", + "9 NaN 0 \n", + "10 NaN 0 \n", + "11 4.0 0 \n", + "12 NaN 0 \n", + "13 NaN 0 \n", + "14 5.0 0 \n", + "15 NaN 0 \n", + "16 NaN 0 \n", + "17 6.0 0 \n", + "18 NaN 0 \n", + "19 NaN 0 \n", + "20 7.0 0 \n", + "21 NaN 0 \n", + "22 NaN 0 \n", + "23 8.0 0 \n", + "24 NaN 0 \n", + "25 NaN 0 \n", + "26 9.0 0 \n", + "27 NaN 0 \n", + "28 NaN 0 \n", + "29 10.0 0 \n", + "30 NaN 0 \n", + "31 NaN 0 \n", + "32 11.0 0 \n", + "33 NaN 0 \n", + "34 NaN 0 \n", + "35 12.0 0 \n", + "36 NaN 0 \n", + "37 NaN 0 \n", + "38 13.0 0 \n", + "39 NaN 0 \n", + "40 NaN 0 \n", + "41 14.0 0 \n", + "42 NaN 0 \n", + "43 NaN 0 \n", + "44 15.0 0 \n", + "45 NaN 0 \n", + "46 NaN 0 \n", + "47 16.0 0 \n", + "48 NaN 0 \n", + "49 NaN 0 " + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_trial.all_event_logs.head(50)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "event_position_df = pd.DataFrame([\n", + " {'event': 'arrival',\n", + " 'x': 50, 'y': 300,\n", + " 'label': \"Arrival\" },\n", + "\n", + " # Triage - minor and trauma\n", + " {'event': 'treatment_wait_begins',\n", + " 'x': 205, 'y': 275,\n", + " 'label': \"Waiting for Treatment\"},\n", + "\n", + " {'event': 'treatment_begins',\n", + " 'x': 205, 'y': 175,\n", + " 'resource':'n_cubicles',\n", + " 'label': \"Being Treated\"},\n", + "\n", + " {'event': 'exit',\n", + " 'x': 270, 'y': 70,\n", + " 'label': \"Exit\"}\n", + "\n", + " ])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Animation function called at 13:43:14\n", + "Iteration through minute-by-minute logs complete 13:43:16\n", + "Snapshot df concatenation complete at 13:43:16\n", + "Reshaped animation dataframe finished construction at 13:43:17\n", + "Placement dataframe finished construction at 13:43:17\n", + "Output animation generation complete at 13:43:19\n", + "Total Time Elapsed: 4.54 seconds\n" + ] + }, + { + "data": { + "text/html": [ + " \n", + " " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "animate_activity_log(\n", + " event_log=my_trial.all_event_logs[my_trial.all_event_logs['run']==1],\n", + " event_position_df= event_position_df,\n", + " scenario=g(),\n", + " debug_mode=True,\n", + " setup_mode=False,\n", + " every_x_time_units=1,\n", + " include_play_button=True,\n", + " icon_and_text_size=20,\n", + " gap_between_entities=6,\n", + " gap_between_rows=25,\n", + " plotly_height=700,\n", + " frame_duration=200,\n", + " plotly_width=1200,\n", + " override_x_max=300,\n", + " override_y_max=500,\n", + " limit_duration=g.sim_duration,\n", + " wrap_queues_at=25,\n", + " wrap_resources_at=None,\n", + " step_snapshot_max=125,\n", + " time_display_units=\"dhm\",\n", + " display_stage_labels=False,\n", + " add_background_image=\"https://raw.githubusercontent.com/Bergam0t/vidigi/refs/heads/main/examples/example_1_simplest_case/Simplest%20Model%20Background%20Image%20-%20Horizontal%20Layout.drawio.png\",\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "event_position_df = pd.DataFrame([\n", + " {'event': 'arrival',\n", + " 'x': 50, 'y': 300,\n", + " 'label': \"Arrival\" },\n", + "\n", + " # Triage - minor and trauma\n", + " {'event': 'treatment_wait_begins',\n", + " 'x': 225, 'y': 280,\n", + " 'label': \"Waiting for Treatment\"},\n", + "\n", + " {'event': 'treatment_begins',\n", + " 'x': 225, 'y': 120,\n", + " 'resource':'n_cubicles',\n", + " 'label': \"Being Treated\"},\n", + "\n", + " {'event': 'exit',\n", + " 'x': 270, 'y': 70,\n", + " 'label': \"Exit\"}\n", + "\n", + " ])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Animation function called at 13:43:19\n", + "Iteration through minute-by-minute logs complete 13:43:22\n", + "Snapshot df concatenation complete at 13:43:22\n", + "Reshaped animation dataframe finished construction at 13:43:22\n", + "Placement dataframe finished construction at 13:43:22\n", + "Output animation generation complete at 13:43:24\n", + "Total Time Elapsed: 4.70 seconds\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "animate_activity_log(\n", + " event_log=my_trial.all_event_logs[my_trial.all_event_logs['run']==1],\n", + " event_position_df= event_position_df,\n", + " scenario=g(),\n", + " debug_mode=True,\n", + " setup_mode=True,\n", + " every_x_time_units=1,\n", + " include_play_button=True,\n", + " icon_and_text_size=20,\n", + " gap_between_entities=6,\n", + " gap_between_rows=25,\n", + " plotly_height=700,\n", + " frame_duration=200,\n", + " plotly_width=1200,\n", + " override_x_max=300,\n", + " override_y_max=500,\n", + " limit_duration=g.sim_duration,\n", + " wrap_queues_at=25,\n", + " wrap_resources_at=15,\n", + " step_snapshot_max=125,\n", + " time_display_units=\"dhm\",\n", + " display_stage_labels=False,\n", + " add_background_image=\"Simplest Model Background Image - larger treatment area - Horizontal Layout.png\",\n", + " )" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "vidigi_package_dev", + "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.11.10" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}