From 1a6138175e5ac1f1efb170d849d91e1447d3864a Mon Sep 17 00:00:00 2001 From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com> Date: Sun, 16 Jun 2024 21:17:50 +0200 Subject: [PATCH] update for final presentation --- tracex_project/trace_comparator/comparator.py | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tracex_project/trace_comparator/comparator.py b/tracex_project/trace_comparator/comparator.py index 68034d0..50319a6 100644 --- a/tracex_project/trace_comparator/comparator.py +++ b/tracex_project/trace_comparator/comparator.py @@ -12,7 +12,7 @@ @log_execution_time(Path(settings.BASE_DIR / "tracex/logs/execution_time.log")) def compare_traces( - view, pipeline_df: pd.DataFrame, ground_truth_df: pd.DataFrame + view, pipeline_df: pd.DataFrame, ground_truth_df: pd.DataFrame ) -> dict: """Executes the trace comparison. @@ -24,15 +24,14 @@ def compare_traces( if c.TEST_MODE: simulate_progress(view) - mapping_pipeline_to_ground_truth = [0, -1, -1, 2, 5, 4, 4, -1, -1, -1, 12, 13, 12, 15] - mapping_ground_truth_to_pipeline = [0, 4, 3, 5, 5, 4, -1, -1, -1, -1, -1, 13, 10, 11, -1, 13, 12, -1] - missing_activities = ['getting tested for covid 19 in local testing center', 'testing positive for covid 19', 'focusing on resting while isolated', 'receiving emotional support from family', 'experiencing slow recovery', 'remainding optimistic and adhering to safety guidelines', 'feeling thankful for healthcare personal'] - unexpected_activities = ['consulting doctor', 'getting tested for Covid-19', 'recovering with family support', 'returning to work with precautions', 'decision to get vaccinated'] - wrong_orders = [('advised home quarantine and treatment', 'receiving positive test results'), ('receiving care from family', 'advised home quarantine and treatment'), ('feeling relief and hope post-vaccination', 'receiving first dose of vaccine'), ('feeling relief and hope post-vaccination', 'experiencing mild side effects'), ('feeling relief and hope post-vaccination', 'receiving second dose of vaccine')] - matching_percent_ground_truth_to_pipeline = 64 - matching_percent_pipeline_to_ground_truth = 61 + mapping_pipeline_to_ground_truth = [0, -1, -1, 1, 12, 13, 16] + mapping_ground_truth_to_pipeline = [0, 3, -1, -1, -1, -1, -1, -1, 3, 3, -1, -1, 4, 5, -1, 6, 6, -1] + missing_activities = ['informing family', 'putting loved ones over financial worries', 'experiencing worse symptoms', 'consulting family physician', 'getting tested for covid 19 in local testing center', 'testing positive for covid 19', 'experiencing slow recovery', 'returning to work with precautions', 'remainding optimistic and adhering to safety guidelines', 'feeling thankful for healthcare personal'] + unexpected_activities = ['consulting doctor for worsening symptoms', 'getting tested for Covid-19'] + wrong_orders = [] + matching_percent_ground_truth_to_pipeline = 71 + matching_percent_pipeline_to_ground_truth = 44 - else: pipeline_activities: pd.Series = pipeline_df["activity"] ground_truth_activities: pd.Series = ground_truth_df["activity"] @@ -73,23 +72,24 @@ def compare_traces( 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" - ) + 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" + ) - 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 + view, pipeline_activities: pd.Series, ground_truth_activities: pd.Series ) -> Tuple[List[int], List[int]]: """Create a mapping of activities from the pipeline to the ground truth and vice versa.""" total_steps: int = len(pipeline_activities) + len(ground_truth_activities) @@ -123,12 +123,12 @@ def find_activity_mapping( def compare_activities( - view, - current_step: int, - total_steps: int, - status: str, - input_activities: pd.Series, - comparison_basis_activities: pd.Series, + view, + current_step: int, + total_steps: int, + status: str, + input_activities: pd.Series, + comparison_basis_activities: pd.Series, ) -> List[Tuple[int, float]]: """Compare input activities with ground truth activities.""" mapping_input_to_comparison: List[Tuple[int, float]] = [] @@ -147,10 +147,10 @@ def compare_activities( def find_activity( - activity, - comparison_basis_activities: pd.Series, - activity_index: int, - mapping_input_to_comparison: List[Tuple[int, float]], + activity, + comparison_basis_activities: pd.Series, + activity_index: int, + mapping_input_to_comparison: List[Tuple[int, float]], ) -> None: """Compares an activity against potential matches to identify the best match based on similarity. @@ -189,7 +189,7 @@ def find_activity( def postprocess_mappings( - mapping_data_to_ground_truth: List, mapping_ground_truth_to_data: List + mapping_data_to_ground_truth: List, mapping_ground_truth_to_data: List ) -> Tuple[List[int], List[int]]: """Postprocess the mappings between data and ground truth.""" mapping_data_to_ground_truth = fill_mapping( @@ -229,7 +229,7 @@ def remove_probabilities(mapping: List[Tuple[int, float]]) -> List[int]: def find_matching_percentage( - input_activities: pd.Series, mapping_input_to_comparison: list + input_activities: pd.Series, mapping_input_to_comparison: list ) -> int: """Calculate the percentage of matching activities.""" total_matching_activities: int = sum( @@ -252,7 +252,7 @@ def find_unmapped_activities(activities: pd.Series, mapping: list) -> List[str]: def find_wrong_orders( - df_activities: pd.Series, mapping_ground_truth_to_data: List[int] + df_activities: pd.Series, mapping_ground_truth_to_data: List[int] ) -> List[Tuple[str, str]]: """Find the activities that are in the wrong order. @@ -270,8 +270,8 @@ def find_wrong_orders( continue if first_activity_index > second_activity_index: if not any( - pair == (first_activity_index, second_activity_index) - for pair in wrong_orders_indices + pair == (first_activity_index, second_activity_index) + for pair in wrong_orders_indices ): wrong_orders_indices.append( (first_activity_index, second_activity_index)