Spaces:
Running
Running
Download script.js from CSNET/whoop-health-tracker-pro: direct link, hf CLI and curl.
- Browser
- Download file 29.5 kB
-
https://huggingface.co/spaces/CSNET/whoop-health-tracker-pro/resolve/main/script.js
- Command line
-
hf download hf://spaces/CSNET/whoop-health-tracker-pro/script.js
-
curl -L -o script.js https://huggingface.co/spaces/CSNET/whoop-health-tracker-pro/resolve/main/script.js
29.5 kB
| // Global Variables | |
| let currentData = {}; | |
| let charts = {}; | |
| // Initialize functions for each page | |
| function initializeRecoveryPage() { | |
| loadMockData(); | |
| updateRecoveryDashboard(); | |
| createRecoveryCharts(); | |
| } | |
| function initializeSleepPage() { | |
| loadMockData(); | |
| updateSleepDashboard(); | |
| createSleepCharts(); | |
| } | |
| function initializeStrainPage() { | |
| loadMockData(); | |
| updateStrainDashboard(); | |
| createStrainCharts(); | |
| } | |
| function initializeJournalPage() { | |
| loadMockData(); | |
| setupJournalHandlers(); | |
| updateJournalDashboard(); | |
| } | |
| function initializeCoachPage() { | |
| loadMockData(); | |
| setupCoachHandlers(); | |
| updateCoachStats(); | |
| } | |
| // Load Mock Data | |
| function loadMockData() { | |
| // Generate mock data for the last 30 days | |
| currentData = { | |
| today: generateTodayData(), | |
| week: generateWeekData(), | |
| month: generateMonthData() | |
| }; | |
| } | |
| function generateTodayData() { | |
| return { | |
| date: new Date().toISOString().split('T')[0], | |
| recoveryScore: Math.floor(Math.random() * 40) + 60, // 60-100 | |
| hrv: Math.floor(Math.random() * 30) + 40, // 40-70 ms | |
| rhr: Math.floor(Math.random() * 20) + 50, // 50-70 bpm | |
| respRate: Math.floor(Math.random() * 6) + 12, // 12-18 breaths/min | |
| sleepPerformance: Math.floor(Math.random() * 30) + 70, // 70-100% | |
| sleepDuration: (Math.random() * 2 + 6).toFixed(1), // 6-8 hours | |
| sleepStages: { | |
| deep: (Math.random() * 1.5 + 1).toFixed(1), | |
| rem: (Math.random() * 2 + 1.5).toFixed(1), | |
| light: (Math.random() * 3 + 3).toFixed(1), | |
| awake: (Math.random() * 0.5 + 0.2).toFixed(1) | |
| }, | |
| dailyStrain: Math.floor(Math.random() * 15) + 5, // 5-20 | |
| maxHR: Math.floor(Math.random() * 50) + 140, // 140-190 bpm | |
| avgHR: Math.floor(Math.random() * 30) + 80, // 80-110 bpm | |
| calories: Math.floor(Math.random() * 1000) + 500, // 500-1500 kcal | |
| activities: generateActivities() | |
| }; | |
| } | |
| function generateWeekData() { | |
| const data = []; | |
| for (let i = 6; i >= 0; i--) { | |
| const date = new Date(); | |
| date.setDate(date.getDate() - i); | |
| data.push({ | |
| date: date.toISOString().split('T')[0], | |
| recoveryScore: Math.floor(Math.random() * 40) + 60, | |
| strain: Math.floor(Math.random() * 15) + 5, | |
| sleepHours: (Math.random() * 2 + 6).toFixed(1) | |
| }); | |
| } | |
| return data; | |
| } | |
| function generateMonthData() { | |
| const data = []; | |
| for (let i = 29; i >= 0; i--) { | |
| const date = new Date(); | |
| date.setDate(date.getDate() - i); | |
| data.push({ | |
| date: date.toISOString().split('T')[0], | |
| recoveryScore: Math.floor(Math.random() * 40) + 60, | |
| hrv: Math.floor(Math.random() * 30) + 40, | |
| rhr: Math.floor(Math.random() * 20) + 50 | |
| }); | |
| } | |
| return data; | |
| } | |
| function generateActivities() { | |
| const types = ['Running', 'Weight Training', 'Yoga', 'Cycling', 'Swimming']; | |
| const activities = []; | |
| const count = Math.floor(Math.random() * 3) + 1; | |
| for (let i = 0; i < count; i++) { | |
| activities.push({ | |
| type: types[Math.floor(Math.random() * types.length)], | |
| duration: Math.floor(Math.random() * 60) + 20, | |
| strain: Math.floor(Math.random() * 10) + 1, | |
| calories: Math.floor(Math.random() * 300) + 100 | |
| }); | |
| } | |
| return activities; | |
| } | |
| // Update Recovery Dashboard | |
| function updateRecoveryDashboard() { | |
| const today = currentData.today; | |
| // Update gauge | |
| const gauge = document.querySelector('custom-recovery-gauge'); | |
| if (gauge) { | |
| gauge.setAttribute('score', today.recoveryScore); | |
| } | |
| // Update metrics | |
| document.getElementById('hrvValue').textContent = today.hrv; | |
| document.getElementById('rhrValue').textContent = today.rhr; | |
| document.getElementById('respRateValue').textContent = today.respRate; | |
| // Calculate strain target based on recovery | |
| let strainTarget; | |
| if (today.recoveryScore > 80) { | |
| strainTarget = '14.0-17.9'; | |
| } else if (today.recoveryScore > 60) { | |
| strainTarget = '10.0-13.9'; | |
| } else { | |
| strainTarget = '0.0-9.9'; | |
| } | |
| document.getElementById('strainTarget').textContent = strainTarget; | |
| // Update insights | |
| updateRecoveryInsights(today); | |
| } | |
| function updateRecoveryInsights(data) { | |
| const insights = document.getElementById('insights'); | |
| const messages = []; | |
| if (data.recoveryScore > 80) { | |
| messages.push({ | |
| icon: 'check-circle', | |
| color: 'text-green-400', | |
| text: 'Excellent recovery! You\'re ready for high-intensity training today.' | |
| }); | |
| } else if (data.recoveryScore > 60) { | |
| messages.push({ | |
| icon: 'alert-circle', | |
| color: 'text-yellow-400', | |
| text: 'Moderate recovery. Consider a balanced workout with adequate rest periods.' | |
| }); | |
| } else { | |
| messages.push({ | |
| icon: 'x-circle', | |
| color: 'text-red-400', | |
| text: 'Low recovery detected. Focus on active recovery and proper nutrition today.' | |
| }); | |
| } | |
| if (data.hrv > 60) { | |
| messages.push({ | |
| icon: 'trending-up', | |
| color: 'text-green-400', | |
| text: 'Your HRV is trending positively, indicating good autonomic balance.' | |
| }); | |
| } | |
| if (data.rhr < 60) { | |
| messages.push({ | |
| icon: 'heart', | |
| color: 'text-blue-400', | |
| text: 'Your resting heart rate is excellent, showing strong cardiovascular fitness.' | |
| }); | |
| } | |
| insights.innerHTML = messages.map(msg => ` | |
| <div class="flex items-start space-x-3"> | |
| <i data-feather="${msg.icon}" class="w-5 h-5 ${msg.color} mt-1"></i> | |
| <p class="text-gray-300">${msg.text}</p> | |
| </div> | |
| `).join(''); | |
| feather.replace(); | |
| } | |
| // Create Recovery Charts | |
| function createRecoveryCharts() { | |
| // Recovery Trend Chart | |
| const ctx1 = document.getElementById('recoveryTrendChart'); | |
| if (ctx1) { | |
| charts.recoveryTrend = new Chart(ctx1, { | |
| type: 'line', | |
| data: { | |
| labels: currentData.month.map(d => new Date(d.date).toLocaleDateString('en', { month: 'short', day: 'numeric' })), | |
| datasets: [{ | |
| label: 'Recovery Score', | |
| data: currentData.month.map(d => d.recoveryScore), | |
| borderColor: '#10b981', | |
| backgroundColor: 'rgba(16, 185, 129, 0.1)', | |
| tension: 0.4 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| max: 100, | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| }, | |
| x: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // HRV Trend Chart | |
| const ctx2 = document.getElementById('hrvTrendChart'); | |
| if (ctx2) { | |
| charts.hrvTrend = new Chart(ctx2, { | |
| type: 'line', | |
| data: { | |
| labels: currentData.month.slice(-7).map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })), | |
| datasets: [{ | |
| label: 'HRV', | |
| data: currentData.month.slice(-7).map(d => d.hrv), | |
| borderColor: '#8b5cf6', | |
| backgroundColor: 'rgba(139, 92, 246, 0.1)', | |
| tension: 0.4 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| }, | |
| x: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // RHR Trend Chart | |
| const ctx3 = document.getElementById('rhrTrendChart'); | |
| if (ctx3) { | |
| charts.rhrTrend = new Chart(ctx3, { | |
| type: 'line', | |
| data: { | |
| labels: currentData.month.slice(-7).map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })), | |
| datasets: [{ | |
| label: 'Resting HR', | |
| data: currentData.month.slice(-7).map(d => d.rhr), | |
| borderColor: '#3b82f6', | |
| backgroundColor: 'rgba(59, 130, 246, 0.1)', | |
| tension: 0.4 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| }, | |
| x: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| } | |
| // Update Sleep Dashboard | |
| function updateSleepDashboard() { | |
| const today = currentData.today; | |
| document.getElementById('sleepPerformance').textContent = today.sleepPerformance; | |
| document.getElementById('sleepDuration').textContent = today.sleepDuration; | |
| document.getElementById('sleepEfficiency').textContent = Math.floor(Math.random() * 20) + 80; // 80-100% | |
| // Update sleep stages | |
| document.getElementById('deepSleep').textContent = today.sleepStages.deep; | |
| document.getElementById('remSleep').textContent = today.sleepStages.rem; | |
| document.getElementById('lightSleep').textContent = today.sleepStages.light; | |
| document.getElementById('awakeTime').textContent = today.sleepStages.awake; | |
| // Update sleep planner | |
| const bedtime = '10:30 PM'; | |
| const wakeTime = '6:30 AM'; | |
| const sleepNeed = '8h 0m'; | |
| document.getElementById('bedtime').textContent = bedtime; | |
| document.getElementById('wakeTime').textContent = wakeTime; | |
| document.getElementById('sleepNeed').textContent = sleepNeed; | |
| } | |
| // Create Sleep Charts | |
| function createSleepCharts() { | |
| const today = currentData.today; | |
| // Sleep Stages Donut Chart | |
| const ctx1 = document.getElementById('sleepStagesChart'); | |
| if (ctx1) { | |
| charts.sleepStages = new Chart(ctx1, { | |
| type: 'doughnut', | |
| data: { | |
| labels: ['Deep', 'REM', 'Light', 'Awake'], | |
| datasets: [{ | |
| data: [ | |
| parseFloat(today.sleepStages.deep), | |
| parseFloat(today.sleepStages.rem), | |
| parseFloat(today.sleepStages.light), | |
| parseFloat(today.sleepStages.awake) | |
| ], | |
| backgroundColor: ['#8b5cf6', '#3b82f6', '#60a5fa', '#6b7280'] | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // Weekly Sleep Chart | |
| const ctx2 = document.getElementById('weeklySleepChart'); | |
| if (ctx2) { | |
| charts.weeklySleep = new Chart(ctx2, { | |
| type: 'bar', | |
| data: { | |
| labels: currentData.week.map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })), | |
| datasets: [{ | |
| label: 'Sleep Hours', | |
| data: currentData.week.map(d => parseFloat(d.sleepHours)), | |
| backgroundColor: '#3b82f6' | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| }, | |
| x: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| } | |
| // Update Strain Dashboard | |
| function updateStrainDashboard() { | |
| const today = currentData.today; | |
| document.getElementById('dailyStrain').textContent = today.dailyStrain; | |
| document.getElementById('maxHR').textContent = today.maxHR; | |
| document.getElementById('avgHR').textContent = today.avgHR; | |
| document.getElementById('calories').textContent = today.calories; | |
| document.getElementById('activeTime').textContent = Math.floor(today.dailyStrain * 15); | |
| // Update strain status | |
| const statusEl = document.getElementById('strainStatus'); | |
| if (today.dailyStrain >= 15) { | |
| statusEl.textContent = 'High Intensity'; | |
| statusEl.className = 'px-4 py-2 rounded-full text-sm font-semibold bg-red-900 text-red-400'; | |
| } else if (today.dailyStrain >= 10) { | |
| statusEl.textContent = 'Moderate'; | |
| statusEl.className = 'px-4 py-2 rounded-full text-sm font-semibold bg-yellow-900 text-yellow-400'; | |
| } else { | |
| statusEl.textContent = 'Light'; | |
| statusEl.className = 'px-4 py-2 rounded-full text-sm font-semibold bg-green-900 text-green-400'; | |
| } | |
| // Update activities list | |
| const activitiesList = document.getElementById('activitiesList'); | |
| if (activitiesList) { | |
| activitiesList.innerHTML = today.activities.map(activity => ` | |
| <div class="activity-card bg-gray-800 rounded-lg p-4 flex items-center justify-between"> | |
| <div class="flex items-center"> | |
| <i data-feather="activity" class="w-5 h-5 mr-3 text-blue-400"></i> | |
| <div> | |
| <div class="font-semibold">${activity.type}</div> | |
| <div class="text-sm text-gray-400">${activity.duration} min</div> | |
| </div> | |
| </div> | |
| <div class="text-right"> | |
| <div class="text-yellow-400 font-semibold">Strain ${activity.strain}</div> | |
| <div class="text-sm text-gray-400">${activity.calories} kcal</div> | |
| </div> | |
| </div> | |
| `).join(''); | |
| feather.replace(); | |
| } | |
| } | |
| // Create Strain Charts | |
| function createStrainCharts() { | |
| // Weekly Strain Chart | |
| const ctx1 = document.getElementById('weeklyStrainChart'); | |
| if (ctx1) { | |
| charts.weeklyStrain = new Chart(ctx1, { | |
| type: 'line', | |
| data: { | |
| labels: currentData.week.map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })), | |
| datasets: [{ | |
| label: 'Daily Strain', | |
| data: currentData.week.map(d => d.strain), | |
| borderColor: '#f59e0b', | |
| backgroundColor: 'rgba(245, 158, 11, 0.1)', | |
| fill: true, | |
| tension: 0.4 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| max: 21, | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| }, | |
| x: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // HR Zones Chart | |
| const ctx2 = document.getElementById('hrZonesChart'); | |
| if (ctx2) { | |
| charts.hrZones = new Chart(ctx2, { | |
| type: 'bar', | |
| data: { | |
| labels: ['Zone 1', 'Zone 2', 'Zone 3', 'Zone 4', 'Zone 5'], | |
| datasets: [{ | |
| label: 'Time in Zone', | |
| data: [45, 30, 20, 10, 5], | |
| backgroundColor: ['#10b981', '#3b82f6', '#f59e0b', '#f97316', '#ef4444'] | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| }, | |
| x: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| } | |
| // Setup Journal Handlers | |
| function setupJournalHandlers() { | |
| // Stress level buttons | |
| document.querySelectorAll('.stress-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| document.querySelectorAll('.stress-btn').forEach(b => b.classList.remove('active')); | |
| this.classList.add('active'); | |
| }); | |
| }); | |
| // Form submission | |
| document.getElementById('journalForm').addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| // Mock save | |
| showNotification('Journal entry saved successfully!'); | |
| }); | |
| } | |
| // Update Journal Dashboard | |
| function updateJournalDashboard() { | |
| // Positive behaviors | |
| const positiveBehaviors = [ | |
| { behavior: 'Good Sleep Duration', impact: '+15% Recovery', icon: 'moon' }, | |
| { behavior: 'No Alcohol', impact: '+8% HRV', icon: 'check' }, | |
| { behavior: 'Moderate Exercise', impact: '+5% Sleep Quality', icon: 'activity' } | |
| ]; | |
| // Negative behaviors | |
| const negativeBehaviors = [ | |
| { behavior: 'High Stress', impact: '-12% Recovery', icon: 'alert-triangle' }, | |
| { behavior: 'Late Caffeine', impact: '-8% Sleep Efficiency', icon: 'coffee' }, | |
| { behavior: 'Inconsistent Schedule', impact: '-10% HRV', icon: 'clock' } | |
| ]; | |
| const positiveEl = document.getElementById('positiveBehaviors'); | |
| if (positiveEl) { | |
| positiveEl.innerHTML = positiveBehaviors.map(b => ` | |
| <div class="flex items-center justify-between p-3 bg-green-900/20 border border-green-700 rounded-lg"> | |
| <div class="flex items-center"> | |
| <i data-feather="${b.icon}" class="w-4 h-4 mr-2 text-green-400"></i> | |
| <span class="text-gray-300">${b.behavior}</span> | |
| </div> | |
| <span class="text-green-400 font-semibold">${b.impact}</span> | |
| </div> | |
| `).join(''); | |
| } | |
| const negativeEl = document.getElementById('negativeBehaviors'); | |
| if (negativeEl) { | |
| negativeEl.innerHTML = negativeBehaviors.map(b => ` | |
| <div class="flex items-center justify-between p-3 bg-red-900/20 border border-red-700 rounded-lg"> | |
| <div class="flex items-center"> | |
| <i data-feather="${b.icon}" class="w-4 h-4 mr-2 text-red-400"></i> | |
| <span class="text-gray-300">${b.behavior}</span> | |
| </div> | |
| <span class="text-red-400 font-semibold">${b.impact}</span> | |
| </div> | |
| `).join(''); | |
| } | |
| feather.replace(); | |
| // Behavior Chart | |
| const ctx = document.getElementById('behaviorChart'); | |
| if (ctx) { | |
| charts.behavior = new Chart(ctx, { | |
| type: 'line', | |
| data: { | |
| labels: currentData.week.map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })), | |
| datasets: [{ | |
| label: 'Recovery Score', | |
| data: currentData.week.map(d => d.recoveryScore), | |
| borderColor: '#10b981', | |
| yAxisID: 'y' | |
| }, { | |
| label: 'Alcohol (1=yes, 0=no)', | |
| data: [0, 1, 0, 0, 1, 0, 0], | |
| borderColor: '#f59e0b', | |
| yAxisID: 'y1' | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| y: { | |
| type: 'linear', | |
| display: true, | |
| position: 'left', | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| }, | |
| y1: { | |
| type: 'linear', | |
| display: true, | |
| position: 'right', | |
| grid: { | |
| drawOnChartArea: false | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| }, | |
| x: { | |
| grid: { | |
| color: '#333' | |
| }, | |
| ticks: { | |
| color: '#999' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // Recent Entries | |
| const entriesEl = document.getElementById('recentEntries'); | |
| if (entriesEl) { | |
| const entries = [ | |
| { date: '2024-01-15', note: 'Feeling great after 8 hours of sleep!', score: 92 }, | |
| { date: '2024-01-14', note: 'Tough workout, need extra rest', score: 68 }, | |
| { date: '2024-01-13', note: 'Stressful day at work', score: 55 } | |
| ]; | |
| entriesEl.innerHTML = entries.map(e => ` | |
| <div class="journal-entry p-4 bg-gray-800 rounded-lg"> | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <div class="text-sm text-gray-400">${e.date}</div> | |
| <div class="mt-1">${e.note}</div> | |
| </div> | |
| <div class="text-2xl font-bold ${e.score > 80 ? 'text-green-400' : e.score > 60 ? 'text-yellow-400' : 'text-red-400'}">${e.score}</div> | |
| </div> | |
| </div> | |
| `).join(''); | |
| } | |
| } | |
| // Setup Coach Handlers | |
| function setupCoachHandlers() { | |
| // Chat form | |
| document.getElementById('chatForm').addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| const input = document.getElementById('chatInput'); | |
| const message = input.value.trim(); | |
| if (message) { | |
| addUserMessage(message); | |
| input.value = ''; | |
| // Simulate coach response | |
| setTimeout(() => { | |
| addCoachMessage(getCoachResponse(message)); | |
| }, 1000); | |
| } | |
| }); | |
| // Quick prompts | |
| document.querySelectorAll('.coach-prompt').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const prompt = this.dataset.prompt; | |
| addUserMessage(this.textContent.trim()); | |
| setTimeout(() => { | |
| addCoachMessage(getCoachResponse(prompt)); | |
| }, 1000); | |
| }); | |
| }); | |
| } | |
| // Update Coach Stats | |
| function updateCoachStats() { | |
| const today = currentData.today; | |
| document.getElementById('coachRecovery').textContent = today.recoveryScore + '%'; | |
| document.getElementById('coachSleep').textContent = today.sleepDuration; | |
| document.getElementById('coachStrain').textContent = today.dailyStrain; | |
| document.getElementById('coachHRV').textContent = today.hrv; | |
| } | |
| // Coach Chat Functions | |
| function addUserMessage(message) { | |
| const chatMessages = document.getElementById('chatMessages'); | |
| const messageEl = document.createElement('div'); | |
| messageEl.className = 'flex items-start justify-end chat-message'; | |
| messageEl.innerHTML = ` | |
| <div class="bg-blue-600 rounded-lg p-4 max-w-md"> | |
| <p>${message}</p> | |
| </div> | |
| <div class="w-8 h-8 bg-gray-700 rounded-full flex items-center justify-center ml-3 mt-1"> | |
| <i data-feather="user" class="w-4 h-4"></i> | |
| </div> | |
| `; | |
| chatMessages.appendChild(messageEl); | |
| chatMessages.scrollTop = chatMessages.scrollHeight; | |
| feather.replace(); | |
| } | |
| function addCoachMessage(message) { | |
| const chatMessages = document.getElementById('chatMessages'); | |
| const messageEl = document.createElement('div'); | |
| messageEl.className = 'flex items-start chat-message'; | |
| messageEl.innerHTML = ` | |
| <div class="w-8 h-8 bg-gradient-to-br from-blue-500 to-purple-600 rounded-full flex items-center justify-center mr-3 mt-1"> | |
| <i data-feather="cpu" class="w-4 h-4"></i> | |
| </div> | |
| <div class="bg-gray-800 rounded-lg p-4 max-w-md"> | |
| <p class="text-gray-300">${message}</p> | |
| </div> | |
| `; | |
| chatMessages.appendChild(messageEl); | |
| chatMessages.scrollTop = chatMessages.scrollHeight; | |
| feather.replace(); | |
| } | |
| function getCoachResponse(prompt) { | |
| const today = currentData.today; | |
| const responses = { | |
| recovery: `Based on your data, today's recovery score is ${today.recoveryScore}%. ${today.recoveryScore > 80 ? 'You\'re in great shape! Consider a high-intensity workout.' : today.recoveryScore > 60 ? 'You\'re moderately recovered. A balanced workout would be ideal.' : 'Your recovery is low. Focus on active recovery and proper nutrition.'}`, | |
| workout: `With a recovery score of ${today.recoveryScore}% and yesterday's strain of ${today.dailyStrain}, I recommend ${today.recoveryScore > 80 ? 'a high-intensity interval training session' : today.recoveryScore > 60 ? 'moderate cardio with some light strength training' : 'active recovery like yoga or a light walk'} today.`, | |
| sleep: `You slept ${today.sleepDuration} hours last night with ${today.sleepPerformance}% performance. ${parseFloat(today.sleepDuration) < 7 ? 'Try to get at least 7-8 hours tonight. Consider going to bed 30 minutes earlier.' : 'Great job on sleep duration! Focus on consistency for optimal recovery.'}`, | |
| strain: `Your daily strain is ${today.dailyStrain}/21. ${today.dailyStrain >= 15 ? 'This was a high-strain day. Ensure adequate recovery tomorrow.' : today.dailyStrain >= 10 ? 'Moderate strain - good balance of activity and recovery.' : 'Light strain day. Consider increasing activity intensity tomorrow.'}` | |
| }; | |
| return responses[prompt] || `I understand you're asking about ${prompt}. Based on your current metrics (Recovery: ${today.recoveryScore}%, Sleep: ${today.sleepDuration}h, Strain: ${today.dailyStrain}), I recommend focusing on consistent sleep patterns and balanced training intensity.`; | |
| } | |
| // Utility Functions | |
| function showNotification(message) { | |
| // Create notification element | |
| const notification = document.createElement('div'); | |
| notification.className = 'fixed bottom-4 right-4 bg-green-600 text-white px-6 py-3 rounded-lg shadow-lg z-50 animate-pulse'; | |
| notification.textContent = message; | |
| document.body.appendChild(notification); | |
| // Remove after 3 seconds | |
| setTimeout(() => { | |
| notification.remove(); | |
| }, 3000); | |
| } |