From 9e707c9d4dc932d57c41093d55a55d5bfbf1d139 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Mon, 9 Dec 2024 02:26:37 +0300 Subject: [PATCH] added stats --- src/app.js | 16 ++++++++++++++++ src/index.html | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index b45f7e0..f2f7701 100644 --- a/src/app.js +++ b/src/app.js @@ -124,6 +124,22 @@ function showChart(selectedMonth) { }, }, }); + + updateStats(data.poppersData[year][month]); +} + +function updateStats(breaths) { + const breathMonth = document.getElementById('breathMonth'); + const breathAverage = document.getElementById('breathAverage'); + + let totalBreathInMonth = 0; + let daysCount = 0; + for (const [key, value] of Object.entries(breaths)) { + totalBreathInMonth += value.length; + daysCount += 1; + } + breathMonth.value = totalBreathInMonth; + breathAverage.value = Math.round(totalBreathInMonth / daysCount); } /* Внешний HTML Tooltip | Потом изменить */ diff --git a/src/index.html b/src/index.html index 5affebc..2160802 100644 --- a/src/index.html +++ b/src/index.html @@ -19,7 +19,7 @@
-

График

+

Дата

+
+
+ Среднее количество вдыханий за сутки + +
+