Skip to content

Commit

Permalink
Add feature Show distance to locations when user-position is known
Browse files Browse the repository at this point in the history
  • Loading branch information
natia-cohen committed Apr 17, 2024
2 parents cd40a97 + 5ea4732 commit 22f3849
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ <h4>By rate:</h4>
<div class="pie"></div>
<ul class="legend"></ul>
</div>
<div class="loc-stats-lastUpdated">
<h4>By last update:</h4>
<div class="pie"></div>
<ul class="legend"></ul>
</div>
</section>
</section>
</div>
Expand Down
4 changes: 3 additions & 1 deletion js/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,16 @@ function renderLocStats() {
locService.getLocCountByRateMap().then(stats => {
handleStats(stats, 'loc-stats-rate')
})
locService.getLocCountBylastUpdated().then(stats => {
handleStats(stats, 'loc-stats-lastUpdated')
})
}

function handleStats(stats, selector) {
// stats = { low: 37, medium: 11, high: 100, total: 148 }
// 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) => {
Expand Down
16 changes: 16 additions & 0 deletions js/services/loc.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const locService = {
setFilterBy,
setSortBy,
getLocCountByRateMap,
getLocCountBylastUpdated,
}

function query() {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 22f3849

Please sign in to comment.