logging.EventLogger
logging.EventLogger(self, event_model=BaseEvent, env=None, run_number=None)Methods
| Name | Description |
|---|---|
| generate_dfg | Generate a Directly-Follows Graph (DFG) from the simulation data. |
| get_events_by_entity | Return all events associated with a specific entity_id. |
| get_events_by_event_name | Return all events of a specific event_type. |
| get_events_by_event_type | Return all events of a specific event_type. |
| get_events_by_run | Return all events associated with a specific entity_id. |
| log_arrival | Helper to log an arrival event with the correct event_type and event fields. |
| log_custom_event | Log a custom event. The ‘event’ here can be any string describing the queue event. |
| log_departure | Helper to log a departure event with the correct event_type and event fields. |
| log_queue | Log a queue event. The ‘event’ here can be any string describing the queue event. |
| log_resource_use_end | Log the end of resource use. Requires resource_id. |
| log_resource_use_start | Log the start of resource use. Requires resource_id. |
| plot_entity_timeline | Plot a timeline of events for a given entity. |
| to_csv | Write the log to a CSV file. |
| to_dataframe | Convert the event log to a pandas DataFrame. |
| to_json | Write the event log to a JSON file or file-like buffer. |
| to_json_string | Return the event log as a pretty JSON string. |
generate_dfg
logging.EventLogger.generate_dfg(
output_format='graphviz-object',
input_time_format='minutes',
**kwargs,
)Generate a Directly-Follows Graph (DFG) from the simulation data.
This method converts the object to a dataframe, appends simulation timestamps, discovers transitions between activities, and renders the result using the specified visualization backend.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| output_format | DFGType | The format of the returned graph. Supported values are: - “graphviz-object”: Returns a Graphviz object for rendering. - “graphviz-image”: Returns a static image of the graph. - “cytoscape-jupyter”: Returns an interactive Cytoscape widget for Jupyter notebooks. - “cytoscape-streamlit”: Returns a Cytoscape component compatible with Streamlit. By default “graphviz-object”. | 'graphviz-object' |
| input_time_format | str | The time unit used to calculate durations and timestamps, by default “minutes”. | 'minutes' |
| **kwargs | Arbitrary keyword arguments passed to the underlying rendering functions (dfg_to_graphviz, dfg_to_cytoscape, etc.). |
{} |
Returns
| Name | Type | Description |
|---|---|---|
| graphviz.Source or ipycytoscape.CytoscapeWidget or bytes | The rendered graph object in the format specified by output_format. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the provided output_format is not a valid DFGType. |
Notes
This function is a wrapper. For detailed information on how nodes and edges are calculated, or for specific rendering parameters available in **kwargs, please refer to the documentation for:
- :func:
discover_dfg: For edge discovery logic. - :func:
dfg_to_graphviz: For Graphviz-specific styling kwargs. - :func:
dfg_to_cytoscape: For jupyter cytoscape styling kwargs. - :func:
dfg_to_cytoscape_streamlit: For streamlit cytoscape styling kwargs.
get_events_by_entity
logging.EventLogger.get_events_by_entity(entity_id, as_dataframe=True)Return all events associated with a specific entity_id.
get_events_by_event_name
logging.EventLogger.get_events_by_event_name(event_name, as_dataframe=True)Return all events of a specific event_type.
get_events_by_event_type
logging.EventLogger.get_events_by_event_type(event_type, as_dataframe=True)Return all events of a specific event_type.
get_events_by_run
logging.EventLogger.get_events_by_run(run_number, as_dataframe=True)Return all events associated with a specific entity_id.
log_arrival
logging.EventLogger.log_arrival(
entity_id,
time=None,
pathway=None,
run_number=None,
**extra_fields,
)Helper to log an arrival event with the correct event_type and event fields.
log_custom_event
logging.EventLogger.log_custom_event(
entity_id,
event_type,
event,
time=None,
pathway=None,
run_number=None,
**extra_fields,
)Log a custom event. The ‘event’ here can be any string describing the queue event. An ‘event_type’ must also be passed, but can be any string of the user’s choosing.
log_departure
logging.EventLogger.log_departure(
entity_id,
time=None,
pathway=None,
run_number=None,
**extra_fields,
)Helper to log a departure event with the correct event_type and event fields.
log_queue
logging.EventLogger.log_queue(
entity_id,
event,
time=None,
pathway=None,
run_number=None,
**extra_fields,
)Log a queue event. The ‘event’ here can be any string describing the queue event.
log_resource_use_end
logging.EventLogger.log_resource_use_end(
entity_id,
resource_id,
time=None,
pathway=None,
run_number=None,
**extra_fields,
)Log the end of resource use. Requires resource_id.
log_resource_use_start
logging.EventLogger.log_resource_use_start(
entity_id,
resource_id,
time=None,
pathway=None,
run_number=None,
**extra_fields,
)Log the start of resource use. Requires resource_id.
plot_entity_timeline
logging.EventLogger.plot_entity_timeline(
entity_id,
split_by_entity_type=False,
show_labels=False,
)Plot a timeline of events for a given entity.
This method visualizes the sequence of events for a specified entity from the event log as a scatter plot. The timeline is plotted using Plotly, with events displayed along the time axis. Events can be split vertically by their type or shown by event labels. Optionally, labels can be displayed directly on the plot.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| entity_id | any | Identifier of the entity whose events should be plotted. | required |
| split_by_entity_type | bool | If True, the y-axis shows event types to separate events vertically. If False, the y-axis shows the event labels. | False |
| show_labels | bool | If True, the event labels are displayed as text on the plot. If False, no labels are shown. | False |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the event log is empty. | |
| ValueError | If no events are found for the given entity_id. |
See Also
to_dataframe : Convert the event log into a DataFrame for analysis.
Notes
- The plot is displayed using
plotly.express.scatter. - The y-axis is treated as categorical to improve readability.
- Marker styling includes a fixed size and outline color for clarity.
to_csv
logging.EventLogger.to_csv(path_or_buffer)Write the log to a CSV file.
to_dataframe
logging.EventLogger.to_dataframe()Convert the event log to a pandas DataFrame.
to_json
logging.EventLogger.to_json(path_or_buffer, indent=2)Write the event log to a JSON file or file-like buffer.
to_json_string
logging.EventLogger.to_json_string(indent=2)Return the event log as a pretty JSON string.