From dc67e355bab04d5a28f9b6a9a5e68ccee0398717 Mon Sep 17 00:00:00 2001 From: AmberLz Date: Thu, 26 Oct 2023 14:44:57 +0200 Subject: [PATCH] Update tab-statistics.page.ts --- .../app/tab-statistics/tab-statistics.page.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.ts b/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.ts index 077bea93..7b421f6c 100644 --- a/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.ts +++ b/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.ts @@ -83,15 +83,23 @@ export class TabStatisticsPage implements OnInit { processDoughnutChart(data: any) { // Get today's day name (e.g., "Mon", "Tue", etc.) + const today = new Date().toLocaleDateString('en-US', { weekday: 'short' }); + //const today = "Wed"; + //console.log("WEDNESDAY", data.result.perDayTimes["Wed"]); // Get the on and off values for today's day from the data - const todayOnValue = data.result.perDayTimes[today]?.on || 0; - const todayOffValue = data.result.perDayTimes[today]?.off || 0; + let uptimeToday = 24; + let downtimeToday = 0; + if (data.result.perDayTimes[today] != undefined) { + const todayOnValue = data.result.perDayTimes[today]?.on || 0; + const todayOffValue = data.result.perDayTimes[today]?.off || 0; + + // Convert total uptime and downtime to hours + uptimeToday = Math.floor(todayOnValue / 60); + downtimeToday = Math.floor(todayOffValue / 60); + } - // Convert total uptime and downtime to hours - const uptimeToday = Math.floor(todayOnValue / 60); - const downtimeToday = Math.floor(todayOffValue / 60); // Data for Doughnut Chart (Uptime/Downtime for Today) const doughnutData = {