Conversation
- Add UserBaseline model with IQR-based anomaly detection
- Add Alembic migration for user_baselines table and analytics indices
- Implement BaselineService with calculations for:
- HRV RMSSD (from nightly recharge)
- Sleep score
- Resting heart rate
- Training load and ratio
- Add baselines API endpoints:
- GET /users/{id}/baselines - List all baselines
- GET /users/{id}/baselines/{metric} - Get specific baseline
- POST /users/{id}/baselines/calculate - Trigger calculation
- GET /users/{id}/baselines/check/{metric}/{value} - Anomaly check
- GET /users/{id}/analytics/status - Data readiness and feature unlocks
Features available based on data days:
- 7 days: Basic stats
- 14 days: Trend analysis
- 21 days: Personalized baselines
- 30 days: Predictive models
- 60 days: Advanced ML
- 90 days: Long-term patterns
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…1.9) - Add automatic baseline recalculation after sync operations - Create test data seeding fixtures with 90 days of realistic data - Weekly HRV patterns (Monday dips, Friday peaks) - Sleep score variations - Training load periodization (4-week cycles) - Occasional anomalies (2% chance) - Add analytics fixtures for different data scenarios (90d, 21d, 7d, 3d) - Write 13 comprehensive tests covering: - Baseline status levels (ready/partial/insufficient) - IQR calculations and bounds - Anomaly detection (warning/critical thresholds) - Multi-metric baseline calculation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Test comment from review |
- Add type params to ASGIConnection[Any, Any, Any, Any] - Add type params to Response[Any] - Add type params to Request[Any, Any, Any] - Import ASGIApp from litestar.types - Add type: ignore for scope comparison (litestar typing issue) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Review: Feature/analytics engineExecutive SummaryThis PR adds a comprehensive analytics baseline system for health metrics. Overall implementation is solid and well-architected, with proper multi-tenancy, good statistical methods, and security-conscious design. Found several issues that should be addressed before merge. 🔴 Critical Issues1. Authorization Bypass: Missing user_id ValidationLocation: Issue: In Current logic: if api_key.user_id is not None and path_user_id:
if api_key.user_id != path_user_id:
raise NotAuthorizedException(...)Problem: When Impact: Anyone with a service-level API key can access all users' baseline data. Recommendation: Add explicit service-level key validation or require admin privileges for cross-user access. Severity: 🔴 HIGH - Authorization bypass in multi-tenant system 2. Type Ignore Comments Hide Real IssueLocation: extreme_lower = self.q1 - 3 * self.iqr # type: ignore
extreme_upper = self.q3 + 3 * self.iqr # type: ignoreIssue: The type ignores are suppressing legitimate type errors. Correct fix: if self.iqr is not None and self.q1 is not None and self.q3 is not None:
extreme_lower = self.q1 - 3 * self.iqr
extreme_upper = self.q3 + 3 * self.iqrSeverity: 🟠 Medium (could cause runtime errors if q1/q3 are None)
|
- Enable use_sticky_comment for automatic PR comment posting - Remove gh pr comment from allowed tools (was causing shell escaping issues) - Add Write tool for flexibility - Update prompt to output review directly instead of posting manually The previous approach had Claude try to post via gh pr comment, but markdown with code blocks caused shell escaping failures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix type safety in is_anomaly(): Remove type: ignore comments by checking all required values (q1, q3, iqr) before calculations - Add user_id format validation: Regex-based validation prevents injection attacks, limits to alphanumeric with _ and - only - Add float input validation: Reject NaN, inf, -inf values in check_anomaly endpoint to prevent edge case errors - Remove redundant quantile check: quantiles(n=4) always returns exactly [Q1, Q2, Q3], no length check needed - Document service-level API key authorization model: Clarify that user_id=None keys intentionally have admin access for SaaS backends Security improvements: - ValidationException for invalid user_id format (1-100 chars) - ValidationException for non-finite float values - Don't reveal all valid metric names in error messages Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
No description provided.