From 69698f673979c8a83fe75e1d6fc66b5e64e4729a Mon Sep 17 00:00:00 2001 From: aj Date: Sun, 20 Oct 2019 16:32:10 +0100 Subject: [PATCH] added album and artist stats --- music/tasks/refresh_lastfm_stats.py | 18 ++++++++-- src/js/Maths/PieChart.js | 2 +- src/js/Playlist/View/Count.js | 56 +++++++++++++++++++++++------ 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/music/tasks/refresh_lastfm_stats.py b/music/tasks/refresh_lastfm_stats.py index ba71f32..fb80bab 100644 --- a/music/tasks/refresh_lastfm_stats.py +++ b/music/tasks/refresh_lastfm_stats.py @@ -24,13 +24,25 @@ def refresh_lastfm_stats(username, playlist_name): database_ref = database.get_user_playlist_ref_by_username(user=username, playlist=playlist_name) playlist_dict = database_ref.get().to_dict() - count = counter.count(Uri(playlist_dict['uri'])) + + spotify_playlist = spotnet.get_playlist(uri=Uri(playlist_dict['uri'])) + track_count = counter.count_playlist(playlist=spotify_playlist) + album_count = counter.count_playlist(playlist=spotify_playlist, query_album=True) + artist_count = counter.count_playlist(playlist=spotify_playlist, query_artist=True) user_count = fmnet.get_user_scrobble_count() - percent = round((count * 100) / user_count, 2) + percent = round((track_count * 100) / user_count, 2) + album_percent = round((album_count * 100) / user_count, 2) + artist_percent = round((artist_count * 100) / user_count, 2) database_ref.update({ - 'lastfm_stat_count': count, + 'lastfm_stat_count': track_count, + 'lastfm_stat_album_count': album_count, + 'lastfm_stat_artist_count': artist_count, + 'lastfm_stat_percent': percent, + 'lastfm_stat_album_percent': album_percent, + 'lastfm_stat_artist_percent': artist_percent, + 'lastfm_stat_last_refresh': datetime.utcnow() }) diff --git a/src/js/Maths/PieChart.js b/src/js/Maths/PieChart.js index 88d0563..d123037 100644 --- a/src/js/Maths/PieChart.js +++ b/src/js/Maths/PieChart.js @@ -21,7 +21,7 @@ class PieChart extends Component { }, options: { legend : { - display : false + display : true }, elements: { arc : { diff --git a/src/js/Playlist/View/Count.js b/src/js/Playlist/View/Count.js index 4edec69..2af87b0 100644 --- a/src/js/Playlist/View/Count.js +++ b/src/js/Playlist/View/Count.js @@ -9,6 +9,17 @@ class Count extends Component { constructor(props){ super(props); this.state = { + playlist: { + lastfm_stat_album_count: 0, + lastfm_stat_artist_count: 0, + lastfm_stat_count: 0, + + lastfm_stat_album_percent: 0, + lastfm_stat_artist_percent: 0, + lastfm_stat_percent: 0, + + lastfm_stat_last_refresh: '' + }, name: props.name, lastfm_refresh: 'never', lastfm_percent: 0, @@ -25,9 +36,7 @@ class Count extends Component { .then((response) => { if(response.data.lastfm_stat_last_refresh != undefined){ this.setState({ - count: response.data.lastfm_stat_count, - lastfm_refresh: response.data.lastfm_stat_last_refresh, - lastfm_percent: response.data.lastfm_stat_percent, + playlist: response.data, isLoading: false }) }else{ @@ -57,24 +66,51 @@ class Count extends Component { return ( - scrobble count: {this.state.count.toLocaleString()} + scrobble count: {this.state.playlist.lastfm_stat_count.toLocaleString()} / {this.state.playlist.lastfm_stat_percent}% - that's {this.state.lastfm_percent}% of all scrobbles + album count: {this.state.playlist.lastfm_stat_album_count.toLocaleString()} / {this.state.playlist.lastfm_stat_album_percent}% - last updated {this.state.lastfm_refresh.toLocaleString()} + artist count: {this.state.playlist.lastfm_stat_artist_count.toLocaleString()} / {this.state.playlist.lastfm_stat_artist_percent}% + + + last updated {this.state.playlist.lastfm_stat_last_refresh.toLocaleString()} + title={this.state.playlist.name}/> + + + + + + + + + +