Creative Layouts - Single Hospital Ward Example

Warning

This example has not yet been updated to reflect all of the new features and recommendations from vidigi 2.0.0, which have further simplified the process of adding vidigi to your model and accessing and modifying your animation.

For now, all of the code below will still work, but check out the getting started page for a full guide to the recommended way to use vidigi 2.0.0.

import pandas as pd
import plotly.io as pio
from ex_8_model_classes import Trial, g

from vidigi.animation import animate_activity_log

pio.renderers.default = "notebook"
clinic_simulation = Trial()
clinic_simulation.trial_results
entity_id event_type event time run_number resource_id
0 1 arrival_departure arrival 0.000000 1 NaN
1 1 queue bed_wait_begins 0.000000 1 NaN
2 1 resource_use stay_begins 0.000000 1 1.0
3 2 arrival_departure arrival 2.337500 1 NaN
4 2 queue bed_wait_begins 2.337500 1 NaN
... ... ... ... ... ... ...
2272 453 resource_use_end stay_complete 8719.027185 100 2.0
2273 453 arrival_departure depart 8719.027185 100 NaN
2274 457 arrival_departure arrival 8719.147321 100 NaN
2275 457 queue bed_wait_begins 8719.147321 100 NaN
2276 457 resource_use stay_begins 8719.147321 100 1.0

242708 rows × 6 columns

event_position_df = pd.DataFrame(
    [
        {"event": "arrival", "x": 50, "y": 800, "label": "Arrival"},
        # Triage - minor and trauma
        {"event": "bed_wait_begins", "x": 205, "y": 700, "label": "Waiting for Bed"},
        {
            "event": "stay_begins",
            "x": 205,
            "y": 175,
            "resource": "number_of_beds",
            "label": "In Ward",
        },
        {"event": "depart", "x": 270, "y": 70, "label": "Exit"},
    ]
)
animate_activity_log(
    event_log=clinic_simulation.trial_results[
        clinic_simulation.trial_results["run_number"] == 1
    ],
    event_position_df=event_position_df,
    scenario=g(),
    # Key animation prep parameters
    every_x_time_units=6,
    simulation_time_unit="hours",
    limit_duration=g.sim_duration,
    step_snapshot_max=125,
    # Animation display parameters
    time_display_units="dhm",
    include_play_button=True,
    setup_mode=True,
    debug_mode=True,
    frame_duration=200,
    # Text parameters
    display_stage_labels=True,
    text_size=20,
    # Entity and queue size and spacing
    entity_icon_size=20,
    wrap_queues_at=25,
    gap_between_entities=6,
    gap_between_queue_rows=30,
    # Resource size and spacing
    gap_between_resources=150,
    gap_between_resource_rows=100,
    resource_icon_size=40,
    wrap_resources_at=2,
    custom_resource_icon="🛏️",
    # Plot size
    plotly_height=600,
    plotly_width=1000,
    # Internal plot coordinates
    override_x_max=300,
    override_y_max=900,
)
Animation function called at 13:56:40
Iteration through time-unit-by-time-unit logs complete 13:56:52
Snapshot df concatenation complete at 13:56:52
Reshaped animation dataframe finished construction at 13:56:52
Placement dataframe started construction at 13:56:52
Placement dataframe finished construction at 13:56:52
Output animation generation complete at 13:56:58
Total Time Elapsed: 18.23 seconds
Back to top