Skip to content

Commit

Permalink
Update process_mining + Handle SQLite Import
Browse files Browse the repository at this point in the history
  • Loading branch information
aarkue committed Oct 7, 2024
1 parent f0defab commit 6c416c7
Show file tree
Hide file tree
Showing 16 changed files with 389 additions and 225 deletions.
276 changes: 187 additions & 89 deletions Cargo.lock

Large diffs are not rendered by default.

227 changes: 147 additions & 80 deletions backend/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = {version = "1.0.192" , features = ["derive"]}
serde_json = "1.0.108"
serde_with = "3.8.1"
ts-rs = { version = "8.1", features = ["serde-compat","chrono-impl"] }
process_mining = "0.3.14"
process_mining = { version = "0.3.17", features=["ocel-sqlite"]}
rayon = "1.8.0"
itertools = "0.11.0"
chrono = "0.4.33"
Expand Down
1 change: 0 additions & 1 deletion backend/shared/src/binding_box/expand_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ impl BindingBox {
let obj_types = self.new_object_vars.get(ob_var).unwrap();
e.relationships
.iter()
.flatten()
.filter(|rel| {
obj_types.contains(
&ocel.ob_by_id(&rel.object_id).unwrap().object_type,
Expand Down
25 changes: 10 additions & 15 deletions backend/shared/src/binding_box/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,18 +617,15 @@ impl Filter {
} => {
let ob = b.get_ob(object, ocel).unwrap();
let ev = b.get_ev(event, ocel).unwrap();
ev.relationships.as_ref().is_some_and(
|rels: &Vec<process_mining::ocel::ocel_struct::OCELRelationship>| {
rels.iter().any(|rel| {
rel.object_id == ob.id
&& if let Some(q) = qualifier {
&rel.qualifier == q
} else {
true
}
})
},
)

ev.relationships.iter().any(|rel| {
rel.object_id == ob.id
&& if let Some(q) = qualifier {
&rel.qualifier == q
} else {
true
}
})
}
Filter::O2O {
object,
Expand All @@ -637,16 +634,14 @@ impl Filter {
} => {
let ob1 = b.get_ob(object, ocel).unwrap();
let ob2 = b.get_ob(other_object, ocel).unwrap();
ob1.relationships.as_ref().is_some_and(|rels| {
rels.iter().any(|rel| {
ob1.relationships.iter().any(|rel| {
rel.object_id == ob2.id
&& if let Some(q) = qualifier {
&rel.qualifier == q
} else {
true
}
})
})
}
Filter::TimeBetweenEvents {
from_event: ev_var_1,
Expand Down
7 changes: 2 additions & 5 deletions backend/shared/src/ocel_qualifiers/qualifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ pub fn get_qualifiers_for_event_types(
ocel.events
.iter()
.filter(|ev| ev.event_type == et.name)
.map(|ev| match ev.relationships.as_ref() {
Some(rs) => rs
.map(|ev| ev.relationships
.iter()
.filter_map(|r| {
let obj = ocel.objects.iter().find(|o| o.id == r.object_id);
Expand All @@ -35,9 +34,7 @@ pub fn get_qualifiers_for_event_types(
.fold(HashMap::new(), |mut acc, c| {
*acc.entry(c).or_insert(0) += 1;
acc
}),
None => HashMap::new(),
})
}))
.fold(HashMap::new(), |mut acc, c| {
c.into_iter().for_each(|(a, b)| {
let entry: &mut Vec<i32> = acc.entry(a).or_default();
Expand Down
14 changes: 4 additions & 10 deletions backend/shared/src/preprocessing/linked_ocel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,11 @@ pub fn get_events_of_type_associated_with_objects(
}

pub fn get_event_relationships(ev: &OCELEvent) -> Vec<OCELRelationship> {
match &ev.relationships {
Some(rels) => rels.clone(),
None => Vec::default(),
}
ev.relationships.clone()
}

pub fn get_object_relationships(obj: &OCELObject) -> Vec<OCELRelationship> {
match &obj.relationships {
Some(rels) => rels.clone(),
None => Vec::new(),
}
obj.relationships.clone()
}

///
Expand Down Expand Up @@ -361,7 +355,7 @@ pub fn link_ocel_info(ocel: OCEL) -> IndexLinkedOCEL {
let mut types_rel_counts: HashMap<EventOrObjectType, usize> = HashMap::new();
for (e_index_usize, e) in ocel.events.iter().enumerate() {
let e_index = EventOrObjectIndex::Event(EventIndex(e_index_usize));
for r in e.relationships.iter().flatten() {
for r in e.relationships.iter() {
if let Some(object_index) = object_index_map.get(&r.object_id) {
let o2_index = EventOrObjectIndex::Object(*object_index);
symmetric_rels.entry(e_index).or_default().insert((
Expand Down Expand Up @@ -390,7 +384,7 @@ pub fn link_ocel_info(ocel: OCEL) -> IndexLinkedOCEL {
}
for (o_index_usize, o) in ocel.objects.iter().enumerate() {
let o_index = EventOrObjectIndex::Object(ObjectIndex(o_index_usize));
for r in o.relationships.iter().flatten() {
for r in o.relationships.iter() {
if let Some(object_index) = object_index_map.get(&r.object_id) {
let o2_index = EventOrObjectIndex::Object(*object_index);
symmetric_rels.entry(o_index).or_default().insert((
Expand Down
10 changes: 2 additions & 8 deletions backend/shared/src/preprocessing/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,11 @@ pub fn get_events_of_type_associated_with_objects(
}

pub fn get_event_relationships(ev: &OCELEvent) -> Vec<OCELRelationship> {
match &ev.relationships {
Some(rels) => rels.clone(),
None => Vec::default(),
}
ev.relationships.clone()
}

pub fn get_object_relationships(obj: &OCELObject) -> Vec<OCELRelationship> {
match &obj.relationships {
Some(rels) => rels.clone(),
None => Vec::new(),
}
obj.relationships.clone()
}

///
Expand Down
6 changes: 3 additions & 3 deletions backend/web-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = "0.6.20"
axum = "0.7.7"
tokio = { version = "1", features = ["full"] }
serde = {version = "1.0.192" , features = ["derive"]}
serde_json = "1.0.108"
process_mining = "0.3.14"
process_mining = { version = "0.3.17", features=["ocel-sqlite"]}
ocedeclare-shared = {path = "../shared"}
tower-http = { version = "0.4.3", features = ["cors"] }
tower-http = { version = "0.6.1", features = ["cors"] }
rayon = "1.8.0"
itertools = "0.11.0"
chrono = "0.4.33"
Expand Down
25 changes: 20 additions & 5 deletions backend/web-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use axum::{
Json, Router,
};
use itertools::Itertools;
use tokio::net::TcpListener;

use std::{
collections::{HashMap, HashSet},
Expand All @@ -28,9 +29,7 @@ use ocedeclare_shared::{
EventWithIndex, IndexOrID, OCELInfo, ObjectWithIndex,
};
use process_mining::{
event_log::ocel::ocel_struct::OCEL,
import_ocel_xml_slice,
ocel::ocel_struct::{OCELEvent, OCELObject},
event_log::ocel::ocel_struct::OCEL, import_ocel_sqlite_from_slice, import_ocel_xml_slice, ocel::ocel_struct::{OCELEvent, OCELObject}
};
use tower_http::cors::CorsLayer;

Expand Down Expand Up @@ -70,6 +69,10 @@ async fn main() {
"/ocel/upload-xml",
post(upload_ocel_xml).layer(DefaultBodyLimit::disable()),
)
.route(
"/ocel/upload-sqlite",
post(upload_ocel_sqlite).layer(DefaultBodyLimit::disable()),
)
.route("/ocel/available", get(get_available_ocels))
.route(
"/ocel/event-qualifiers",
Expand All @@ -93,8 +96,8 @@ async fn main() {
.route("/", get(|| async { "Hello, Aaron!" }))
.layer(cors);
// run it with hyper on localhost:3000
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener,app.into_make_service())
.await
.unwrap();
}
Expand All @@ -120,6 +123,18 @@ async fn upload_ocel_xml<'a>(
(StatusCode::OK, Json(ocel_info))
}

async fn upload_ocel_sqlite<'a>(
State(state): State<AppState>,
ocel_bytes: Bytes,
) -> (StatusCode, Json<OCELInfo>) {
let ocel = import_ocel_sqlite_from_slice(&ocel_bytes).unwrap();
let mut x: std::sync::RwLockWriteGuard<'_, Option<IndexLinkedOCEL>> = state.ocel.write().unwrap();
let ocel_info: OCELInfo = (&ocel).into();
*x = Some(IndexLinkedOCEL::new(ocel));

(StatusCode::OK, Json(ocel_info))
}

async fn upload_ocel_json<'a>(
State(state): State<AppState>,
ocel_bytes: Bytes,
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const VALID_OCEL_MIME_TYPES = [
"text/json",
"text/xml",
"application/xml",
"application/vnd.sqlite3",
"application/vnd.sqlite",

];
export const OcelInfoContext = createContext<OCELInfo | undefined>(undefined);

Expand Down Expand Up @@ -279,7 +282,7 @@ function App() {
or drag a file here
</p>
<p className="text-xs text-gray-500">
Supported: OCEL2-JSON, OCEL2-XML
Supported: OCEL2-JSON, OCEL2-XML, OCEL2-SQLITE
</p>
</div>
<input
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/BackendProviderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const API_WEB_SERVER_BACKEND_PROVIDER: BackendProvider = {
).json();
},
"ocel/upload": async (ocelFile) => {
const type = ocelFile.name.endsWith(".json") ? "json" : "xml";
const type = ocelFile.name.endsWith(".json") ? "json" : ocelFile.name.endsWith(".xml") ? "xml" : "sqlite";
return await (
await fetch(BACKEND_URL + `/ocel/upload-${type}`, {
method: "post",
Expand Down
3 changes: 1 addition & 2 deletions tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ tauri-build = { version = "1.5.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
# tauri = { version = "1.6.1", features = ["dialog-open"] }
tauri = { version = "1.6.1", features = ["dialog-open", "devtools"] }
process_mining = "0.3.14"
process_mining = { version = "0.3.17", features= ["ocel-sqlite"] }
ocedeclare-shared = {path = "../../backend/shared"}


Expand Down
7 changes: 5 additions & 2 deletions tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use ocedeclare_shared::{
preprocessing::linked_ocel::{link_ocel_info, IndexLinkedOCEL},
EventWithIndex, IndexOrID, OCELInfo, ObjectWithIndex,
};
use process_mining::{import_ocel_json_from_path, import_ocel_xml_file};
use process_mining::{import_ocel_json_from_path, import_ocel_sqlite_from_path, import_ocel_xml_file};
use tauri::State;

type OCELStore = Mutex<Option<IndexLinkedOCEL>>;
Expand All @@ -27,7 +27,10 @@ type OCELStore = Mutex<Option<IndexLinkedOCEL>>;
fn import_ocel(path: &str, state: tauri::State<OCELStore>) -> Result<OCELInfo, String> {
let ocel = match path.ends_with(".json") {
true => import_ocel_json_from_path(path).map_err(|e| format!("{:?}", e))?,
false => import_ocel_xml_file(path),
false => match path.ends_with(".xml") {
true => import_ocel_xml_file(path),
false => import_ocel_sqlite_from_path(path).map_err(|e| format!("{:?}", e))?,
},
};
let ocel_info: OCELInfo = (&ocel).into();
let mut state_guard = state.lock().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tauri/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "OCPQ-tauri",
"version": "0.5.1"
"version": "0.6.1"
},
"tauri": {
"allowlist": {
Expand Down
2 changes: 1 addition & 1 deletion tauri/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const tauriBackend: BackendProvider = {
"ocel/picker": async () => {
const path = await dialog.open({
title: "Select an OCEL2 file",
filters: [{ name: "OCEL2", extensions: ["json", "xml"] }],
filters: [{ name: "OCEL2", extensions: ["json", "xml","sqlite","sqlite3","db"] }],
});
if (typeof path === "string") {
const ocelInfo: OCELInfo = await invoke("import_ocel", { path });
Expand Down

0 comments on commit 6c416c7

Please sign in to comment.