Skip to content

Commit

Permalink
♻️ add typing where it makes sense and make some methods static
Browse files Browse the repository at this point in the history
  • Loading branch information
soeren227 committed May 24, 2024
1 parent 0563412 commit 8dd58bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions tracex_project/extraction/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Admin file for extraction app."""
from django.contrib import admin
from typing import Union
from extraction.models import Event, PatientJourney, Prompt, Trace, Cohort, Metric


Expand Down Expand Up @@ -60,15 +61,18 @@ class EventInline(admin.TabularInline):
"metrics_correctness_confidence",
)

def metrics_activity_relevance(self, obj):
@staticmethod
def metrics_activity_relevance(obj: Event) -> Union[str, int]:
"""Returns the activity relevance metric for the event."""
return obj.metrics.activity_relevance if hasattr(obj, "metrics") else "-"

def metrics_timestamp_correctness(self, obj):
@staticmethod
def metrics_timestamp_correctness(obj: Event) -> Union[str, int]:
"""Returns the timestamp correctness metric for the event."""
return obj.metrics.timestamp_correctness if hasattr(obj, "metrics") else "-"

def metrics_correctness_confidence(self, obj):
@staticmethod
def metrics_correctness_confidence(obj: Event) -> Union[str, int]:
"""Returns the correctness confidence metric for the event."""
return obj.metrics.correctness_confidence if hasattr(obj, "metrics") else "-"

Expand Down
3 changes: 2 additions & 1 deletion tracex_project/extraction/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Implementation of forms for the extraction app."""
from django import forms
from typing import List, Tuple

from extraction.models import PatientJourney
from tracex.forms import BaseEventForm
Expand Down Expand Up @@ -59,7 +60,7 @@ def __init__(self, *args, **kwargs):
].choices = self.get_patient_journey_choices()

@staticmethod
def get_patient_journey_choices():
def get_patient_journey_choices() -> List[Tuple[str, str]]:
"""Returns a list of tuples containing the names of all patient journeys from the database."""
patient_journeys = PatientJourney.manager.all()
choices = [
Expand Down
7 changes: 5 additions & 2 deletions tracex_project/extraction/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# pylint: disable=unused-argument, unused-variable

import pandas as pd
from typing import Dict, List

from django.urls import reverse_lazy
from django.views import generic
Expand Down Expand Up @@ -273,7 +274,7 @@ def get_context_data(self, **kwargs):
return context

@staticmethod
def build_trace_df(filter_dict):
def build_trace_df(filter_dict: Dict[str, List[str]]) -> pd.DataFrame:
"""Build the trace dataframe based on the filter settings."""
trace_df = Orchestrator.get_instance().get_data()
trace_df_filtered = utils.DataFrameUtilities.filter_dataframe(
Expand All @@ -286,7 +287,9 @@ def build_trace_df(filter_dict):
return trace_df_filtered

@staticmethod
def build_event_log_df(filter_dict, trace):
def build_event_log_df(
filter_dict: Dict[str, List[str]], trace: pd.DataFrame
) -> pd.DataFrame:
"""Build the event log dataframe based on the filter settings."""
event_log_df = utils.DataFrameUtilities.get_events_df()

Expand Down

0 comments on commit 8dd58bd

Please sign in to comment.