Add a better way for most listen album
This commit is contained in:
@@ -121,7 +121,34 @@
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<h3>Top Played Album</h3>
|
||||
<h3>Top Played Album (Naive Way)</h3>
|
||||
<div class="alert alert-info">
|
||||
<strong>Caution:</strong> In this list, albums with more than 10 artists are ignored.
|
||||
</div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Album</th>
|
||||
<th>Artist Name</th>
|
||||
<th>Track Count</th>
|
||||
<th>Play Count</th>
|
||||
<th>Average Play</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let album of mostPlayedAlbumsNaive">
|
||||
<td><b>{{album.Name}}</b></td>
|
||||
<td>{{album['Album Artist'] ? album['Album Artist'] : album.Artist}}</td>
|
||||
<td>{{album['Track Count']}}</td>
|
||||
<td>{{album['Play Count']}}</td>
|
||||
<td>{{album['Play Count'] / album['Track Count']}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<h3>Top Played Album (avg. play way)</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -139,7 +166,6 @@
|
||||
<td>{{album['Track Count']}}</td>
|
||||
<td>{{album['Play Count']}}</td>
|
||||
<td>{{album['Play Count'] / album['Track Count']}}</td>
|
||||
<!-- TODO It was at this moment, Jackson knew it's better to use avg. play count rather than just play count (or both) -->
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -28,6 +28,7 @@ export class DashboardComponent implements OnInit {
|
||||
mostPlayedSongs: Song[] = [];
|
||||
|
||||
mostPlayedAlbums: Album[] = [];
|
||||
mostPlayedAlbumsNaive: Album[] = [];
|
||||
|
||||
lastAddedAlbums: Bucket[] = [];
|
||||
albumArtists = [];
|
||||
@@ -55,15 +56,22 @@ export class DashboardComponent implements OnInit {
|
||||
data => this.mostPlayedSongs = data
|
||||
);
|
||||
|
||||
this.elsService.getMostPlayedAlbum()
|
||||
.then(result => {
|
||||
result.forEach(album => {
|
||||
if (album.Artist.length <= 10) {
|
||||
this.mostPlayedAlbums.push(album);
|
||||
}
|
||||
});
|
||||
|
||||
this.elsService.getMostPlayedAlbumNaive()
|
||||
.then(result => {
|
||||
result.forEach(album => {
|
||||
if (album.Artist.length <= 10) {
|
||||
this.mostPlayedAlbumsNaive.push(album);
|
||||
}
|
||||
});
|
||||
this.mostPlayedAlbumsNaive.splice(10, this.mostPlayedAlbumsNaive.length);
|
||||
});
|
||||
|
||||
this.elsService.getMostPlayedAlbum().subscribe(result => {
|
||||
this.mostPlayedAlbums = result;
|
||||
// this.mostPlayedAlbums.splice
|
||||
});
|
||||
|
||||
|
||||
|
||||
this.elsService.getGenres().subscribe(data => this.topGenres = data);
|
||||
this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data);
|
||||
|
||||
@@ -114,7 +114,7 @@ export class ElsService {
|
||||
.map(res => this.responseToSongs(res));
|
||||
}
|
||||
|
||||
getMostPlayedAlbum(): Promise<Album[]> {
|
||||
getMostPlayedAlbumNaive(): Promise<Album[]> {
|
||||
return this.http
|
||||
.get(this.elsUrl + 'album' + ElsService.ACTION_SEARCH + '?sort=Play Count:desc&size=20')
|
||||
.toPromise()
|
||||
@@ -123,6 +123,28 @@ export class ElsService {
|
||||
// TODO Excluse 'Divers' + compilation
|
||||
}
|
||||
|
||||
getMostPlayedAlbum(): Observable<Album[]> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'album' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'sort': [
|
||||
{
|
||||
'Play Count': 'desc'
|
||||
},
|
||||
{
|
||||
'_script': {
|
||||
'type': 'number',
|
||||
'script': {
|
||||
'inline': 'doc[\'Play Count\'].value / doc[\'Track Count\'].value'
|
||||
},
|
||||
'order': 'desc'
|
||||
}
|
||||
}
|
||||
]
|
||||
}), {headers: this.headers})
|
||||
.map(res => this.responseToAlbums(res));
|
||||
}
|
||||
|
||||
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
|
||||
console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from);
|
||||
return this.http
|
||||
|
||||
Reference in New Issue
Block a user