Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
🔥 add Pits suggestions

Co-authored-by: Pit Buttchereit <[email protected]>
  • Loading branch information
nils-schmitt and PitButtchereit authored May 24, 2024
1 parent 1c0c2ae commit f6f12cc
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions tracex_project/extraction/logic/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def execute(
Executes the logic of the module. Override this to define your own module.
Keyword arguments:
_input -- Any additional input to the module
patient_journey -- The patient journey as text
patient_journey_sentences -- The same patient journey as a list of sentences
_input -- Any additional input to the module.
patient_journey -- The patient journey as text.
patient_journey_sentences -- The same patient journey as a list of sentences.
"""
self.patient_journey = patient_journey
self.patient_journey_sentences = patient_journey_sentences
Expand All @@ -57,8 +57,8 @@ def execute_and_save(
Executes the logic of the module and saves the result to the database. Override this to define your own module.
Keyword arguments:
patient_journey -- The patient journey as text
patient_journey_sentences -- The same patient journey as a list of sentences
patient_journey -- The patient journey as text.
patient_journey_sentences -- The same patient journey as a list of sentences.
"""
self.patient_journey = patient_journey
self.patient_journey_sentences = patient_journey_sentences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def execute(
patient_journey: str = None,
patient_journey_sentences: List[str] = None,
cohort=None,
):
) -> pd.DataFrame:
"""
Extracts the activity labels from the patient journey with the following steps:
1. Number the patient journey sentences to enable selecting a specific range of sentences.
Expand All @@ -45,7 +45,7 @@ def execute(
patient_journey_numbered: str = self.__number_patient_journey_sentences(
patient_journey_sentences
)
activity_labels = self.__extract_activities(patient_journey_numbered, condition)
activity_labels: pd.DataFrame = self.__extract_activities(patient_journey_numbered, condition)

return activity_labels

Expand All @@ -65,7 +65,7 @@ def __number_patient_journey_sentences(patient_journey_sentences: List[str]) ->
return patient_journey_numbered

@staticmethod
def __extract_activities(patient_journey_numbered: str, condition: Optional[str]):
def __extract_activities(patient_journey_numbered: str, condition: Optional[str]) -> pd.DataFrame:
"""
Converts a patient journey, where every sentence is numbered, to a DataFrame with the activity labels by
extracting the activity labels from the patient journey.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def execute(
patient_journey=None,
patient_journey_sentences=None,
cohort=None,
):
) -> pd.DataFrame:
"""Classifies corresponding event types for all activity labels in a dataframe."""
super().execute(
df,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def execute(
patient_journey=None,
patient_journey_sentences=None,
cohort=None,
):
) -> pd.DataFrame:
"""Extracts the location information for each activity in a dataframe."""
super().execute(
df,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def execute(
patient_journey=None,
patient_journey_sentences=None,
cohort=None,
):
) -> pd.DataFrame:
"""Measures the output of the pipeline based on specified metrics.
These metrics are 'activity relevance' and 'timestamp correctness'."""
super().execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def execute(
patient_journey=None,
patient_journey_sentences: List[str] = None,
cohort=None,
):
) -> pd.DataFrame:
"""This function extracts the time information from the patient journey.
For each activity label, the start date, end date and duration are extracted."""
super().execute(
Expand Down
2 changes: 1 addition & 1 deletion tracex_project/extraction/logic/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def initialize_modules(self):
}
return modules

def run(self, view=None):
def run(self, view=None) -> pd.DataFrame:
"""Run the modules and set default values for modules not executed."""
modules = self.initialize_modules()
execution_step: int = 1
Expand Down
4 changes: 2 additions & 2 deletions tracex_project/tracex/logic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def dataframe_to_xes(df, name, activity_key):
return file_path

@staticmethod
def text_to_sentence_list(text):
def text_to_sentence_list(text: str) -> List[str]:
"""Converts a text into a list of its sentences."""
text = text.replace("\n", " ")
# This regex looks for periods, question marks, or exclamation marks,
Expand Down Expand Up @@ -292,7 +292,7 @@ def set_default_timestamps(df):
df["time:duration"] = "00:01:00"

@staticmethod
def delete_metrics_columns(df: pd.DataFrame):
def delete_metrics_columns(df: pd.DataFrame) -> pd.DataFrame:
"""Delete metrics columns from the dataframe."""
df = df.drop(
columns=[
Expand Down

0 comments on commit f6f12cc

Please sign in to comment.