feat: Add tests for verifying multiple dose functionality and CSV saving
This commit is contained in:
104
test_dose_verification.py
Normal file
104
test_dose_verification.py
Normal file
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to verify dose saving functionality by examining CSV data.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def verify_dose_saving():
|
||||
"""Verify that multiple doses are being saved correctly."""
|
||||
|
||||
# Read the CSV data
|
||||
try:
|
||||
df = pd.read_csv("thechart_data.csv")
|
||||
print("📊 Examining CSV data for dose entries...")
|
||||
print(f" Total entries: {len(df)}")
|
||||
|
||||
# Check for dose columns
|
||||
dose_columns = [col for col in df.columns if col.endswith("_doses")]
|
||||
print(f" Dose columns found: {dose_columns}")
|
||||
|
||||
# Look for entries with multiple doses
|
||||
entries_with_doses = 0
|
||||
entries_with_multiple_doses = 0
|
||||
|
||||
for _, row in df.iterrows():
|
||||
row_has_doses = False
|
||||
row_has_multiple = False
|
||||
|
||||
for dose_col in dose_columns:
|
||||
dose_data = str(row[dose_col])
|
||||
if dose_data and dose_data != "nan" and dose_data.strip():
|
||||
row_has_doses = True
|
||||
# Count doses (separated by |)
|
||||
dose_count = len(dose_data.split("|"))
|
||||
medicine_name = dose_col.replace("_doses", "")
|
||||
|
||||
print(f" {row['date']} - {medicine_name}: {dose_count} dose(s)")
|
||||
if dose_count > 1:
|
||||
row_has_multiple = True
|
||||
print(f" → Multiple doses: {dose_data}")
|
||||
|
||||
if row_has_doses:
|
||||
entries_with_doses += 1
|
||||
if row_has_multiple:
|
||||
entries_with_multiple_doses += 1
|
||||
|
||||
print("\n📈 Summary:")
|
||||
print(f" Entries with doses: {entries_with_doses}")
|
||||
print(f" Entries with multiple doses: {entries_with_multiple_doses}")
|
||||
|
||||
if entries_with_multiple_doses > 0:
|
||||
print("✅ Multiple dose saving IS working!")
|
||||
return True
|
||||
else:
|
||||
print("⚠️ No multiple dose entries found")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error reading CSV: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def check_latest_entry():
|
||||
"""Check the most recent entry for dose data."""
|
||||
try:
|
||||
df = pd.read_csv("thechart_data.csv")
|
||||
latest = df.iloc[-1]
|
||||
|
||||
print(f"\n🔍 Latest entry ({latest['date']}):")
|
||||
dose_columns = [col for col in df.columns if col.endswith("_doses")]
|
||||
|
||||
for dose_col in dose_columns:
|
||||
medicine = dose_col.replace("_doses", "")
|
||||
dose_data = str(latest[dose_col])
|
||||
|
||||
if dose_data and dose_data != "nan" and dose_data.strip():
|
||||
dose_count = len(dose_data.split("|"))
|
||||
print(f" {medicine}: {dose_count} dose(s) - {dose_data}")
|
||||
else:
|
||||
print(f" {medicine}: No doses")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error checking latest entry: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🔬 Dose Verification Test")
|
||||
print("=" * 30)
|
||||
|
||||
# Change to the directory containing the CSV
|
||||
os.chdir("/home/will/Code/thechart")
|
||||
|
||||
success = verify_dose_saving()
|
||||
check_latest_entry()
|
||||
|
||||
if success:
|
||||
print("\n✅ Multiple dose functionality is working correctly!")
|
||||
else:
|
||||
print("\n❌ Multiple dose functionality needs investigation")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user