Daily Wellness & Productivity Log
Weekly Overview & Insights
Overview for Week:
Weekly Averages (1-5 Scale):
Average Productivity Level: N/A
Average Scores Visualized:
Reflections on Your Week:
Daily Logs for the Week:
No logs found for this week.
Select a week and click "Analyze Week" to view your overview.
Log for ${new Date(dateKey+'T00:00:00Z').toLocaleDateString()} loaded. You can edit and re-save.
`; } else { mpbTodayLogDisplayEl.innerHTML = `No log for ${new Date(dateKey+'T00:00:00Z').toLocaleDateString()} yet. Fill the form to save.
`; } if(mpbDailyLogSavedMessageEl) mpbDailyLogSavedMessageEl.style.display = 'none'; } function mpbHandleDailyLogSubmit(e) { e.preventDefault(); const dateKey = mpbLogDateEl.value; if (!dateKey) { alert("Please select a date."); return; } const wellnessScores = {}; mpbWellnessFactorDefs.forEach(factor => { wellnessScores[factor.id] = parseInt(document.getElementById(`factor-${factor.id}`).value); }); mpbDailyLogs[dateKey] = { date: dateKey, wellnessScores: wellnessScores, productivityLevel: parseInt(mpbProductivityLevelEl.value), notes: mpbContextualNotesEl.value.trim() }; mpbSaveDailyLogs(); if(mpbDailyLogSavedMessageEl){ mpbDailyLogSavedMessageEl.textContent = `Log for ${new Date(dateKey+'T00:00:00Z').toLocaleDateString()} saved!`; mpbDailyLogSavedMessageEl.style.display = 'block'; setTimeout(() => { if(mpbDailyLogSavedMessageEl) mpbDailyLogSavedMessageEl.style.display = 'none'; }, 3000); } mpbLoadLogForDate(); } function mpbGetWeekDates(selectedDateStr) { const d = new Date(selectedDateStr + 'T00:00:00'); d.setHours(0,0,0,0); const day = d.getDay(); const diffToMonday = day === 0 ? -6 : 1 - day; const monday = new Date(d); monday.setDate(d.getDate() + diffToMonday); const sunday = new Date(monday); sunday.setDate(monday.getDate() + 6); return { start: monday, end: sunday }; } function mpbGenerateWeeklyOverview() { if (!mpbReviewWeekDateEl || !mpbSelectedReviewWeekDisplayEl || !mpbWeeklyOverviewAreaEl || !mpbLogHistoryTableBodyEl || !mpbNoLogsForWeekMessageEl || !mpbNoOverviewDataMessageEl || !mpbWeeklyAveragesDisplayEl || !mpbAvgProdValueEl || !mpbCorrelationInsightsEl || !mpbDownloadReportBtnEl || !mpbFactorAverageScoresChartEl) return; const selectedDateStr = mpbReviewWeekDateEl.value; if (!selectedDateStr) { mpbNoOverviewDataMessageEl.textContent = "Please select a date for the week to review."; mpbNoOverviewDataMessageEl.style.display = 'block'; mpbWeeklyOverviewAreaEl.style.display = 'none'; return; } const weekDates = mpbGetWeekDates(selectedDateStr); mpbSelectedReviewWeekDisplayEl.textContent = `${weekDates.start.toLocaleDateString()} - ${weekDates.end.toLocaleDateString()}`; const logsForWeek = []; let currentDateIter = new Date(weekDates.start); while (currentDateIter <= weekDates.end) { const dateKey = currentDateIter.toISOString().slice(0,10); if (mpbDailyLogs[dateKey]) { logsForWeek.push(mpbDailyLogs[dateKey]); } currentDateIter.setDate(currentDateIter.getDate() + 1); } while(mpbLogHistoryTableBodyEl.firstChild) mpbLogHistoryTableBodyEl.removeChild(mpbLogHistoryTableBodyEl.firstChild); if(mpbLogHistoryTableHeaderRowEl) { mpbLogHistoryTableHeaderRowEl.innerHTML = ''; let th = mpbLogHistoryTableHeaderRowEl.insertCell(); th.textContent = "Date"; mpbWellnessFactorDefs.forEach(f => { th = mpbLogHistoryTableHeaderRowEl.insertCell(); th.textContent = f.label.split(' ')[0]; }); th = mpbLogHistoryTableHeaderRowEl.insertCell(); th.textContent = "Productivity"; th = mpbLogHistoryTableHeaderRowEl.insertCell(); th.textContent = "Notes"; } if (logsForWeek.length === 0) { mpbNoLogsForWeekMessageEl.style.display = 'block'; mpbWeeklyAveragesDisplayEl.innerHTML = 'N/A
'; mpbAvgProdValueEl.textContent = 'N/A'; mpbFactorAverageScoresChartEl.innerHTML = 'No data for chart.
'; mpbCorrelationInsightsEl.innerHTML = 'No daily logs found for this week to generate insights.
${f.label}: ${avg.toFixed(1)}
`; factorAveragesForChart.push({label: f.label, value: avg, type: 'wellness'}); }); mpbWeeklyAveragesDisplayEl.innerHTML = avgWellnessHTML; const avgProd = productivityCount > 0 ? (totalProductivitySum / productivityCount) : 0; mpbAvgProdValueEl.textContent = avgProd.toFixed(1); factorAveragesForChart.push({label: "Productivity", value: avgProd, type: 'productivity'}); mpbRenderSimpleBarChart(factorAveragesForChart); let insightsHTML = '- ';
const avgProdNum = parseFloat(avgProd);
mpbWellnessFactorDefs.forEach(f => {
const avgFactorScore = weeklyAverages[f.id].count > 0 ? (weeklyAverages[f.id].sum / weeklyAverages[f.id].count) : null;
if(avgFactorScore !== null && !isNaN(avgProdNum) && logsForWeek.length > 2) { // Need a few days for meaningful observation
let highWellnessHighProdDays = 0; let lowWellnessLowProdDays = 0;
logsForWeek.forEach(log => {
if(log.wellnessScores[f.id] >= 4 && log.productivityLevel >=4) highWellnessHighProdDays++;
if(log.wellnessScores[f.id] <= 2 && log.productivityLevel <=2) lowWellnessLowProdDays++;
});
if (highWellnessHighProdDays >= logsForWeek.length * 0.4) { // If 40%+ days had this strong positive correlation
insightsHTML += `
- A number of days this week showed high '${f.label}' coinciding with high 'Productivity'. What elements contributed to these positive days? `; } if (lowWellnessLowProdDays >= logsForWeek.length * 0.4) { insightsHTML += `
- On several days, lower '${f.label}' appeared alongside lower 'Productivity'. Exploring the notes for these days might offer insights. `; } } }); if(logsForWeek.filter(log => log.notes && (log.notes.toLowerCase().includes("stress") || log.notes.toLowerCase().includes("pressure") || log.notes.toLowerCase().includes("overwhelm"))).length >= Math.max(1, logsForWeek.length * 0.2) ){ // If stress mentioned on at least 20% of days (min 1) insightsHTML += `
- Your notes mentioned terms like 'stress', 'pressure', or 'overwhelm' this week. How did these instances align with your wellness and productivity ratings on those specific days? `; } if (avgProdNum >= 4 && avgWellnessHTML.includes("Sleep: ") && parseFloat(avgWellnessHTML.split("Sleep: ")[1].split("")[0]) >= 4) { insightsHTML += `
- High average productivity this week seems to align with good average sleep quality. This is often a positive pattern. `; } if (avgProdNum <= 2 && avgWellnessHTML.includes("Energy Level: ") && parseFloat(avgWellnessHTML.split("Energy Level: ")[1].split("")[0]) <= 2) { insightsHTML += `
- Lower average productivity this week appears alongside lower average energy levels. What might have influenced your energy? `; } if(insightsHTML === '
- Reflect on your daily entries. What connections do you see between your wellness scores, productivity levels, and the day\'s events or notes? '; insightsHTML += '
- ') insightsHTML += '
