sequenceDiagram participant U as User participant AAL as animate_activity_log (The Director) participant RFA as reshape_for_animations (Snapshot Prep) participant GAD as generate_animation_df (Position Calc) participant GA as generate_animation (Animation Builder) participant PFig as Plotly Figure (The Movie) U->>AAL: Call with event_log, layout, options AAL->>RFA: Process event_log for snapshots RFA-->>AAL: Return snapshot data AAL->>GAD: Calculate (x, y) positions using snapshot data & layout GAD-->>AAL: Return data with positions AAL->>GA: Generate animation using positioned data & options GA-->>AAL: Return Plotly animation object AAL-->>U: Return Plotly Figure
Chapter 1: Animation Facade (animate_activity_log
)
Welcome to vidigi
! If you’ve ever watched a simulation of people moving through a hospital, a queue at a shop, or any process, you know how helpful visualizations can be. vidigi
is designed to help you create exactly those kinds of animations from your process data.
But creating animations can seem complicated, right? You need to track where everyone is at every moment, figure out their positions on the screen, and then stitch it all together. It sounds like a lot of work!
That’s where animate_activity_log
comes in. Think of it as the “Easy Button” for creating your vidigi
animations.
How to Use animate_activity_log
(A Simple Example)
Let’s say you have your data ready in two tables (we’ll learn how to make these in later chapters!):
my_event_log
: A table listing every time a patient arrived, started waiting, got treated, etc.my_layout
: A table defining the (x, y) coordinates on the screen for “Arrival”, “Waiting Area”, “Treatment Room”, and “Exit”.
Using animate_activity_log
is straightforward:
# Import the function first
from vidigi.animation import animate_activity_log
import pandas as pd # We'll use pandas DataFrames
# --- Pretend we have these already ---
# (Chapters 2 & 3 will show how to create these!)
= pd.DataFrame({ # A simplified example log
my_event_log 'patient': [1, 1, 1, 1, 2, 2, 2, 2],
'event': ['arrival', 'start_wait', 'start_treat', 'depart',
'arrival', 'start_wait', 'start_treat', 'depart'],
'time': [0, 0, 5, 15, 2, 2, 8, 20],
# ... other columns needed like event_type, pathway, resource_id ...
'event_type': ['arrival_departure','queue','resource_use','arrival_departure',
'arrival_departure','queue','resource_use','arrival_departure'],
'pathway': ['A','A','A','A', 'A','A','A','A'],
'resource_id': [None, None, 1, None, None, None, 2, None],
'run': [1,1,1,1, 1,1,1,1]
})
= pd.DataFrame({ # A simplified example layout
my_layout 'event': ['arrival', 'start_wait', 'start_treat', 'depart'],
'x': [10, 50, 100, 150],
'y': [50, 50, 50, 50],
'label': ['Arrival', 'Waiting', 'Treatment', 'Exit'], # Human-readable names
'resource': [None, None, 'treatment_rooms', None] # Link resource events to capacity
})
# --- A simple scenario object (optional) ---
class SimpleScenario:
= 2 # Let's say we have 2 treatment rooms
treatment_rooms = SimpleScenario()
scenario_details
# --- Now, the magic happens! ---
# Call the "Easy Button" function
= animate_activity_log(
my_animation =my_event_log, # What happened?
event_log=my_layout, # Where should things be?
event_position_df=scenario_details, # How many resources? (Optional)
scenario='dhm', # Show time as days/hours/mins
time_display_units=20, # Make icons a bit smaller
icon_and_text_size=1 # Take a snapshot every 1 time unit
every_x_time_units
)
# You can now display the animation (e.g., in a Jupyter Notebook)
# my_animation.show() # This would pop up the interactive animation
What happens when you run this?
You don’t get numbers or text back directly. Instead, my_animation
holds an interactive Plotly animation object. If you were running this in a tool like a Jupyter Notebook and called my_animation.show()
, you’d see an animation appear, showing little icons (representing patients) moving from the ‘Arrival’ location, possibly waiting at ‘Waiting’, moving to ‘Treatment’, and finally leaving via ‘Exit’, all synchronized with the times in my_event_log
.
What’s Happening Under the Hood?
animate_activity_log
acts like our movie director, but it relies on a crew of helper functions to do the actual work. Here’s a simplified view of the steps it takes internally when you call it:
- Snapshot Prep (Act 1): The raw
event_log
tells us when things change, but an animation needs to know where everyone is at regular intervals (like every minute, or every 10 minutes).animate_activity_log
first calls helper functions (reshape_for_animations
) to process the event log and figure out the status (location or activity) of every patient at each “snapshot” time. - Position Calculation (Act 2): Knowing a patient is “Waiting” isn’t enough for the animation; we need exact (x, y) screen coordinates.
animate_activity_log
uses another helper (generate_animation_df
) along with yourevent_position_df
(the layout) to calculate the precise (x, y) position for every patient in every snapshot, handling things like arranging patients neatly in queues or assigning them to specific resource slots (like Treatment Room 1 vs. Treatment Room 2). - Animation Generation (The Final Cut): With the fully prepared data frame containing patient IDs, icons, and precise (x, y) coordinates for every time snapshot,
animate_activity_log
calls the final specialist function (generate_animation
). This function takes all that prepared data and uses the Plotly library to build the actual interactive animation figure, complete with a timeline slider, play/pause buttons, and tooltips.
Here’s a diagram showing that flow:
Essentially, animate_activity_log
orchestrates calls to these more specialized functions, which you can explore in later chapters:
- Snapshot Preparation (
reshape_for_animations
&generate_animation_df
) - Animation Generation (
generate_animation
)
You can call these functions individually if you need very fine-grained control, but for most uses, the animate_activity_log
facade is the way to go!
Key Customization Options
While we used basic options above, animate_activity_log
has many parameters to customize your animation:
every_x_time_units
: How often to take a snapshot (smaller numbers = smoother but potentially slower animation).icon_and_text_size
: Controls the size of the patient icons and any labels.add_background_image
: You can overlay the animation on a floor plan or diagram!time_display_units
: Show time as simple numbers, or format it like ‘Days:Hours:Minutes’.frame_duration
/frame_transition_duration
: Control the speed of the animation playback.wrap_queues_at
: How many patients to show in a line before starting a new row in a queue.
…and many more! Check the function’s documentation for all the possibilities.
Conclusion
You’ve now met animate_activity_log
, the main entry point and “easy button” for creating process animations with vidigi
. It acts as a facade, hiding the complexity of data preparation and animation generation by coordinating specialized helper functions. You provide the raw event data and layout information, and it delivers the final animated visualization.
But how do we get that crucial event_log
data in the first place? That’s exactly what we’ll cover in the next chapter!
Next up: Chapter 2: Event Log
Generated by AI Codebase Knowledge Builder