diff --git a/tracex_project/extraction/views.py b/tracex_project/extraction/views.py index 2fea72a..2201854 100644 --- a/tracex_project/extraction/views.py +++ b/tracex_project/extraction/views.py @@ -164,7 +164,8 @@ def form_valid(self, form): self.request.session["selected_modules"] = selected_modules if self.request.session.get("is_comparing") is True: - orchestrator.save_results_to_db() + if not TEST_MODE: + orchestrator.save_results_to_db() return redirect(reverse_lazy("testing_comparison")) diff --git a/tracex_project/trace_comparator/comparator.py b/tracex_project/trace_comparator/comparator.py index 0816a76..6c4a66b 100644 --- a/tracex_project/trace_comparator/comparator.py +++ b/tracex_project/trace_comparator/comparator.py @@ -21,29 +21,99 @@ def compare_traces( has no match as 'unexpected'. Finally, determine activities from the pipeline that are correctly matched but in the wrong order. """ - pipeline_activities: pd.Series = pipeline_df["activity"] - ground_truth_activities: pd.Series = ground_truth_df["activity"] - - ( - mapping_pipeline_to_ground_truth, - mapping_ground_truth_to_pipeline, - ) = find_activity_mapping(view, pipeline_activities, ground_truth_activities) - missing_activities: List[str] = find_unmapped_activities( - ground_truth_activities, mapping_ground_truth_to_pipeline - ) - unexpected_activities: List[str] = find_unmapped_activities( - pipeline_activities, mapping_pipeline_to_ground_truth - ) - wrong_orders: List[Tuple[str, str]] = find_wrong_orders( - pipeline_activities, mapping_ground_truth_to_pipeline - ) + if c.TEST_MODE: + simulate_progress(view) + + mapping_pipeline_to_ground_truth = [ + 0, + -1, + -1, + 5, + 4, + 5, + 7, + -1, + 8, + 7, + -1, + -1, + -1, + -1, + 15, + 15, + ] + mapping_ground_truth_to_pipeline = [ + 0, + -1, + -1, + 5, + 4, + 3, + 5, + 6, + 8, + 8, + -1, + -1, + 14, + 14, + -1, + 14, + 14, + ] + missing_activities = [ + "isolating myself", + "informing family", + "experiencing slow recovery", + "returning to work with precautions", + "remainding optimistic and adhering to safety guidelines", + ] + unexpected_activities = [ + "taking immediate action", + "isolating and informing family", + "receiving doctor's recommendations for treatment", + "receiving support from children", + "slowly recovering from infection", + "returning to work with precautions", + "improvement in Covid-19 situation", + "receiving first dose of vaccine", + ] + wrong_orders = [ + ("getting tested for Covid-19", "worsening symptoms and consulting doctor"), + ("getting tested for Covid-19", "facing financial difficulties"), + ( + "worsening symptoms and consulting doctor", + "facing financial difficulties", + ), + ] + matching_percent_ground_truth_to_pipeline = 62 + matching_percent_pipeline_to_ground_truth = 72 + + + else: + pipeline_activities: pd.Series = pipeline_df["activity"] + ground_truth_activities: pd.Series = ground_truth_df["activity"] + + ( + mapping_pipeline_to_ground_truth, + mapping_ground_truth_to_pipeline, + ) = find_activity_mapping(view, pipeline_activities, ground_truth_activities) + missing_activities: List[str] = find_unmapped_activities( + ground_truth_activities, mapping_ground_truth_to_pipeline + ) + unexpected_activities: List[str] = find_unmapped_activities( + pipeline_activities, mapping_pipeline_to_ground_truth + ) + wrong_orders: List[Tuple[str, str]] = find_wrong_orders( + pipeline_activities, mapping_ground_truth_to_pipeline + ) - matching_percent_pipeline_to_ground_truth: int = find_matching_percentage( - pipeline_activities, mapping_pipeline_to_ground_truth - ) - matching_percent_ground_truth_to_pipeline: int = find_matching_percentage( - ground_truth_activities, mapping_ground_truth_to_pipeline - ) + matching_percent_pipeline_to_ground_truth: int = find_matching_percentage( + pipeline_activities, mapping_pipeline_to_ground_truth + ) + matching_percent_ground_truth_to_pipeline: int = find_matching_percentage( + ground_truth_activities, mapping_ground_truth_to_pipeline + ) results: dict = { "mapping_pipeline_to_ground_truth": mapping_pipeline_to_ground_truth, @@ -57,6 +127,21 @@ def compare_traces( return results +def simulate_progress(view): + count = 0 + while count <= 50: + count += 5 + time.sleep(1) + update_progress( + view, count, 100, "Mapping Pipeline Activites to Ground Truth Activites" + ) + + while count <= 100: + count += 5 + time.sleep(1) + update_progress( + view, count, 100, "Mapping Ground Truth Activites to Pipeline Activites" + ) def find_activity_mapping( view, pipeline_activities: pd.Series, ground_truth_activities: pd.Series diff --git a/tracex_project/trace_comparator/views.py b/tracex_project/trace_comparator/views.py index cf5fa7c..b0dd2bc 100644 --- a/tracex_project/trace_comparator/views.py +++ b/tracex_project/trace_comparator/views.py @@ -16,7 +16,7 @@ from trace_comparator.comparator import compare_traces from trace_comparator.forms import PatientJourneySelectForm from tracex.logic.utils import DataFrameUtilities, Conversion - +from tracex.logic.constants import TEST_MODE class TraceComparisonMixin(View): """Mixin providing functionality that is used in multiple views in the trace comparator app.""" @@ -74,7 +74,10 @@ class TraceTestingComparisonView(TemplateView, TraceComparisonMixin): def get_context_data(self, **kwargs): """Prepare the latest trace of the selected Patient Journey that is available in the database for display.""" context = super().get_context_data(**kwargs) - patient_journey_name: str = self.request.session.get("patient_journey_name") + if TEST_MODE: + patient_journey_name = "journey_comparison_1" + else: + patient_journey_name: str = self.request.session.get("patient_journey_name") patient_journey: str = PatientJourney.manager.get( name=patient_journey_name ).patient_journey @@ -115,10 +118,15 @@ def get(self, request, *args, **kwargs): def post(self, request): """Compare the newest trace of a Patient Journey against the ground truth and update session with results.""" - patient_journey_name: str = self.request.session.get("patient_journey_name") - ground_truth_df, pipeline_df = self.get_first_and_last_trace( - patient_journey_name - ) + if not TEST_MODE: + patient_journey_name: str = self.request.session.get("patient_journey_name") + ground_truth_df, pipeline_df = self.get_first_and_last_trace( + patient_journey_name + ) + + else: + pipeline_df = [] + ground_truth_df = [] try: comparison_result_dict: dict = compare_traces(