From 5ea4732c2904f3f5caecc6880d4f92ef38ca112c Mon Sep 17 00:00:00 2001 From: pavel Date: Wed, 17 Apr 2024 13:49:48 +0300 Subject: [PATCH] Add another pie chart by last time updated --- index.html | 5 +++++ js/app.controller.js | 4 +++- js/services/loc.service.js | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 7ad53b7..1673d18 100644 --- a/index.html +++ b/index.html @@ -63,6 +63,11 @@

By rate:

+
+

By last update:

+
+ +
diff --git a/js/app.controller.js b/js/app.controller.js index 65d92bc..c99a7ce 100644 --- a/js/app.controller.js +++ b/js/app.controller.js @@ -254,6 +254,9 @@ function renderLocStats() { locService.getLocCountByRateMap().then(stats => { handleStats(stats, 'loc-stats-rate') }) + locService.getLocCountBylastUpdated().then(stats => { + handleStats(stats, 'loc-stats-lastUpdated') + }) } function handleStats(stats, selector) { @@ -261,7 +264,6 @@ function handleStats(stats, selector) { // stats = { low: 5, medium: 5, high: 5, baba: 55, mama: 30, total: 100 } const labels = cleanStats(stats) const colors = utilService.getColors() - var sumPercent = 0 var colorsStr = `${colors[0]} ${0}%, ` labels.forEach((label, idx) => { diff --git a/js/services/loc.service.js b/js/services/loc.service.js index 37a96c5..c6f95c0 100644 --- a/js/services/loc.service.js +++ b/js/services/loc.service.js @@ -30,7 +30,8 @@ export const locService = { save, setFilterBy, setSortBy, - getLocCountByRateMap + getLocCountByRateMap, + getLocCountBylastUpdated } function query() { @@ -105,6 +106,21 @@ function getLocCountByRateMap() { }) } +function getLocCountBylastUpdated() { + return storageService.query(DB_KEY) + .then(locs => { + const locCountByUpdate = locs.reduce((map, loc) => { + if (utilService.elapsedTime(loc.updatedAt) === 'just now') map['just Now']++ + else if (utilService.elapsedTime(loc.updatedAt) === 'last hour') map['last Hour']++ + else if (utilService.elapsedTime(loc.updatedAt) === 'today') map.today++ + else map['more then a day']++ + return map + }, { "just Now": 0, "last Hour": 0, today: 0, "more then a day": 0 }) + locCountByUpdate.total = locs.length + return locCountByUpdate + }) +} + function setSortBy(sortBy = {}) { gSortBy = sortBy }