babylon.engine.event_evaluator

Event Template evaluation engine.

Provides pure functions to evaluate EventTemplates against WorldState graphs. This is NOT a System - it’s a utility module used by Systems or the engine.

Sprint: Event Template System

Functions

aggregate_and_compare(values, aggregation, ...)

Aggregate values and compare to threshold.

calculate_graph_metric(graph, metric)

Calculate a graph-level aggregate metric.

compare(value, operator, threshold)

Apply comparison operator.

evaluate_edge_condition(condition, graph)

Evaluate an EdgeCondition against edges.

evaluate_graph_condition(condition, graph)

Evaluate a GraphCondition against graph-level metrics.

evaluate_node_condition(condition, graph)

Evaluate a NodeCondition against matching nodes.

evaluate_preconditions(preconditions, graph)

Evaluate a PreconditionSet against the graph.

evaluate_template(template, graph, current_tick)

Evaluate an EventTemplate against the current graph state.

filter_nodes(graph, node_filter)

Filter nodes based on NodeFilter criteria.

get_matching_nodes_for_resolution(template, ...)

Get nodes that match the template's node conditions.

get_nested_value(data, path)

Get a value from nested dict using dot notation.

babylon.engine.event_evaluator.evaluate_template(template, graph, current_tick)[source]

Evaluate an EventTemplate against the current graph state.

Parameters:
  • template – The EventTemplate to evaluate.

  • graph – NetworkX graph representing WorldState.

  • current_tick – Current simulation tick.

Returns:

The matching Resolution if preconditions met and a resolution matches, None otherwise.

Return type:

Resolution | None

babylon.engine.event_evaluator.evaluate_preconditions(preconditions, graph)[source]

Evaluate a PreconditionSet against the graph.

Parameters:
  • preconditions – Set of conditions to evaluate.

  • graph – NetworkX graph to evaluate against.

Returns:

True if preconditions are satisfied, False otherwise.

Return type:

bool

babylon.engine.event_evaluator.evaluate_node_condition(condition, graph)[source]

Evaluate a NodeCondition against matching nodes.

Parameters:
  • condition – The node condition to evaluate.

  • graph – NetworkX graph to evaluate against.

Returns:

True if condition is satisfied, False otherwise.

Return type:

bool

babylon.engine.event_evaluator.evaluate_edge_condition(condition, graph)[source]

Evaluate an EdgeCondition against edges.

Parameters:
  • condition – The edge condition to evaluate.

  • graph – NetworkX graph to evaluate against.

Returns:

True if condition is satisfied, False otherwise.

Return type:

bool

babylon.engine.event_evaluator.evaluate_graph_condition(condition, graph)[source]

Evaluate a GraphCondition against graph-level metrics.

Parameters:
  • condition – The graph condition to evaluate.

  • graph – NetworkX graph to evaluate against.

Returns:

True if condition is satisfied, False otherwise.

Return type:

bool

babylon.engine.event_evaluator.calculate_graph_metric(graph, metric)[source]

Calculate a graph-level aggregate metric.

Parameters:
  • graph – NetworkX graph to analyze.

  • metric – Name of the metric to calculate.

Returns:

The calculated metric value.

Return type:

float

babylon.engine.event_evaluator.filter_nodes(graph, node_filter)[source]

Filter nodes based on NodeFilter criteria.

Parameters:
  • graph – NetworkX graph containing nodes.

  • node_filter – Filter criteria, or None for all nodes.

Returns:

List of node IDs matching the filter.

Return type:

list[str]

babylon.engine.event_evaluator.get_nested_value(data, path)[source]

Get a value from nested dict using dot notation.

Follows the same pattern as TriggerCondition._get_nested_value.

Parameters:
  • data (dict[str, Any]) – Dictionary to search.

  • path (str) – Dot-notation path (e.g., ideology.agitation).

Return type:

float | None

Returns:

The value as float, or None if not found.

babylon.engine.event_evaluator.compare(value, operator, threshold)[source]

Apply comparison operator.

Parameters:
  • value (float) – Value to compare.

  • operator (str) – Comparison operator.

  • threshold (float) – Threshold to compare against.

Return type:

bool

Returns:

True if comparison succeeds, False otherwise.

babylon.engine.event_evaluator.aggregate_and_compare(values, aggregation, operator, threshold)[source]

Aggregate values and compare to threshold.

Parameters:
  • values (list[float]) – List of values to aggregate.

  • aggregation (str) – Aggregation method.

  • operator (str) – Comparison operator.

  • threshold (float) – Threshold to compare against.

Return type:

bool

Returns:

True if aggregated comparison succeeds, False otherwise.

babylon.engine.event_evaluator.get_matching_nodes_for_resolution(template, graph)[source]

Get nodes that match the template’s node conditions.

Used for ${node_id} substitution in resolution effects.

Parameters:
  • template – The EventTemplate being resolved.

  • graph – NetworkX graph to search.

Returns:

List of node IDs that satisfy the node conditions.

Return type:

list[str]