Habit Auto-Scheduling Improvements
Mind Your Now features an intelligent automatic scheduling system for habits that leverages OptaPlanner and machine learning to optimize your daily routine. This system goes beyond simple time allocation to understand your preferences and optimize for the best possible scheduling outcomes.
Overview
The habit auto-scheduling system uses a sophisticated constraint-solving approach powered by OptaPlanner 9.44.0 and integrated with the PlanningService to automatically schedule habits and chores based on your availability, preferences, and historical patterns.
Architecture Components
PlanningService Integration
The PlanningService
serves as the core orchestrator for all scheduling operations:
- OptaPlanner Solver: Uses constraint programming to find optimal scheduling solutions
- Event Schedule Domain: Manages the planning solution with time grains, schedules, and assignments
- Constraint Provider: Defines hard, medium, and soft constraints for scheduling decisions
- Incremental Scoring: Efficiently recalculates scores as the schedule changes
OptaPlanner Domain Model
The scheduling system uses these key domain entities:
- EventSchedule: The main planning solution containing all scheduling data
- EventAssignment: Planning entities representing scheduled habits/chores
- TimeGrain: 15-minute time slots that habits can be assigned to
- Event: Represents the habit or chore to be scheduled
- Day: Groups time grains by calendar day
User Preferences System
Scheduling preferences are managed through the customer entity and schedule blocks:
- Default Time Zone: Stored in
MYNCustomer.defaultTimeZone
- Schedule Blocks: Defined availability windows in
ScheduleBlock
entities - Picture Preferences: User interface preferences via
PicturePreference
enum - AI Usage Limits: Configurable limits for AI-powered optimization
Smart Scheduling Algorithm
Decision Flow:
- Availability Assessment → Check user's schedule blocks and existing calendar events
- Preference Analysis → Apply learned preferences for optimal time slot selection
- Conflict Detection → Identify and resolve scheduling conflicts automatically
- Constraint Evaluation → Score solutions using hard/medium/soft constraints
- Optimization → Find the best schedule using OptaPlanner's solving algorithms
- Calendar Integration → Create calendar events for scheduled items
Time Slot Selection Logic
The system intelligently selects time slots based on:
- Schedule Blocks: User-defined availability windows
- Historical Patterns: Learning from past scheduling success
- Task Dependencies: Respecting prerequisites and sequences
- Calendar Integration: Avoiding conflicts with existing events
- Priority Levels: CRITICAL, OPPORTUNITY_NOW, OVER_THE_HORIZON, PARKING_LOT
Conflict Resolution Scenarios
Common Conflict Types:
-
Overlapping Assignments: Multiple habits scheduled at the same time
- Resolution: Reschedule lower-priority items to alternative slots
-
Calendar Event Conflicts: Scheduled habits conflict with existing calendar events
- Resolution: Automatically adjust to available time slots
-
Schedule Block Violations: Habits scheduled outside available hours
- Resolution: Move to valid time windows or suggest schedule adjustments
-
Duration Mismatches: Habit duration exceeds available time slot
- Resolution: Split into multiple sessions or extend time block
-
Recurring Task Conflicts: Daily habits conflict with weekly/monthly tasks
- Resolution: Priority-based scheduling with intelligent spacing
API Endpoints
POST /api/v2/scheduling/habits/schedule
Triggers on-demand scheduling of habits and chores for the current user.
Parameters:
numberOfDays
(optional): Number of days to schedule (1-30, default 7)
Authentication: JWT token required with user email claim
Response Format:
{
"message": "Scheduling completed successfully",
"itemsScheduled": 15,
"scheduledItems": [
{
"taskId": "habit-123",
"taskTitle": "Morning Exercise",
"taskType": "HABIT",
"scheduledDate": "2025-01-15T07:00:00",
"durationMinutes": 30
}
]
}
GET /api/v2/scheduling/habits/status
Returns information about habits and chores eligible for auto-scheduling.
Response:
{
"userEmail": "[email protected]",
"schedulingEnabled": true,
"nextScheduledRun": "Daily at 2:00 AM UTC",
"message": "Use POST endpoint to trigger immediate scheduling"
}
Machine Learning Components
The system incorporates machine learning for preference learning and optimization:
- Preference Learning: Analyzes user behavior to understand optimal scheduling patterns
- Success Rate Tracking: Monitors completion rates to improve future scheduling
- Adaptive Scheduling: Adjusts algorithms based on user feedback and completion data
- Conflict Pattern Recognition: Learns common conflict scenarios and prevention strategies
Performance Optimization Tips
For Large Habit Lists:
- Batch Processing: Schedule multiple habits in single optimization runs
- Time Window Limiting: Use focused scheduling windows rather than entire days
- Priority Filtering: Schedule high-priority items first, then fill remaining slots
- Incremental Updates: Use problem changes for small schedule modifications
- Cache Optimization: Leverage time grain caching for repeated queries
Constraint Tuning:
- Use hard constraints only for absolute requirements
- Apply medium constraints for important preferences
- Use soft constraints for nice-to-have optimizations
- Balance constraint complexity with solving time
Manual Override Options
Users retain full control over their scheduled habits:
- Individual Rescheduling: Drag and drop habits to different time slots
- Recurring Pattern Changes: Modify habit frequency and timing
- Priority Adjustments: Change habit importance levels
- Schedule Block Updates: Adjust availability windows as needed
- Constraint Customization: Enable/disable specific scheduling rules
Advanced Features
AI-Powered Optimization
The system leverages AI services for enhanced scheduling:
- Task Optimization: AI-suggested improvements to habit timing
- Pattern Recognition: Identifying optimal scheduling patterns
- Predictive Scheduling: Anticipating future scheduling needs
- Adaptive Learning: Continuously improving based on user behavior
Calendar Synchronization
Full integration with external calendar systems:
- Google Calendar: Bidirectional sync with habit events
- Conflict Prevention: Real-time checking against calendar events
- Time Zone Handling: Intelligent handling of time zone differences
- Event Templates: Standardized calendar event creation
Household Scheduling
Support for multi-user household scheduling:
- Shared Habits: Coordinate family habits and chores
- Assignment Distribution: Fair allocation of household tasks
- Conflict Resolution: Handle overlapping family member schedules
- Notification Coordination: Household-wide scheduling updates
Implementation Notes
The auto-scheduling system is designed with these technical considerations:
- Thread Safety: Uses Redis locks for concurrent scheduling operations
- Scalability: Efficient handling of multiple users and large habit sets
- Reliability: Robust error handling and fallback mechanisms
- Monitoring: Comprehensive logging and performance tracking
- Security: JWT-based authentication with proper authorization checks
This intelligent scheduling system transforms habit management from a manual chore into an automated, optimized experience that adapts to your lifestyle and preferences.