Skip to content

Commit

Permalink
update for final presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
PitButtchereit committed Jun 16, 2024
1 parent 5c07d2e commit 1a61381
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions tracex_project/trace_comparator/comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]] = []
Expand All @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 1a61381

Please sign in to comment.