// Mock Data for 7 days
const mockData = {
dates: ["11/9", "11/10", "11/11", "11/12", "11/13", "11/14", "11/15"],
daily: [
{
date: "2024-11-09",
readinessScore: 75,
sleepScore: 80,
activityScore: 85,
rhr: 55,
hrv: 65,
tempDelta: 0.2,
sleepDuration: 400
},
{
date: "2024-11-10",
readinessScore: 88,
sleepScore: 91,
activityScore: 75,
rhr: 50,
hrv: 85,
tempDelta: -0.1,
sleepDuration: 480
},
{
date: "2024-11-11",
readinessScore: 65,
sleepScore: 72,
activityScore: 90,
rhr: 58,
hrv: 50,
tempDelta: 0.5,
sleepDuration: 390
},
{
date: "2024-11-12",
readinessScore: 90,
sleepScore: 85,
activityScore: 80,
rhr: 51,
hrv: 90,
tempDelta: 0.0,
sleepDuration: 450
},
{
date: "2024-11-13",
readinessScore: 85,
sleepScore: 90,
activityScore: 78,
rhr: 52,
hrv: 80,
tempDelta: -0.2,
sleepDuration: 470
},
{
date: "2024-11-14",
readinessScore: 70,
sleepScore: 75,
activityScore: 92,
rhr: 57,
hrv: 60,
tempDelta: 0.1,
sleepDuration: 420
},
{
date: "2024-11-15",
readinessScore: 92,
sleepScore: 95,
activityScore: 60,
rhr: 49,
hrv: 95,
tempDelta: -0.3,
sleepDuration: 500
}
]
};
let currentDayIndex = 6; // Start with the last day (today)
function updateDashboard() {
const currentData = mockData.daily[currentDayIndex];
const currentDate = mockData.dates[currentDayIndex];
// Update date
document.getElementById('currentDate').textContent = `November ${currentDate}, 2024`;
// Update score cards
updateScoreCard('readinessCard', currentData.readinessScore, 'readiness');
updateScoreCard('sleepCard', currentData.sleepScore, 'sleep');
updateScoreCard('activityCard', currentData.activityScore, 'activity');
// Update vitals
document.getElementById('rhrValue').textContent = currentData.rhr;
document.getElementById('hrvValue').textContent = currentData.hrv;
document.getElementById('tempValue').textContent = currentData.tempDelta;
// Update sleep details
const hours = Math.floor(currentData.sleepDuration / 60);
const minutes = currentData.sleepDuration % 60;
document.getElementById('totalSleep').textContent = `${hours}h ${minutes}m`;
document.getElementById('timeInBed').textContent = `${hours}h ${minutes + 30}m`;
document.getElementById('sleepEfficiency').textContent = `${currentData.sleepScore}%`;
// Update sleep stages
updateSleepStages();
// Update insights
updateInsights(currentData);
// Update charts
updateCharts();
}
function updateScoreCard(cardId, score, type) {
const card = document.getElementById(cardId);
if (!card) return;
let color, status;
if (score >= 85) {
color = 'green';
status = 'Optimal';
} else if (score >= 70) {
color = 'yellow';
status = 'Good';
} else {
color = 'red';
status = 'Pay Attention';
}
card.setAttribute('score', score);
card.setAttribute('status', status);
card.setAttribute('color', color);
}
function updateSleepStages() {
const stagesContainer = document.getElementById('sleepStages');
const stages = [
{ name: 'Deep Sleep', value: 20, class: 'sleep-stage-deep' },
{ name: 'REM Sleep', value: 25, class: 'sleep-stage-rem' },
{ name: 'Light Sleep', value: 55, class: 'sleep-stage-light' }
];
stagesContainer.innerHTML = stages.map(stage => `
${stage.name}
${stage.value}%
`).join('');
}
function updateInsights(data) {
const insights = [];
if (data.rhr < 52) {
insights.push("Your resting heart rate was lower than usual, indicating strong recovery. 💪");
}
if (data.readinessScore < 70) {
insights.push("Lower readiness today. Focus on light activity and prioritize rest. 🧘♂️");
}
if (data.sleepScore > 90) {
insights.push("Excellent sleep quality last night! Your body is well-recovered. 🌙✨");
}
if (data.hrv > 85) {
insights.push("High HRV detected - your nervous system is in great shape! 🎯");
}
if (insights.length === 0) {
insights.push("Your metrics are looking balanced. Keep up the good work! 📊");
}
document.getElementById('insightText').textContent = insights.join(" ");
}
function updateCharts() {
drawReadinessChart();
drawHrvChart();
}
function drawReadinessChart() {
const canvas = document.getElementById('readinessChart');
const ctx = canvas.getContext('2d');
const width = canvas.offsetWidth;
const height = 192;
canvas.width = width;
canvas.height = height;
ctx.clearRect(0, 0, width, height);
// Draw grid lines
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
ctx.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const y = (height / 4) * i;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
}
// Draw readiness score line
ctx.strokeStyle = '#10b981';
ctx.lineWidth = 2;
ctx.beginPath();
const readinessData = mockData.daily.map(d => d.readinessScore);
const xStep = width / (readinessData.length - 1);
readinessData.forEach((score, i) => {
const x = i * xStep;
const y = height - (score / 100) * height;
if (i === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
// Draw point
ctx.fillStyle = '#10b981';
ctx.beginPath();
ctx.arc(x, y, 4, 0, Math.PI * 2);
ctx.fill();
});
ctx.stroke();
// Draw RHR line
ctx.strokeStyle = '#ef4444';
ctx.lineWidth = 2;
ctx.beginPath();
const rhrData = mockData.daily.map(d => 100 - d.rhr); // Invert for better visualization
rhrData.forEach((value, i) => {
const x = i * xStep;
const y = height - (value / 100) * height;
if (i === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
// Draw point
ctx.fillStyle = '#ef4444';
ctx.beginPath();
ctx.arc(x, y, 4, 0, Math.PI * 2);
ctx.fill();
});
ctx.stroke();
// Draw date labels
ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
ctx.font = '11px sans-serif';
ctx.textAlign = 'center';
mockData.dates.forEach((date, i) => {
const x = i * xStep;
ctx.fillText(date, x, height - 5);
});
}
function drawHrvChart() {
const canvas = document.getElementById('hrvChart');
const ctx = canvas.getContext('2d');
const width = canvas.offsetWidth;
const height = 192;
canvas.width = width;
canvas.height = height;
ctx.clearRect(0, 0, width, height);
// Draw grid lines
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
ctx.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const y = (height / 4) * i;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
}
// Draw HRV line
ctx.strokeStyle = '#8b5cf6';
ctx.lineWidth = 2;
ctx.beginPath();
const hrvData = mockData.daily.map(d => d.hrv);
const xStep = width / (hrvData.length - 1);
hrvData.forEach((value, i) => {
const x = i * xStep;
const y = height - (value / 100) * height;
if (i === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
// Draw point
ctx.fillStyle = '#8b5cf6';
ctx.beginPath();
ctx.arc(x, y, 4, 0, Math.PI * 2);
ctx.fill();
});
ctx.stroke();
// Draw Temperature Delta line
ctx.strokeStyle = '#f59e0b';
ctx.lineWidth = 2;
ctx.beginPath();
const tempData = mockData.daily.map(d => (d.tempDelta + 1) * 50); // Normalize to 0-100 scale
tempData.forEach((value, i) => {
const x = i * xStep;
const y = height - (value / 100) * height;
if (i === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
// Draw point
ctx.fillStyle = '#f59e0b';
ctx.beginPath();
ctx.arc(x, y, 4, 0, Math.PI * 2);
ctx.fill();
});
ctx.stroke();
// Draw date labels
ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
ctx.font = '11px sans-serif';
ctx.textAlign = 'center';
mockData.dates.forEach((date, i) => {
const x = i * xStep;
ctx.fillText(date, x, height - 5);
});
}
// Event Listeners
document.getElementById('prevDay').addEventListener('click', () => {
if (currentDayIndex > 0) {
currentDayIndex--;
updateDashboard();
}
});
document.getElementById('nextDay').addEventListener('click', () => {
if (currentDayIndex < mockData.daily.length - 1) {
currentDayIndex++;
updateDashboard();
}
});
document.getElementById('weeklyView').addEventListener('click', function() {
this.classList.add('bg-purple-600', 'text-white');
this.classList.remove('bg-gray-700', 'text-gray-300');
document.getElementById('monthlyView').classList.remove('bg-purple-600', 'text-white');
document.getElementById('monthlyView').classList.add('bg-gray-700', 'text-gray-300');
updateCharts();
});
document.getElementById('monthlyView').addEventListener('click', function() {
this.classList.add('bg-purple-600', 'text-white');
this.classList.remove('bg-gray-700', 'text-gray-300');
document.getElementById('weeklyView').classList.remove('bg-purple-600', 'text-white');
document.getElementById('weeklyView').classList.add('bg-gray-700', 'text-gray-300');
// Simulate monthly view by regenerating with more data points
updateCharts();
});
// Initialize dashboard on load
document.addEventListener('DOMContentLoaded', () => {
updateDashboard();
});
// Handle window resize for responsive charts
window.addEventListener('resize', () => {
updateCharts();
});