Skip to content

Commit

Permalink
♻️ apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
FR-SON committed May 25, 2024
1 parent 4aebf41 commit 3f5d28d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
23 changes: 13 additions & 10 deletions tracex_project/trace_comparator/comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@


@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):
def compare_traces(
view, pipeline_df: pd.DataFrame, ground_truth_df: pd.DataFrame
) -> dict:
"""Executes the trace comparison.
Compare the piepline output to the ground truth and determine all matching activities.Classify every activity
Expand Down Expand Up @@ -96,15 +98,15 @@ def compare_activities(
total_steps: int,
status: str,
input_activities: pd.Series,
ground_truth_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]] = []
for index, activity in enumerate(input_activities):
update_progress(view, current_step, total_steps, status)
find_activity(
activity,
ground_truth_activities,
comparison_basis_activities,
index,
mapping_input_to_comparison,
)
Expand All @@ -116,7 +118,7 @@ def compare_activities(

def find_activity(
activity,
ground_truth_activities: pd.Series,
comparison_basis_activities: pd.Series,
activity_index: int,
mapping_input_to_comparison: List[Tuple[int, float]],
) -> None:
Expand All @@ -127,9 +129,11 @@ def find_activity(
certain range. For instance, an activity with index 5 ist compared to activities 3-7 from the ground truth. Both
activities are sent to the GPT model to determine if they are semantically similar.
"""
lower, upper = u.get_snippet_bounds(activity_index, len(ground_truth_activities))
lower, upper = u.get_snippet_bounds(
activity_index, len(comparison_basis_activities)
)
possible_matches: List[Tuple[int, float]] = []
for count, second_activity in enumerate(ground_truth_activities[lower:upper]):
for count, second_activity in enumerate(comparison_basis_activities[lower:upper]):
messages = Prompt.objects.get(name="COMPARE_MESSAGES").text
messages.append(
{
Expand All @@ -149,6 +153,7 @@ def find_activity(
for index, prob in possible_matches
if prob > c.THRESHOLD_FOR_MATCH
),
key=lambda x: x[1],
default=(-1, 0),
)
)
Expand All @@ -171,10 +176,8 @@ def postprocess_mappings(


def fill_mapping(mapping_back_to_forth: List, mapping_forth_to_back: List) -> List:
"""Fill the missing mappings using the reverse mapping.
Fills up missing mappings using the reverse mapping and updates existing mappings, if ones with higher
probabilities are found. If an activity has no mapping on either side, it is left as is.
"""Fill up missing mappings using the reverse mapping and updates existing mappings, if ones with higher
probabilities are found. If an activity has no mapping on either side, leave it as is.
"""
for index_forth, activity_index_forth in enumerate(mapping_back_to_forth):
if activity_index_forth[0] == -1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="container">
<h1>Extraction Result</h1>

<h2>Patient Journey: {{ patient_journey_name }}</h2>
<h3>Patient Journey: {{ patient_journey_name }}</h3>
<p>{{ patient_journey }}</p>
<p><b>This is the event log extracted from the journey above</b></p>
<div id="xesContent" class="xes_container">
Expand All @@ -35,6 +35,11 @@ <h2>Patient Journey: {{ patient_journey_name }}</h2>
{% csrf_token %}
<button type="submit" class="menu_button" id="progress_button">Start Comparing Against Ground Truth</button>
</form>
<script>
function disableButton() {
document.getElementById("progress_button").classList.add("processing");
}
</script>

<a href="{% url 'testing_environment' %}">
<button class="menu_button">Return to Trace Testing Environment</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<script src="{% static '/trace_comparator/js/dashboard.js' %}" defer></script>
</head>
<body class="main_body">
<h2>Trace Comparison Results ({{patient_journey_name}})</h2>
<h1>Trace Comparison Results</h1>

<h2>Patient Journey: {{ patient_journey_name }}</h2>
<div class="dashboard">
<div class="row">
<div class="metric-tile">
Expand Down
12 changes: 7 additions & 5 deletions tracex_project/trace_comparator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ def get_context_data(self, **kwargs):
.id
)
pipeline_df: pd.DataFrame = DataFrameUtilities.get_events_df(query_last_trace)
pipeline_df: pd.DataFrame = DataFrameUtilities.delete_metrics_columns(
pipeline_df
)

context.update(
{
"patient_journey_name": patient_journey_name,
"patient_journey": patient_journey,
"pipeline_output": Conversion.create_html_table_from_df(pipeline_df),
"pipeline_output": Conversion.create_html_table_from_df(
DataFrameUtilities.delete_metrics_columns(pipeline_df)
),
}
)

Expand Down Expand Up @@ -213,7 +213,9 @@ def __build_context_update(
"patient_journey": PatientJourney.manager.get(
name=patient_journey_name
).patient_journey,
"pipeline_output": Conversion.create_html_table_from_df(pipeline_df),
"pipeline_output": Conversion.create_html_table_from_df(
DataFrameUtilities.delete_metrics_columns(pipeline_df)
),
"ground_truth_output": Conversion.create_html_table_from_df(
DataFrameUtilities.delete_metrics_columns(ground_truth_df)
),
Expand Down

0 comments on commit 3f5d28d

Please sign in to comment.