Naive approche to get most played album

This commit is contained in:
2018-02-10 01:06:58 +01:00
parent 6e323c39c7
commit b307b88ef1
3 changed files with 59 additions and 0 deletions

View File

@@ -120,6 +120,31 @@
</table>
</div>
<div class="col-md-12">
<h3>Top Played Album</h3>
<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 mostPlayedAlbums">
<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>
<!-- 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>
</div>
<div class="col-md-6">
<h3>Top Genres</h3>
<table class="table table-striped">

View File

@@ -27,6 +27,8 @@ export class DashboardComponent implements OnInit {
mostPlayedSongs: Song[] = [];
mostPlayedAlbums: Album[] = [];
lastAddedAlbums: Bucket[] = [];
albumArtists = [];
@@ -53,6 +55,16 @@ 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.getGenres().subscribe(data => this.topGenres = data);
this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data);
// this.elsService.getGenreCount().subscribe(data => console.log(data));

View File

@@ -114,6 +114,15 @@ export class ElsService {
.map(res => this.responseToSongs(res));
}
getMostPlayedAlbum(): Promise<Album[]> {
return this.http
.get(this.elsUrl + 'album' + ElsService.ACTION_SEARCH + '?sort=Play Count:desc&size=20')
.toPromise()
.then(res => this.responseToAlbums(res))
.catch(this.handleError);
// TODO Excluse 'Divers' + compilation
}
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from);
return this.http
@@ -327,6 +336,19 @@ export class ElsService {
return result;
}
/** Process a response to a array of songs.
*
* @param res Response to process
*/
private responseToAlbums(res: Response): Album[] {
const result: Array<Album> = [];
res.json().hits.hits.forEach((hit) => {
result.push(hit._source);
});
return result;
}
/** Process an aggregation response to an array of Bucket.
*
* @param res Response to process