Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rework main flow proccessing #13

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def _compose_and_draw(self, pygraph: AGraph, flow: TokenSequence):

return diagram

def _compose_and_draw_inner(self, pygraph: AGraph, flow: TokenSequence, name: str):
def _compose_and_draw_inner(
self, pygraph: AGraph, flow: TokenSequence, name: str
):
pygraph.add_subgraph(
name=name, label=name, cluster=True, labelloc="t", fontcolor="blue"
)
Expand All @@ -46,11 +48,16 @@ def _compose_and_draw_inner(self, pygraph: AGraph, flow: TokenSequence, name: st

def draw_epc(self, file_format: list[FileFormat]):
cluster = Cluster()
cluster.extract_flows(file_name_list=[file.input_path for file in file_format])
cluster.extract_flows(
file_name_list=[file.input_path for file in file_format]
)

for index, process in enumerate(cluster._main_flows):
main_flows = [flow.tokens for flow in cluster._main_flows]
for index, main_flow in enumerate(main_flows):
G = AGraph(directed=True, compound=True)
current_main_process = self._compose_and_draw(pygraph=G, flow=process)
current_main_process = self._compose_and_draw(
pygraph=G, flow=main_flow
)
inner_flows = [
flow
for flow in cluster._inner_flows
Expand All @@ -63,6 +70,9 @@ def draw_epc(self, file_format: list[FileFormat]):

file = file_format[index]
G.layout()
G.draw(file.output_path, prog="dot")
G.draw(
f"./_outputs/{cluster._main_flows[index].name}.png",
prog="dot",
)

log.info("Done.")
log.info(msg=f"{file.output_path} - Done.")
39 changes: 36 additions & 3 deletions clusterer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Flows:

class Cluster:
_inner_flows: list[Flow] = []
_main_flows: list[str] = []
_main_flows: list[Flow] = []

def __init__(self) -> None:
pass
Expand All @@ -45,12 +45,35 @@ def _find_inner_diagrams(self, token: str, index: int, flows: Flows):
if flows.latest_flow is not None:
flows.latest_flow.tokens.append(token)

# TODO refactor repeated functionality
def _find_main_flows(self, token: str, index: int, flows: Flows):
if ClusterKeywords.MAIN_CLUSTER in token:
flow = deepcopy(Flow())
flow.name = (
re.search(
rf"(?<={ClusterKeywords.MAIN_CLUSTER})(.*?)$", token
)[0]
.lstrip()
.rstrip()
)
flows.latest_flow = deepcopy(flow)
flows.processed_indexes.update({"start_index": index})

elif ClusterKeywords.END_MAIN_CLUSTER in token:
self._main_flows.append(deepcopy(flows.latest_flow))
flows.processed_indexes.update({"end_index": index})
flows.latest_flow = None
return True

if flows.latest_flow is not None:
flows.latest_flow.tokens.append(token)

def extract_flows(self, file_name_list: list[str]):
for file in file_name_list:
parser = Parser()
parsed = parser.parse(file)
flows = Flows()

flows = Flows()
for index, token_raw in enumerate(parsed):
indexes_processed = self._find_inner_diagrams(
str(token_raw), index, flows
Expand All @@ -62,4 +85,14 @@ def extract_flows(self, file_name_list: list[str]):

del parsed[start_index:end_index]

self._main_flows.append(parsed)
main_flows = Flows()
for index, token_raw in enumerate(parsed):
indexes_processed = self._find_main_flows(
str(token_raw), index, main_flows
)

if indexes_processed:
start_index = main_flows.processed_indexes["start_index"]
end_index = main_flows.processed_indexes["end_index"] + 1

del parsed[start_index:end_index]
2 changes: 2 additions & 0 deletions settings/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ClusterKeywords(StringEnum):
CLUSTER = "inner-diagram:"
END_CLUSTER = "end-diagram:"
INNER_FLOW = "inner-flow:"
MAIN_CLUSTER = "main-diagram:"
END_MAIN_CLUSTER = "end-diagram-main:"


NODE_KEYWORDS = [
Expand Down
Loading