Spaces:
Running
Running
File size: 11,201 Bytes
152c583 | 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 386 387 388 389 390 391 392 393 | // 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 => `
<div class="space-y-1">
<div class="flex justify-between text-sm">
<span class="text-gray-400">${stage.name}</span>
<span>${stage.value}%</span>
</div>
<div class="sleep-stage-bar">
<div class="${stage.class}" style="width: ${stage.value}%; height: 100%; transition: width 0.5s ease;"></div>
</div>
</div>
`).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();
}); |