-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_30day_planning.py
More file actions
385 lines (302 loc) · 11.4 KB
/
test_30day_planning.py
File metadata and controls
385 lines (302 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/usr/bin/env python3
"""Test and demonstration script for advanced 30-day training plan system.
This script demonstrates:
1. Advanced mesocycle-based planning
2. Optimal control integration
3. Interactive visualization generation
4. Plan adjustment capabilities
5. Real-world scenario testing
"""
import sys
import json
import numpy as np
from datetime import datetime, timedelta
# Add project to path
sys.path.append('/Users/alex/workspace/supercompensation')
from strava_supercompensation.analysis.advanced_planning import (
AdvancedPlanGenerator, MesocycleType, WorkoutType
)
from strava_supercompensation.analysis.plan_adjustment import (
PlanAdjustmentEngine, AdjustmentReason, AdjustmentType
)
from strava_supercompensation.analysis.model_integration import (
get_integrated_analyzer
)
def test_advanced_plan_generation():
"""Test advanced 30-day plan generation."""
print("\n" + "="*60)
print("Testing Advanced 30-Day Plan Generation")
print("="*60)
generator = AdvancedPlanGenerator("test_user")
# Test different scenarios
scenarios = [
{
'name': 'Fitness Building',
'goal': 'fitness',
'target_date': None,
'constraints': {'max_weekly_hours': 12, 'rest_days': [6]}
},
{
'name': 'Race Preparation',
'goal': 'performance',
'target_date': datetime.utcnow() + timedelta(days=45),
'constraints': {'max_weekly_hours': 15, 'rest_days': [6]}
},
{
'name': 'Recovery Phase',
'goal': 'recovery',
'target_date': None,
'constraints': {'max_weekly_hours': 8, 'rest_days': [6, 0]} # Sunday and Monday
}
]
results = {}
for scenario in scenarios:
print(f"\n--- {scenario['name']} ---")
plan = generator.generate_30_day_plan(
goal=scenario['goal'],
target_event_date=scenario['target_date'],
constraints=scenario['constraints']
)
# Analyze plan
summary = plan['summary']
print(f"Total Load: {summary['total_load']:.0f} TSS")
print(f"Total Duration: {summary['total_duration_hours']:.1f} hours")
print(f"Fitness Gain: +{summary['fitness_gain']:.1f}")
print(f"Hard Days: {summary['hard_days']}")
print(f"Easy Days: {summary['easy_days']}")
print(f"Rest Days: {summary['rest_days']}")
# Check for overtraining
if summary['overtraining_days'] > 0:
print(f"⚠️ Overtraining risk detected on {summary['overtraining_days']} days")
else:
print("✓ No overtraining risk detected")
# Store for further analysis
results[scenario['name']] = plan
return results
def test_plan_adjustments():
"""Test plan adjustment system."""
print("\n" + "="*60)
print("Testing Plan Adjustment System")
print("="*60)
# Generate a base plan
generator = AdvancedPlanGenerator("test_user")
plan = generator.generate_30_day_plan(goal='performance')
# Initialize adjustment engine
adjuster = PlanAdjustmentEngine("test_user")
# Simulate various scenarios requiring adjustments
scenarios = [
{
'name': 'Poor Recovery',
'wellness_data': {
'recovery_score': 45,
'hrv_status': 'poor',
'sleep_quality': 60,
'stress_level': 80
},
'constraints': None
},
{
'name': 'Weather Issues',
'wellness_data': None,
'constraints': {
'weather': {
datetime.utcnow().date() + timedelta(days=1): {
'condition': 'severe_storm',
'temperature': 5,
'wind_speed': 60,
'precipitation': 90
}
}
}
},
{
'name': 'Schedule Conflicts',
'wellness_data': None,
'constraints': {
'schedule_conflicts': [
{
'date': datetime.utcnow().date() + timedelta(days=3),
'reason': 'business_trip'
}
]
}
}
]
for scenario in scenarios:
print(f"\n--- {scenario['name']} ---")
# Get suggested adjustments
adjustments = adjuster.evaluate_plan_adjustments(
current_plan=plan['daily_workouts'],
wellness_data=scenario['wellness_data'],
constraints=scenario['constraints']
)
print(f"Suggested adjustments: {len(adjustments)}")
for adj in adjustments[:3]: # Show top 3
print(f" • {adj.adjustment_type.value}: {adj.reason.value}")
print(f" Confidence: {adj.confidence:.1f}")
print(f" Notes: {adj.notes[:60]}...")
# Apply high-confidence adjustments
adjusted_plan, applied = adjuster.apply_adjustments(
plan['daily_workouts'],
adjustments,
auto_apply_threshold=0.8
)
print(f"Applied {len(applied)} automatic adjustments")
return adjustments
def test_visualization_data():
"""Test visualization data generation."""
print("\n" + "="*60)
print("Testing Visualization Data Generation")
print("="*60)
generator = AdvancedPlanGenerator("test_user")
plan = generator.generate_30_day_plan(goal='balanced')
viz_data = plan['visualizations']
print("Visualization components:")
for component, data in viz_data.items():
if isinstance(data, list):
print(f" • {component}: {len(data)} data points")
elif isinstance(data, dict):
print(f" • {component}: {len(data)} keys")
# Validate data structure
required_components = [
'daily_data',
'weekly_summary',
'fitness_progression',
'recovery_status'
]
missing = [comp for comp in required_components if comp not in viz_data]
if missing:
print(f"⚠️ Missing visualization components: {missing}")
else:
print("✓ All required visualization components present")
return viz_data
def test_integrated_system():
"""Test integration with advanced models."""
print("\n" + "="*60)
print("Testing Integrated System")
print("="*60)
analyzer = get_integrated_analyzer("test_user")
# Generate optimal plan using integrated models
plan = analyzer.generate_optimal_plan(
goal='balanced',
duration_days=30,
rest_days=[6] # Sunday rest
)
if plan['success']:
print("✓ Integrated optimization successful")
print(f"Total weekly load: {np.sum(plan['loads']):.1f}")
print(f"Load distribution: {[f'{x:.0f}' for x in plan['loads'][:7]]}")
# Check recommendations
recs = plan['recommendations']
rec_counts = {}
for rec in recs:
rec_counts[rec] = rec_counts.get(rec, 0) + 1
print("Recommendation distribution:")
for rec, count in rec_counts.items():
print(f" {rec}: {count} days")
else:
print("❌ Integrated optimization failed")
return plan
def generate_sample_html():
"""Generate sample HTML visualization."""
print("\n" + "="*60)
print("Generating Sample HTML Visualization")
print("="*60)
# Generate a sample plan
generator = AdvancedPlanGenerator("test_user")
plan = generator.generate_30_day_plan(goal='fitness')
# Extract visualization data
viz_data = plan['visualizations']
# Create HTML with embedded data
html_template_path = '/Users/alex/workspace/supercompensation/templates/training_plan_visualization.html'
output_path = '/Users/alex/workspace/supercompensation/sample_30day_plan.html'
try:
with open(html_template_path, 'r') as f:
html_content = f.read()
# Replace the sample data loading with actual data
data_js = f"loadPlanData({json.dumps(plan, default=str, indent=2)});"
# Insert the data loading call
html_content = html_content.replace(
'loadPlanData(sampleData);',
data_js
)
with open(output_path, 'w') as f:
f.write(html_content)
print(f"✓ HTML visualization generated: {output_path}")
print("Open this file in a browser to view the interactive plan")
except Exception as e:
print(f"❌ Failed to generate HTML: {e}")
return output_path
def run_performance_benchmarks():
"""Run performance benchmarks."""
print("\n" + "="*60)
print("Running Performance Benchmarks")
print("="*60)
import time
generator = AdvancedPlanGenerator("test_user")
# Benchmark plan generation
start_time = time.time()
plan = generator.generate_30_day_plan(goal='performance')
generation_time = time.time() - start_time
print(f"Plan generation time: {generation_time:.2f} seconds")
# Benchmark adjustment evaluation
adjuster = PlanAdjustmentEngine("test_user")
start_time = time.time()
adjustments = adjuster.evaluate_plan_adjustments(
current_plan=plan['daily_workouts'],
wellness_data={'recovery_score': 60},
constraints={'weather': {}}
)
adjustment_time = time.time() - start_time
print(f"Adjustment evaluation time: {adjustment_time:.2f} seconds")
print(f"Number of workouts analyzed: {len(plan['daily_workouts'])}")
print(f"Adjustments suggested: {len(adjustments)}")
# Memory usage estimate
plan_size = sys.getsizeof(plan) / 1024 # KB
print(f"Plan data size: {plan_size:.1f} KB")
return {
'generation_time': generation_time,
'adjustment_time': adjustment_time,
'plan_size': plan_size
}
def main():
"""Run comprehensive test suite."""
print("\n" + "#"*60)
print("# ADVANCED 30-DAY TRAINING PLAN TEST SUITE")
print("#"*60)
try:
# Test plan generation
plan_results = test_advanced_plan_generation()
# Test plan adjustments
adjustment_results = test_plan_adjustments()
# Test visualization
viz_data = test_visualization_data()
# Test integrated system
integrated_results = test_integrated_system()
# Generate sample HTML
html_path = generate_sample_html()
# Run benchmarks
benchmarks = run_performance_benchmarks()
print("\n" + "#"*60)
print("# TEST SUMMARY")
print("#"*60)
print(f"✓ Plan generation: {len(plan_results)} scenarios tested")
print(f"✓ Adjustment system: {len(adjustment_results)} adjustments evaluated")
print(f"✓ Visualization: {len(viz_data)} components generated")
print(f"✓ Integration: {'Success' if integrated_results['success'] else 'Failed'}")
print(f"✓ HTML output: {html_path}")
print(f"\nPerformance:")
print(f" Generation: {benchmarks['generation_time']:.2f}s")
print(f" Adjustments: {benchmarks['adjustment_time']:.2f}s")
print(f" Memory: {benchmarks['plan_size']:.1f} KB")
print("\n" + "#"*60)
print("# ALL TESTS COMPLETED SUCCESSFULLY ✓")
print("#"*60)
return 0
except Exception as e:
print(f"\n❌ Test failed with error: {e}")
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(main())