chore: update books; consistent sorting for music

This commit is contained in:
Cory Dransfeldt 2024-05-21 19:16:51 -07:00
parent 43e22f5027
commit c2f2a399cb
No known key found for this signature in database
2 changed files with 6 additions and 4 deletions

View file

@ -10790,7 +10790,7 @@
"categories": [ "categories": [
"Biography & Autobiography" "Biography & Autobiography"
], ],
"thumbnail": "https://books.google.com/books/content?id=f8LrtwEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api&w=512", "thumbnail": "https://coryd.dev/media/books/1573449709-see-a-little-light.jpg",
"language": "en", "language": "en",
"link": "https://books.google.com/books/about/See_a_Little_Light.html?hl=&id=f8LrtwEACAAJ" "link": "https://books.google.com/books/about/See_a_Little_Light.html?hl=&id=f8LrtwEACAAJ"
} }

View file

@ -58,8 +58,9 @@ const fetchAllTimeData = async (fields, table) => {
return rows return rows
} }
const aggregateData = (data, groupByField, groupByType, sort = true) => { const aggregateData = (data, groupByField, groupByType) => {
const aggregation = {} const aggregation = {}
data.forEach(item => { data.forEach(item => {
const key = item[groupByField] const key = item[groupByField]
if (!aggregation[key]) { if (!aggregation[key]) {
@ -92,7 +93,8 @@ const aggregateData = (data, groupByField, groupByType, sort = true) => {
} }
aggregation[key].plays++ aggregation[key].plays++
}) })
const aggregatedData = sort ? Object.values(aggregation).sort((a, b) => b.plays - a.plays) : Object.values(aggregation)
const aggregatedData = Object.values(aggregation).sort((a, b) => b.plays - a.plays)
aggregatedData.forEach((item, index) => { aggregatedData.forEach((item, index) => {
item.rank = index + 1 item.rank = index + 1
@ -158,7 +160,7 @@ export default async function() {
artists: aggregateData(recentData, 'artist_name', 'artists'), artists: aggregateData(recentData, 'artist_name', 'artists'),
albums: aggregateData(recentData, 'album_name', 'albums'), albums: aggregateData(recentData, 'album_name', 'albums'),
tracks: aggregateData(recentData, 'track_name', 'track'), tracks: aggregateData(recentData, 'track_name', 'track'),
tracksChronological: aggregateData(recentData, 'track_name', 'track', false), tracksChronological: aggregateData(recentData, 'track_name', 'track').sort((a, b) => b.timestamp - a.timestamp),
genres: aggregateGenres(recentData), genres: aggregateGenres(recentData),
totalTracks: recentData?.length?.toLocaleString('en-US') totalTracks: recentData?.length?.toLocaleString('en-US')
} }