Skip to content

Commit

Permalink
fix(ccmodel-hepheastus): pr fixes
Browse files Browse the repository at this point in the history
Signed-off-by: brunoffmateus <[email protected]>
Signed-off-by: Rafael Belchior <[email protected]>
  • Loading branch information
brunoffmateus authored and RafaelAPB committed Nov 27, 2024
1 parent d2cb962 commit 9b0aa48
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 233 deletions.
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"cccs",
"ccep",
"ccid",
"ccmodel",
"cctx",
"celo",
"cids",
"clazz",
Expand Down Expand Up @@ -206,6 +208,7 @@
"undici",
"unixfs",
"Unmarshal",
"unmodeled",
"utxoexample",
"uuidv",
"vscc",
Expand Down
3 changes: 1 addition & 2 deletions packages/cactus-plugin-ccmodel-hephaestus/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cactus-openapi-spec-plugin-consortium-manual.json
src/main/typescript/generated/openapi/typescript-axios/.npmignore
src/test/csv
src/test/json
src/test/ccLogs
10 changes: 10 additions & 0 deletions packages/cactus-plugin-ccmodel-hephaestus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ In the root of the project to install the dependencies execute the command:
npm run configure
```

The plugin requires Python and packages for process mining functionality. Install the following prerequisites:
1. Python 3.x and pip:
```sh
sudo apt install python3 python3-pip
```
2. Required Python packages:
```sh
pip3 install pm4py pandas
```

Know how to use the following plugins of the project:

- [cactus-plugin-ledger-connector-besu](https://github.com/hyperledger/cactus/tree/main/packages/cactus-plugin-ledger-connector-besu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
from pm4py.objects.petri_net.obj import PetriNet, Marking
from pm4py.objects.petri_net.utils import petri_utils

#chage path if necessary
path = os.getcwd()
parent = os.path.dirname(path)
csv_dir = path + "/packages/cactus-plugin-ccmodel-hephaestus/src/test/csv"
json_dir = path + "/packages/cactus-plugin-ccmodel-hephaestus/src/test/json"
pnml_file = path + "/packages/cactus-plugin-ccmodel-hephaestus/src/main/typescript/pm4py-adapter/process_models/pnml/petri_output.pnml"

##################################################################

def import_csv_original(file_path):
Expand All @@ -34,17 +27,6 @@ def import_json_original(file_path):

##################################################################

def unserialize_and_check_conformance_file(ccLog):
net, initial_marking, final_marking = pm4py.read_pnml(pnml_file)
# pm4py.view_petri_net(net, initial_marking, final_marking)

# check conformance:
print("\n----diagnostics:")
diagnostics = pm4py.conformance_diagnostics_alignments(ccLog, net, initial_marking, final_marking)
print(diagnostics)

##################################################################

def divide_model(model):
split_model = model.split(';')
return split_model[0], split_model[1], split_model[2], split_model[3], split_model[4]
Expand Down Expand Up @@ -112,17 +94,15 @@ def unserialize_model(model):
(source, target) = get_from_to_arc(arc)

# source is a place, target is a transition
if get_place(net.places, source) != None:
if get_place(net.places, source) != None:
place = get_place(net.places, source)
transition = get_transition(net.transitions, target)
petri_utils.add_arc_from_to(place, transition, net)

# target is a place, source is a transition
elif get_place(net.places, target) != None:
transition = get_transition(net.transitions, source)
place = get_place(net.places, target)
petri_utils.add_arc_from_to(transition, place, net)

# target and source are both a transition or a place - cannot happen
else:
print("arcs cannot have the same type in source and target")
Expand Down Expand Up @@ -171,13 +151,13 @@ def unserialize_and_check_conformance(ccLog):
if len(non_conforming_activities) != 0:
print("NON-CONFORMANCE:")
print(non_conforming_activities)
print(file)
print(os.path.basename(log_file_path))
return

if len(all_activities) == len(conforming_activities):
print("FULL CONFORMANCE:")
print(conforming_activities)
print(file)
print(os.path.basename(log_file_path))
return

# If there were no skips in the case, then all the conforming activities
Expand All @@ -191,36 +171,36 @@ def unserialize_and_check_conformance(ccLog):
if ignore_skips == True:
print("PARTIAL CONFORMANCE:")
print(conforming_activities)
print(file)
print(os.path.basename(log_file_path))
else:
print("SKIPPED ACTIVITY:")
print(skipped_activities)
print(file)
print(os.path.basename(log_file_path))

##################################################################

def main():
file_csv = file + ".csv"
file_json = file + ".json"

file_path_csv = os.path.join(csv_dir, file_csv)
file_path_json = os.path.join(json_dir, file_json)
if (os.path.exists(file_path_csv)):
ccLog = import_csv_original(file_path_csv)
if not os.path.exists(log_file_path):
print(f"File '{log_file_path}' does not exist")
exit(1)

file_extension = os.path.splitext(log_file_path)[1].lower()

if file_extension == '.csv':
ccLog = import_csv_original(log_file_path)
unserialize_and_check_conformance(ccLog)
elif (os.path.exists(file_path_json)):
ccLog = import_json_original(file_path_json)
elif file_extension == '.json':
ccLog = import_json_original(log_file_path)
unserialize_and_check_conformance(ccLog)
else:
print(f"File '{file}' does not exist")
print(file_path_json)
print(f"Unsupported file type: {file_extension}")
exit(1)

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python3 check_conformance.py file_with_new_logs serialized_ccmodel")
print("Usage: python3 check_conformance.py path_to_log_file serialized_ccmodel")
exit(1)

file = sys.argv[1]
log_file_path = sys.argv[1]
serialized_ccmodel = sys.argv[2]
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import sys
import os
# uncomment if problems with dependencies
#%pip install pm4py
#%pip install pandas
import pm4py
import time
import pandas
import pickle
import json

def import_csv_original(file_path):
event_log = pandas.read_csv(file_path, sep=';')
event_log = pm4py.format_dataframe(event_log, case_id='caseID', activity_key='methodName', timestamp_key='timestamp')
return event_log

def import_json_original(file_path):
with open(file_path, 'r') as file:
data = json.load(file)
event_log = pandas.DataFrame(data)
event_log = pm4py.format_dataframe(event_log, case_id='caseID', activity_key='methodName', timestamp_key='timestamp')
return event_log

##################################################################

def create_and_serialize_model(ccLog):
pn, im, fm = pm4py.discover_petri_net_inductive(ccLog)
# pm4py.view_petri_net(pn, im, fm)
return str(pn.places) + ";" + str(pn.transitions) + ";" + str(pn.arcs) + ";" + str(im) + ";" + str(fm)

##################################################################

def main():
file_path = sys.argv[1]

if not os.path.exists(file_path):
print(f"File '{file_path}' does not exist")
exit(1)

file_extension = os.path.splitext(file_path)[1].lower()

if file_extension == '.csv':
ccLog = import_csv_original(file_path)
serialized_model = create_and_serialize_model(ccLog)
print(serialized_model)
elif file_extension == '.json':
ccLog = import_json_original(file_path)
serialized_model = create_and_serialize_model(ccLog)
print(serialized_model)
else:
print(f"Unsupported file type: {file_extension}")
exit(1)

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python3 create_model.py path_to_log_file")
exit(1)

main()
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { execSync } from "child_process";

import path from "path";

export function createModelPM4PY(file_name: string): string {
const createModelScript = path.join(__dirname, "create_model.py");
const command = `python3 ${createModelScript} ${file_name}`;
export function createModelPM4PY(logPath: string): string {
const createModelScript = path.join(__dirname, "../python/create_model.py");
const command = `python3 ${createModelScript} ${logPath}`;

try {
const startTime = new Date();
Expand All @@ -21,11 +21,14 @@ export function createModelPM4PY(file_name: string): string {
}

export function checkConformancePM4PY(
file_name: string,
logPath: string,
serializedCCModel: string,
): string {
const checkConformanceScript = path.join(__dirname, "check_conformance.py");
const command = `python3 ${checkConformanceScript} ${file_name} \'${serializedCCModel}\'`;
const checkConformanceScript = path.join(
__dirname,
"../python/check_conformance.py",
);
const command = `python3 ${checkConformanceScript} ${logPath} \'${serializedCCModel}\'`;

// console.log(command);
try {
Expand Down
Loading

0 comments on commit 9b0aa48

Please sign in to comment.