Experiment other ways to get most played artist

This commit is contained in:
2018-03-20 22:33:05 +01:00
parent 92d9281c35
commit efac03a1c7
3 changed files with 111 additions and 6 deletions

View File

@@ -171,6 +171,57 @@
</table> </table>
</div> </div>
<div class="col-md-12">
<h3>Top Played Artist (Naive Way)</h3>
<!-- <div class="alert alert-info"> -->
<!-- <strong>Caution:</strong> In this list, artist with more than 10 artists are ignored. -->
<!-- </div> -->
<table class="table table-striped">
<thead>
<tr>
<th>Artist</th>
<th>Album Count</th>
<th>Track Count</th>
<th>Play Count</th>
<th>Average Play</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let artist of mostPlayedArtistsNaive">
<td><b>{{artist.Name}}</b></td>
<td>{{artist.Album.length}}</td>
<td>{{artist['Track Count']}}</td>
<td>{{artist['Play Count']}}</td>
<td>{{artist['Play Count'] / artist['Track Count']}}</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-12">
<h3>Top Played Artist (avg. play way)</h3>
<table class="table table-striped">
<thead>
<tr>
<th>Artist</th>
<th>Album Count</th>
<th>Track Count</th>
<th>Play Count</th>
<th>Average Play</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let artist of mostPlayedArtists">
<td><b>{{artist.Name}}</b></td>
<td>{{artist.Album.length}}</td>
<td>{{artist['Track Count']}}</td>
<td>{{artist['Play Count']}}</td>
<td>{{artist['Play Count'] / artist['Track Count']}}</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-6"> <div class="col-md-6">
<h3>Top Genres</h3> <h3>Top Genres</h3>
<table class="table table-striped"> <table class="table table-striped">

View File

@@ -30,6 +30,9 @@ export class DashboardComponent implements OnInit {
mostPlayedAlbums: Album[] = []; mostPlayedAlbums: Album[] = [];
mostPlayedAlbumsNaive: Album[] = []; mostPlayedAlbumsNaive: Album[] = [];
mostPlayedArtists: Artist[] = [];
mostPlayedArtistsNaive: Artist[] = [];
lastAddedAlbums: Bucket[] = []; lastAddedAlbums: Bucket[] = [];
albumArtists = []; albumArtists = [];
@@ -71,6 +74,19 @@ export class DashboardComponent implements OnInit {
// this.mostPlayedAlbums.splice // this.mostPlayedAlbums.splice
}); });
this.elsService.getMostPlayedArtistNaive()
.then(result => {
this.mostPlayedArtistsNaive = result;
});
this.elsService.getMostPlayedArtist().subscribe(result => {
result.forEach(artist => {
if (artist['Track Count'] > 10) {
this.mostPlayedArtists.push(artist);
}
});
});
this.elsService.getGenres().subscribe(data => this.topGenres = data); this.elsService.getGenres().subscribe(data => this.topGenres = data);
@@ -81,7 +97,7 @@ export class DashboardComponent implements OnInit {
const BreakException = {}; const BreakException = {};
this.elsService.getLastAddedAlbums(6).subscribe(buckets => { this.elsService.getLastAddedAlbums(6).subscribe(buckets => {
buckets.forEach(bucket => { buckets.forEach(bucket => {
console.log(bucket); // console.log(bucket);
if (lastAddedAlbumsTemp.length === 0) { if (lastAddedAlbumsTemp.length === 0) {
lastAddedAlbumsTemp.push(bucket); lastAddedAlbumsTemp.push(bucket);
@@ -99,7 +115,7 @@ export class DashboardComponent implements OnInit {
} }
}); });
// console.log("alors"); // console.log("alors");
console.log(lastAddedAlbumsTemp); // console.log(lastAddedAlbumsTemp);
this.lastAddedAlbums = lastAddedAlbumsTemp; this.lastAddedAlbums = lastAddedAlbumsTemp;
this.lastAddedAlbums.forEach(bucket => this.getArtistName(bucket)); this.lastAddedAlbums.forEach(bucket => this.getArtistName(bucket));

View File

@@ -128,9 +128,6 @@ export class ElsService {
.post(this.elsUrl + 'album' + ElsService.ACTION_SEARCH, .post(this.elsUrl + 'album' + ElsService.ACTION_SEARCH,
JSON.stringify({ JSON.stringify({
'sort': [ 'sort': [
{
'Play Count': 'desc'
},
{ {
'_script': { '_script': {
'type': 'number', 'type': 'number',
@@ -145,6 +142,35 @@ export class ElsService {
.map(res => this.responseToAlbums(res)); .map(res => this.responseToAlbums(res));
} }
getMostPlayedArtistNaive(): Promise<Artist[]> {
return this.http
.get(this.elsUrl + 'artist' + ElsService.ACTION_SEARCH + '?sort=Play Count:desc&size=20')
.toPromise()
.then(res => this.responseToAlbums(res))
.catch(this.handleError);
// TODO Excluse 'Divers' + compilation
}
getMostPlayedArtist(): Observable<Artist[]> {
return this.http
.post(this.elsUrl + 'artist' + ElsService.ACTION_SEARCH,
JSON.stringify({
'sort': [
{
'_script': {
'type': 'number',
'script': {
'inline': 'doc[\'Play Count\'].value / doc[\'Track Count\'].value'
},
'order': 'desc'
}
},
],
'size': 100
}), {headers: this.headers})
.map(res => this.responseToArtists(res));
}
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> { getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from); console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from);
return this.http return this.http
@@ -358,7 +384,7 @@ export class ElsService {
return result; return result;
} }
/** Process a response to a array of songs. /** Process a response to a array of songs.
* *
* @param res Response to process * @param res Response to process
*/ */
@@ -370,6 +396,18 @@ export class ElsService {
return result; return result;
} }
/** Process a response to a array of songs.
*
* @param res Response to process
*/
private responseToArtists(res: Response): Artist[] {
const result: Array<Artist> = [];
res.json().hits.hits.forEach((hit) => {
result.push(hit._source);
});
return result;
}
/** Process an aggregation response to an array of Bucket. /** Process an aggregation response to an array of Bucket.
* *