diff --git a/client.py b/client.py index 2fedd46..66b816a 100644 --- a/client.py +++ b/client.py @@ -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" ) @@ -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 @@ -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.") diff --git a/clusterer.py b/clusterer.py index be07126..2026d46 100644 --- a/clusterer.py +++ b/clusterer.py @@ -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 @@ -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 @@ -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] diff --git a/settings/language.py b/settings/language.py index 6bea77b..ceb6c55 100644 --- a/settings/language.py +++ b/settings/language.py @@ -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 = [