Skip to main content

ebi_objects/conversions/
to_event_log.rs

1use crate::{
2    Activity, ActivityKey, CompressedEventLogXes, EventLogTraceAttributes, EventLogXes,
3    IntoTraceIterator,
4    ebi_objects::{
5        compressed_event_log::CompressedEventLog,
6        compressed_event_log_trace_attributes::CompressedEventLogTraceAttributes,
7        event_log::EventLog, event_log_csv::EventLogCsv, event_log_python::EventLogPython,
8    },
9};
10use process_mining::core::event_data::case_centric::EventLogClassifier;
11
12impl From<CompressedEventLog> for EventLog {
13    fn from(value: CompressedEventLog) -> Self {
14        log::info!("Convert compressed event log into event log.");
15        value.log
16    }
17}
18
19impl From<CompressedEventLogTraceAttributes> for EventLog {
20    fn from(value: CompressedEventLogTraceAttributes) -> Self {
21        log::info!("Convert compressed event log with trace attributes into event log.");
22        value.log.into()
23    }
24}
25
26impl From<EventLogTraceAttributes> for EventLog {
27    fn from(value: EventLogTraceAttributes) -> Self {
28        Self {
29            activity_key: value.activity_key,
30            traces: value.traces.into_iter().map(|(trace, _)| trace).collect(),
31        }
32    }
33}
34
35impl From<EventLogXes> for EventLog {
36    fn from(value: EventLogXes) -> Self {
37        log::info!("Convert XES event log into event log.");
38        let traces = value.iter_traces().collect();
39        Self {
40            activity_key: value.activity_key,
41            traces,
42        }
43    }
44}
45
46impl From<EventLogPython> for EventLog {
47    fn from(value: EventLogPython) -> Self {
48        value.log.into()
49    }
50}
51
52impl From<CompressedEventLogXes> for EventLog {
53    fn from(value: CompressedEventLogXes) -> Self {
54        value.log.into()
55    }
56}
57
58impl From<EventLogCsv> for EventLog {
59    fn from(value: EventLogCsv) -> Self {
60        let traces = value.iter_traces().collect();
61        Self {
62            activity_key: value.activity_key,
63            traces,
64        }
65    }
66}
67
68impl From<(process_mining::EventLog, EventLogClassifier)> for EventLog {
69    fn from(value: (process_mining::EventLog, EventLogClassifier)) -> Self {
70        let mut result = Self {
71            activity_key: ActivityKey::new(),
72            traces: vec![],
73        };
74
75        let (rust4pm_log, classifier) = value;
76
77        for trace_index in 0..rust4pm_log.traces.len() {
78            result.traces.push(
79                rust4pm_log.traces[trace_index]
80                    .events
81                    .iter()
82                    .map(|event| {
83                        result
84                            .activity_key
85                            .process_activity(&classifier.get_class_identity(event))
86                    })
87                    .collect::<Vec<Activity>>(),
88            );
89        }
90
91        result
92    }
93}