From a76c85f10943027d4a8bbdc6f4336886cb2bc769 Mon Sep 17 00:00:00 2001 From: Kien Date: Fri, 7 Jun 2024 01:14:34 +0200 Subject: [PATCH] added test mode for extraction --- .../extraction/logic/orchestrator.py | 11 ++++++++ tracex_project/extraction/views.py | 25 +++++++++++++++---- tracex_project/tracex/logic/constants.py | 2 ++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/tracex_project/extraction/logic/orchestrator.py b/tracex_project/extraction/logic/orchestrator.py index d94c633..a140640 100644 --- a/tracex_project/extraction/logic/orchestrator.py +++ b/tracex_project/extraction/logic/orchestrator.py @@ -10,6 +10,7 @@ from django.utils.dateparse import parse_duration from django.core.exceptions import ObjectDoesNotExist import pandas as pd +import time from extraction.logic.modules import ( Preprocessor, @@ -276,3 +277,13 @@ def update_progress(self, view, execution_step: int, module_name: str) -> None: view.request.session["progress"] = percentage view.request.session["status"] = module_name view.request.session.save() + + def simulate_extraction(self, view): + """Simulate the progress of the extraction process.""" + for current_step, current_module in enumerate( + self.configuration.modules, start=1 + ): + self.update_progress( + view, current_step, self.configuration.modules[current_module]().name + ) + time.sleep(1) \ No newline at end of file diff --git a/tracex_project/extraction/views.py b/tracex_project/extraction/views.py index b952410..2fea72a 100644 --- a/tracex_project/extraction/views.py +++ b/tracex_project/extraction/views.py @@ -9,7 +9,8 @@ # pylint: disable=unused-argument, unused-variable import pandas as pd - +from tracex.logic.constants import TEST_MODE +from django.db.models import Q from django.urls import reverse_lazy from django.views import generic from django.http import JsonResponse @@ -22,7 +23,7 @@ JourneySelectForm, ) from extraction.logic.orchestrator import Orchestrator, ExtractionConfiguration -from extraction.models import PatientJourney +from extraction.models import PatientJourney, Trace from tracex.views import DownloadXesView from tracex.logic import utils @@ -143,7 +144,10 @@ def form_valid(self, form): ) orchestrator.reduce_modules_to(modules_list) try: - orchestrator.run(view=self) + if TEST_MODE: + orchestrator.simulate_extraction(view=self) + else: + orchestrator.run(view=self) except Exception as e: # pylint: disable=broad-except orchestrator.reset_instance() self.request.session.flush() @@ -243,7 +247,17 @@ def get_context_data(self, **kwargs): "attribute_location": orchestrator.get_configuration().locations, } - trace = self.build_trace_df(filter_dict) + if TEST_MODE: + patient_journey_name = "Synthetic journey 1" + query_last_trace = Q( + id=Trace.manager.filter(patient_journey__name=patient_journey_name) + .latest("last_modified") + .id + ) + trace = utils.DataFrameUtilities.get_events_df(query_last_trace) + print(trace) + else: + trace = self.build_trace_df(filter_dict) event_log = self.build_event_log_df(filter_dict, trace) form = self.get_form() @@ -334,7 +348,8 @@ def get_context_data(self, **kwargs): """Prepare and return the context data for the save success page.""" context = super().get_context_data(**kwargs) orchestrator = Orchestrator.get_instance() - orchestrator.save_results_to_db() + if not TEST_MODE: + orchestrator.save_results_to_db() return context diff --git a/tracex_project/tracex/logic/constants.py b/tracex_project/tracex/logic/constants.py index 7ada56b..5a00f04 100644 --- a/tracex_project/tracex/logic/constants.py +++ b/tracex_project/tracex/logic/constants.py @@ -132,3 +132,5 @@ SNOMED_CT_HEADERS = { "User-Agent": "browser", } + +TEST_MODE = True \ No newline at end of file