from examples.example_2_branching_multistep.ex_2_model_classes import Trial, g
from vidigi.animation import animate_activity_log
import pandas as pd
import plotly.io as pio
= "notebook" pio.renderers.default
Example 2: Branching + Multi-step Case
= Trial()
my_trial
my_trial.run_trial()
50) my_trial.all_event_logs.head(
patient | pathway | event | event_type | time | resource_id | run | |
---|---|---|---|---|---|---|---|
0 | 1 | Shared | arrival | arrival_departure | 3.285355 | NaN | 0 |
1 | 1 | Non-Trauma | triage_wait_begins | queue | 3.285355 | NaN | 0 |
2 | 1 | Non-Trauma | triage_begins | resource_use | 3.285355 | 1.0 | 0 |
3 | 2 | Shared | arrival | arrival_departure | 3.289691 | NaN | 0 |
4 | 2 | Non-Trauma | triage_wait_begins | queue | 3.289691 | NaN | 0 |
5 | 2 | Non-Trauma | triage_begins | resource_use | 3.289691 | 2.0 | 0 |
6 | 1 | Non-Trauma | triage_complete | resource_use_end | 7.364946 | 1.0 | 0 |
7 | 1 | Non-Trauma | MINORS_registration_wait_begins | queue | 7.364946 | NaN | 0 |
8 | 1 | Non-Trauma | MINORS_registration_begins | resource_use | 7.364946 | 1.0 | 0 |
9 | 2 | Non-Trauma | triage_complete | resource_use_end | 9.407274 | 2.0 | 0 |
10 | 2 | Non-Trauma | MINORS_registration_wait_begins | queue | 9.407274 | NaN | 0 |
11 | 2 | Non-Trauma | MINORS_registration_begins | resource_use | 9.407274 | 2.0 | 0 |
12 | 1 | Non-Trauma | MINORS_registration_complete | resource_use_end | 15.418481 | 1.0 | 0 |
13 | 1 | Non-Trauma | MINORS_examination_wait_begins | queue | 15.418481 | NaN | 0 |
14 | 1 | Non-Trauma | MINORS_examination_begins | resource_use | 15.418481 | 1.0 | 0 |
15 | 2 | Non-Trauma | MINORS_registration_complete | resource_use_end | 17.104670 | 2.0 | 0 |
16 | 2 | Non-Trauma | MINORS_examination_wait_begins | queue | 17.104670 | NaN | 0 |
17 | 2 | Non-Trauma | MINORS_examination_begins | resource_use | 17.104670 | 2.0 | 0 |
18 | 1 | Non-Trauma | MINORS_examination_complete | resource_use_end | 31.636252 | 1.0 | 0 |
19 | 1 | Shared | depart | arrival_departure | 31.636252 | NaN | 0 |
20 | 2 | Non-Trauma | MINORS_examination_complete | resource_use_end | 32.875857 | 2.0 | 0 |
21 | 2 | Non-Trauma | requires_treatment | attribute_assigned | 32.875857 | NaN | 0 |
22 | 2 | Non-Trauma | MINORS_treatment_wait_begins | queue | 32.875857 | NaN | 0 |
23 | 2 | Non-Trauma | MINORS_treatment_begins | resource_use | 32.875857 | 1.0 | 0 |
24 | 3 | Shared | arrival | arrival_departure | 33.426168 | NaN | 0 |
25 | 3 | Non-Trauma | triage_wait_begins | queue | 33.426168 | NaN | 0 |
26 | 3 | Non-Trauma | triage_begins | resource_use | 33.426168 | 1.0 | 0 |
27 | 3 | Non-Trauma | triage_complete | resource_use_end | 33.545008 | 1.0 | 0 |
28 | 3 | Non-Trauma | MINORS_registration_wait_begins | queue | 33.545008 | NaN | 0 |
29 | 3 | Non-Trauma | MINORS_registration_begins | resource_use | 33.545008 | 1.0 | 0 |
30 | 4 | Shared | arrival | arrival_departure | 37.900548 | NaN | 0 |
31 | 4 | Non-Trauma | triage_wait_begins | queue | 37.900548 | NaN | 0 |
32 | 4 | Non-Trauma | triage_begins | resource_use | 37.900548 | 2.0 | 0 |
33 | 4 | Non-Trauma | triage_complete | resource_use_end | 37.914164 | 2.0 | 0 |
34 | 4 | Non-Trauma | MINORS_registration_wait_begins | queue | 37.914164 | NaN | 0 |
35 | 4 | Non-Trauma | MINORS_registration_begins | resource_use | 37.914164 | 2.0 | 0 |
36 | 3 | Non-Trauma | MINORS_registration_complete | resource_use_end | 42.359504 | 1.0 | 0 |
37 | 3 | Non-Trauma | MINORS_examination_wait_begins | queue | 42.359504 | NaN | 0 |
38 | 3 | Non-Trauma | MINORS_examination_begins | resource_use | 42.359504 | 3.0 | 0 |
39 | 4 | Non-Trauma | MINORS_registration_complete | resource_use_end | 45.938325 | 2.0 | 0 |
40 | 4 | Non-Trauma | MINORS_examination_wait_begins | queue | 45.938325 | NaN | 0 |
41 | 4 | Non-Trauma | MINORS_examination_begins | resource_use | 45.938325 | 1.0 | 0 |
42 | 2 | Non-Trauma | MINORS_treatment_ends | resource_use_end | 46.278797 | 1.0 | 0 |
43 | 2 | Shared | depart | arrival_departure | 46.278797 | NaN | 0 |
44 | 5 | Shared | arrival | arrival_departure | 51.770459 | NaN | 0 |
45 | 5 | Non-Trauma | triage_wait_begins | queue | 51.770459 | NaN | 0 |
46 | 5 | Non-Trauma | triage_begins | resource_use | 51.770459 | 1.0 | 0 |
47 | 5 | Non-Trauma | triage_complete | resource_use_end | 55.072516 | 1.0 | 0 |
48 | 5 | Non-Trauma | MINORS_registration_wait_begins | queue | 55.072516 | NaN | 0 |
49 | 5 | Non-Trauma | MINORS_registration_begins | resource_use | 55.072516 | 1.0 | 0 |
= pd.DataFrame([
event_position_df # {'event': 'arrival', 'x': 10, 'y': 250, 'label': "Arrival" },
# Triage - minor and trauma
'event': 'triage_wait_begins',
{'x': 160, 'y': 375, 'label': "Waiting for<br>Triage" },
'event': 'triage_begins',
{'x': 160, 'y': 315, 'resource':'n_triage', 'label': "Being Triaged" },
# Minors (non-trauma) pathway
'event': 'MINORS_registration_wait_begins',
{'x': 300, 'y': 145, 'label': "Waiting for<br>Registration" },
'event': 'MINORS_registration_begins',
{'x': 300, 'y': 85, 'resource':'n_reg', 'label':'Being<br>Registered' },
'event': 'MINORS_examination_wait_begins',
{'x': 465, 'y': 145, 'label': "Waiting for<br>Examination" },
'event': 'MINORS_examination_begins',
{'x': 465, 'y': 85, 'resource':'n_exam', 'label': "Being<br>Examined" },
'event': 'MINORS_treatment_wait_begins',
{'x': 630, 'y': 145, 'label': "Waiting for<br>Treatment" },
'event': 'MINORS_treatment_begins',
{'x': 630, 'y': 85, 'resource':'n_cubicles_non_trauma_treat', 'label': "Being<br>Treated" },
# Trauma pathway
'event': 'TRAUMA_stabilisation_wait_begins',
{'x': 300, 'y': 560, 'label': "Waiting for<br>Stabilisation" },
'event': 'TRAUMA_stabilisation_begins',
{'x': 300, 'y': 490, 'resource':'n_trauma', 'label': "Being<br>Stabilised" },
'event': 'TRAUMA_treatment_wait_begins',
{'x': 630, 'y': 560, 'label': "Waiting for<br>Treatment" },
'event': 'TRAUMA_treatment_begins',
{'x': 630, 'y': 490, 'resource':'n_cubicles_trauma_treat', 'label': "Being<br>Treated" },
'event': 'exit',
{'x': 670, 'y': 330, 'label': "Exit"}
])
animate_activity_log(=my_trial.all_event_logs[my_trial.all_event_logs['run']==1],
event_log= event_position_df,
event_position_df=g(),
scenario=True,
debug_mode=True,
setup_mode=5,
every_x_time_units=True,
include_play_button=10,
gap_between_entities=20,
gap_between_rows=900,
plotly_height=1600,
plotly_width=700,
override_x_max=675,
override_y_max=20,
icon_and_text_size=10,
wrap_queues_at=50,
step_snapshot_max=g.sim_duration,
limit_duration="dhm",
time_display_units=False,
display_stage_labels="https://raw.githubusercontent.com/Bergam0t/vidigi/refs/heads/main/examples/example_2_branching_multistep/Full%20Model%20Background%20Image%20-%20Horizontal%20Layout.drawio.png",
add_background_image )
Animation function called at 18:04:15
Iteration through minute-by-minute logs complete 18:04:15
Snapshot df concatenation complete at 18:04:15
Reshaped animation dataframe finished construction at 18:04:15
Placement dataframe finished construction at 18:04:15
Output animation generation complete at 18:04:16
Total Time Elapsed: 1.35 seconds