Skip to content

Commit

Permalink
♻️ merge main into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
PitButtchereit committed May 24, 2024
2 parents e08f78f + 07c3f25 commit 5a283e4
Show file tree
Hide file tree
Showing 11 changed files with 4,399 additions and 176 deletions.
Binary file modified tracex_project/db.sqlite3
Binary file not shown.
8 changes: 4 additions & 4 deletions tracex_project/db_results/templates/evaluation.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1 style="text-align: center">Evaluation View</h1>

<!-- Display complete event log -->
<div>
<button id="toggleButton1">Show/Hide Event Log with applied filters</button>
<button id="toggleButton1" class="function_button">Show/Hide Event Log with applied filters</button>
<div id="contentWrapper1" style="display: none;">
{% if event_log_table %}
<p></p>
Expand All @@ -31,7 +31,7 @@ <h1 style="text-align: center">Evaluation View</h1>
</div>

<div>
<button id="toggleButton2" style="margin-top: 1em">Show/Hide Cohorts belonging to remaining entries</button>
<button id="toggleButton2" class="function_button" style="margin-top: 1em">Show/Hide Cohorts belonging to remaining entries</button>
<div id="contentWrapper2" style="display: none;">
{% if cohorts_table %}
<p></p>
Expand Down Expand Up @@ -143,12 +143,12 @@ <h1 style="text-align: center">Evaluation View</h1>

{{ form.errors }}

<input type="submit" value="Refresh Filter" class="button">
<input type="submit" value="Refresh Filter" class="function_button">
</form>
<br>

<!-- Trigger/Open The Modal (XES Download) -->
<button id="downloadBtn" class="button">Download XES File</button>
<button id="downloadBtn" class="function_button">Download XES File</button>
<div id="downloadModal" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
Expand Down
6 changes: 3 additions & 3 deletions tracex_project/extraction/fixtures/prompts_fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@
}
],
[
"gender",
"sex",
{
"role": "system",
"content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the gender of the author. If the gender isn't clear, you should take the context into account. Only if the context doesn't help, you should return 'N/A'."
"content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the sex of the author. If the sex isn't clear, you should take the context into account. Only if the context doesn't help, you should return 'N/A'."
},
{
"role": "user",
Expand Down Expand Up @@ -608,7 +608,7 @@
"age",
{
"role": "system",
"content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the age of the author. If the gender isn't clear, you should take the context into account. Young means 25, middle aged 50 and old 75. Only if the context doesn't help, you should return 'N/A'."
"content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the age of the author. If the sex isn't clear, you should take the context into account. Young means 25, middle aged 50 and old 75. Only if the context doesn't help, you should return 'N/A'."
},
{
"role": "user",
Expand Down
169 changes: 0 additions & 169 deletions tracex_project/extraction/tests.py

This file was deleted.

Empty file.
129 changes: 129 additions & 0 deletions tracex_project/extraction/tests/test_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"""Test cases for the modules in the extraction app."""
from django.test import TestCase
import pandas as pd

from extraction.logic.modules import (
ActivityLabeler,
TimeExtractor,
EventTypeClassifier,
LocationExtractor,
)


class ActivityLabelerTests(TestCase):
"""Test cases for the ActivityLabeler."""

fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]

def test_execute_return_value(self):
"""Test if the return value of the execute method is a DataFrame and if the column name is as expected."""
test_data = ["I fell ill yesterday.", "I went to the doctor today."]
activity_labeler = ActivityLabeler()
result = activity_labeler.execute(patient_journey_sentences=test_data)

self.assertIsInstance(result, pd.DataFrame)
self.assertIn("activity", result.columns)
self.assertIn("sentence_id", result.columns)


class TimeExtractorTests(TestCase):
"""Test cases for the TimeExtractor."""

fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]

def test_execute_return_value(self):
"""Test if the return value of the execute method is a DataFrame and if the column names are as expected."""
data = {"activity": ["fell ill"], "sentence_id": ["1"]}
patient_journey = ["I fell ill on June 5 and recovered on June 7."]
input_dataframe = pd.DataFrame(data)
time_extractor = TimeExtractor()
result = time_extractor.execute(
df=input_dataframe, patient_journey_sentences=patient_journey
)

self.assertIsInstance(result, pd.DataFrame)
self.assertIn("time:timestamp", result.columns)
self.assertIn("time:end_timestamp", result.columns)
self.assertIn("time:duration", result.columns)

def test_return_value_is_datetime(self):
"""Test if the returned DataFrame columns are of type datetime."""
data = {"activity": ["fell ill"], "sentence_id": ["1"]}
patient_journey = ["I fell ill on June 5 and recovered on June 7."]
input_dataframe = pd.DataFrame(data)
time_extractor = TimeExtractor()
result = time_extractor.execute(
df=input_dataframe, patient_journey_sentences=patient_journey
)

self.assertTrue((result["time:timestamp"].apply(lambda x: isinstance(x, pd.Timestamp))).all())
self.assertTrue((result["time:end_timestamp"].apply(lambda x: isinstance(x, pd.Timestamp))).all())

def test_processing_downwards(self):
"""Test if the post-processing function is correctly applied to the DataFrame downwards."""
data = {"activity": ["fell ill", "had fever"], "sentence_id": ["1", "2"]}
patient_journey = ["I fell ill on June 5 and recovered on June 7. After that I had fever."]
input_dataframe = pd.DataFrame(data)
time_extractor = TimeExtractor()
result = time_extractor.execute(
df=input_dataframe, patient_journey_sentences=patient_journey
)

self.assertTrue((result["time:timestamp"].apply(lambda x: isinstance(x, pd.Timestamp))).all())
self.assertTrue((result["time:end_timestamp"].apply(lambda x: isinstance(x, pd.Timestamp))).all())

def test_post_processing_upwards(self):
"""Test if the post-processing function is correctly applied to the DataFrame upwards."""
data = {"activity": ["had fever", "fell ill",], "sentence_id": ["1", "2"]}
patient_journey = ["I had fever. After that I fell ill on June 5 and recovered on June 7."]
input_dataframe = pd.DataFrame(data)
time_extractor = TimeExtractor()
result = time_extractor.execute(
df=input_dataframe, patient_journey_sentences=patient_journey
)

self.assertTrue((result["time:timestamp"].apply(lambda x: isinstance(x, pd.Timestamp))).all())
self.assertTrue((result["time:end_timestamp"].apply(lambda x: isinstance(x, pd.Timestamp))).all())


class EventTypeClassifierTests(TestCase):
"""Test cases for the EventTypeClassifier."""

fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]

def test_execute_return_value(self):
"""Test if the return value of the execute method is a DataFrame and if the column name is as expected."""
test_data = {
"activity": "fell ill",
"time:timestamp": "20220601T0000",
"time:end_timestamp": "20220605T0000",
"time:duration": "96:00:00",
}
input_dataframe = pd.DataFrame([test_data])
event_type_classifier = EventTypeClassifier()
result = event_type_classifier.execute(input_dataframe)

self.assertIsInstance(result, pd.DataFrame)
self.assertIn("event_type", result.columns)


class LocationExtractorTests(TestCase):
"""Test cases for the LocationExtractor."""

fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]

def test_execute_return_value(self):
"""Test if the return value of the execute method is a DataFrame and if the column name is as expected."""
test_data = {
"activity": "fell ill",
"time:timestamp": "20220601T0000",
"time:end_timestamp": "20220605T0000",
"time:duration": "96:00:00",
"event_type": "Symptom Onset",
}
input_dataframe = pd.DataFrame([test_data])
location_extractor = LocationExtractor()
result = location_extractor.execute(input_dataframe)

self.assertIsInstance(result, pd.DataFrame)
self.assertIn("attribute_location", result.columns)
Loading

0 comments on commit 5a283e4

Please sign in to comment.