Naive approche to get most played album
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user