feat: Implement dose calculation fix and enhance legend feature
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled

- Fixed dose calculation logic in `_calculate_daily_dose` to correctly parse timestamps with multiple colons.
- Added comprehensive test cases for various dose formats and edge cases in `test_dose_calculation.py`.
- Enhanced graph legend to display individual medicines with average dosages and track medicines without dose data.
- Updated legend styling and positioning for better readability and organization.
- Created new tests for enhanced legend functionality, including handling of medicines with and without data.
- Improved mocking for matplotlib components in tests to prevent TypeErrors.
This commit is contained in:
William Valentin
2025-07-30 14:22:07 -07:00
parent d14d19e7d9
commit b76191d66d
12 changed files with 1042 additions and 68 deletions

View File

@@ -89,3 +89,33 @@ def sample_dose_data():
'nan_value': 'nan', # Should be 0
'no_units': '2025-07-28 18:59:45:10|2025-07-28 19:34:19:5', # Should sum to 15
}
@pytest.fixture
def legend_test_dataframe():
"""DataFrame specifically designed for testing legend functionality."""
return pd.DataFrame({
'date': ['2024-01-01', '2024-01-02', '2024-01-03'],
'depression': [3, 2, 4],
'anxiety': [2, 3, 1],
'sleep': [4, 3, 5],
'appetite': [3, 4, 2],
# Medicine with consistent doses for average testing
'bupropion': [1, 1, 1],
'bupropion_doses': ['2024-01-01 08:00:00:100mg',
'2024-01-02 08:00:00:200mg',
'2024-01-03 08:00:00:150mg'], # Average: 150mg
# Medicine with varying doses
'propranolol': [1, 1, 0],
'propranolol_doses': ['2024-01-01 12:00:00:10mg',
'2024-01-02 12:00:00:20mg',
''], # Average: 15mg (10+20)/2
# Medicines without dose data
'hydroxyzine': [0, 0, 0],
'hydroxyzine_doses': ['', '', ''],
'gabapentin': [0, 0, 0],
'gabapentin_doses': ['', '', ''],
'quetiapine': [0, 0, 0],
'quetiapine_doses': ['', '', ''],
'note': ['Test note 1', 'Test note 2', 'Test note 3']
})