Skip to content

Commit

Permalink
added test mode for extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
tkv29 committed Jun 6, 2024
1 parent a9eb6f2 commit a76c85f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
11 changes: 11 additions & 0 deletions tracex_project/extraction/logic/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
25 changes: 20 additions & 5 deletions tracex_project/extraction/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tracex_project/tracex/logic/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@
SNOMED_CT_HEADERS = {
"User-Agent": "browser",
}

TEST_MODE = True

0 comments on commit a76c85f

Please sign in to comment.