use wasm4pm_compat::event_log::EventLog as CompatEventLog;
pub const DEFAULT_DEPENDENCY_THRESHOLD: f64 = 0.5;
pub fn discover_heuristic_real(
log: &CompatEventLog,
activity_key: &str,
) -> anyhow::Result<wasm4pm::models::DFG> {
let native_log: wasm4pm::models::EventLog = log.clone().into();
let dfg = wasm4pm::advanced_algorithms::discover_heuristic_miner_from_log(
&native_log,
activity_key,
DEFAULT_DEPENDENCY_THRESHOLD,
);
Ok(dfg)
}
#[cfg(test)]
mod tests {
use super::*;
use wasm4pm_compat::event_log::{Event, Trace};
fn build_small_log() -> CompatEventLog {
let trace1 = Trace::new(
"case-1".to_string(),
vec![
Event::with_activity("a"),
Event::with_activity("b"),
Event::with_activity("c"),
],
);
let trace2 = Trace::new(
"case-2".to_string(),
vec![
Event::with_activity("a"),
Event::with_activity("b"),
Event::with_activity("c"),
],
);
let trace3 = Trace::new(
"case-3".to_string(),
vec![
Event::with_activity("a"),
Event::with_activity("b"),
Event::with_activity("d"),
],
);
CompatEventLog {
attributes: Vec::new(),
traces: vec![trace1, trace2, trace3],
extensions: None,
classifiers: None,
global_trace_attrs: None,
global_event_attrs: None,
}
}
#[test]
fn discover_heuristic_real_runs_on_small_log_and_finds_strong_dependency() {
let log = build_small_log();
let dfg = discover_heuristic_real(&log, "concept:name")
.expect("heuristic miner should discover a DFG without panicking");
assert!(
!dfg.nodes.is_empty(),
"expected a non-empty DFG, got {dfg:?}"
);
let has_a_to_b = dfg
.edges
.iter()
.any(|e| e.from == "a" && e.to == "b" && e.frequency == 3);
assert!(
has_a_to_b,
"expected a repeated a->b dependency edge with frequency 3, got edges: {:?}",
dfg.edges
);
let has_b_to_c = dfg
.edges
.iter()
.any(|e| e.from == "b" && e.to == "c" && e.frequency == 2);
assert!(
has_b_to_c,
"expected a repeated b->c dependency edge with frequency 2, got edges: {:?}",
dfg.edges
);
}
}