The LifeLytics backend now includes a complete data simulation and reporting system that generates realistic test users, simulates 30 days of health data, and creates insightful reports.
backend/services/simulationService.py- Core simulation engine
backend/routes/test.py- Test endpoints for simulation
test_simulation_direct.py- Unit tests (direct service calls)test_simulation_api.py- API endpoint verificationtest_simulation_integration.py- Full workflow integration test
backend/main.py- Added test router
generateTestUsers(n_users: int = 5) -> List[str]- Generates 5+ test users with diverse health profiles
- Profiles:
athlete,sedentary,diabetic-risk,active - Each user has:
- Unique user ID (format:
test_user_1,test_user_2, etc.) - Random height (1.5m - 1.9m)
- Random weight (50kg - 100kg)
- Baseline health characteristics per profile
- Unique user ID (format:
simulateMonthData(user_id: str) -> None- Generates realistic daily health metrics for 30 days
- For each day:
sleep: 4-9 hours (profile-dependent)steps: 1,000-12,000 steps (profile-dependent)glucose: 70-250 mg/dL (profile-dependent)heart_rate: 50-120 bpm (profile-dependent)
- Patterns are realistic:
- Athletes: high steps, stable glucose
- Sedentary: low steps, higher glucose
- Diabetic-risk: fluctuating glucose
- Random variations + trends simulate real behavior
saveInsightsToFile(user_id: str, insights: Dict) -> str- Saves insights to
.txtfiles - Format:
insights_<user_id>.txt - Content includes:
- User ID and timestamp
- Health Score (0-100)
- Insights (list)
- Risks (list)
- Recommendations (list)
generateSimulationReport(user_ids: List[str]) -> Dict- Generates summary report with:
- Number of users created
- Number of files generated
- Timestamp
- List of user IDs
POST /test/generate-data
- Creates 7 test users
- Simulates 30 days of data for each
- Generates insights and saves to files
- Response:
{ "users_created": 7, "files_generated": 7, "user_list": [...] }
GET /test/users
- Returns all test users with basic info
- Response:
{ "users": { "test_user_1": { "profile": "athlete", "height": 1.69, "weight": 77.7, "health_logs_count": 30, "created_at": "..." } }, "total_users": 7 }
GET /test/user/{user_id}
- Returns complete user data including:
- Profile info (height, weight, profile type)
- Summary statistics (average sleep, steps, glucose, HR)
- All 30 health logs with daily metrics
- Example Response:
{ "user_id": "test_user_1", "profile": "athlete", "height": 1.69, "weight": 77.7, "summary": { "avg_sleep": 7.1, "avg_steps": 12141, "avg_glucose": 84.0, "avg_heart_rate": 72, "total_days": 30 }, "health_logs": [...] }
GET /test/user/{user_id}/insights
- Generates insights based on user's 30-day data
- Returns health score, insights, risks, recommendations
✓ User generation: 5 users created successfully
✓ 30-day data simulation: realistic patterns generated
✓ Insight file creation: 3 files saved successfully
✓ Report generation: summary created
✓ File cleanup: test files removed
✓ GET /test/users: returns all test users (200)
✓ POST /test/generate-data: generates 7 users (200)
✓ GET /test/user/test_user_1: returns user data (200)
- Profile: athlete
- Height: 1.69m, Weight: 77.7kg
- Avg Sleep: 7.1 hours
- Avg Steps: 12,141 steps/day
- Avg Glucose: 84.0 mg/dL
- Avg Heart Rate: 72 bpm
Day 1: Sleep=7.6h, Steps=12,822, Glucose=90.8, HR=79
Day 2: Sleep=5.9h, Steps=9,309, Glucose=70.6, HR=58
...30 days total with realistic variation
backend/
├── services/
│ └── simulationService.py # Data generation & reporting
├── routes/
│ └── test.py # API endpoints (4 routes)
├── main.py # Router registration
└── database.py # In-memory storage
Data Flow:
generateTestUsers()
→ creates user profiles in database
simulateMonthData()
→ generates 30 daily metrics per user
generateInsights()
→ analyzes data for insights/risks
saveInsightsToFile()
→ saves to insights_<user_id>.txt
-
Profile-Based Realism
- Each profile has baseline health characteristics
- Data varies realistically within profile constraints
- Trends and random variation simulate real patterns
-
Modular Services
- Simulation service fully decoupled from routes
- Can be used independently or via API
- Easy to extend with new profile types
-
In-Memory Persistence
- Uses existing database module
- Structured like Firestore for future migration
- Ready for real DB integration
-
File Export
- Generates human-readable
.txtreports - One file per user with full insights
- Easy to batch-import or archive
- Generates human-readable
-
Comprehensive Testing
- Unit tests (direct service calls)
- API tests (endpoint verification)
- Integration tests (full workflow)
# Start server
uvicorn backend.main:app --reload --port 8000
# Generate all test data
curl -X POST http://localhost:8000/test/generate-data
# Get specific user data
curl http://localhost:8000/test/user/test_user_1
# View in Swagger
open http://localhost:8000/docsfrom backend.services import simulationService
from backend.database import getUserData
# Generate users
user_ids = simulationService.generateTestUsers(5)
# Simulate data
for uid in user_ids:
simulationService.simulateMonthData(uid)
# Get user data
user = getUserData("test_user_1")
print(user["healthLogs"]) # 30 days of data-
Profile Enhancement
- Add more health conditions (hypertension, asthma, etc.)
- Allow custom baseline values
- Add realistic seasonal variations
-
Data Variety
- Generate multiple months of data
- Add anomalies/events (illness, exercise spike)
- Support different data intervals
-
Insights Enhancement
- Cache insights for faster response
- Add LLM-powered analysis
- Generate trend reports
-
Frontend Integration
- Create dashboard to visualize test data
- Show insight reports
- Compare user profiles
✅ Production Ready for Testing
- All endpoints functional
- Realistic data generation
- Proper error handling
- Fully tested and documented
Ready for:
- Frontend development (use test data)
- Performance testing (load test with simulated users)
- UX testing (use diverse user profiles)
- Data visualization (insight reports available)
When /test/generate-data is called, the following files are created:
insights_test_user_1.txt
insights_test_user_2.txt
insights_test_user_3.txt
...
insights_test_user_7.txt
Each file contains:
LifeLytics Health Insights Report
================================
User ID: test_user_1
Generated: 2026-04-05 17:33:37
Health Score: 78/100
Insights:
• Good sleep patterns
• Moderate activity level
Risks:
• Low average steps
Recommendations:
• Increase daily walks
• Monitor glucose levels
Status: ✅ Complete and Tested Version: 1.0 Date: April 5, 2026