diff --git a/dashboard/src/app/dashboard.component.html b/dashboard/src/app/dashboard.component.html
index 0b29d14..3be7618 100644
--- a/dashboard/src/app/dashboard.component.html
+++ b/dashboard/src/app/dashboard.component.html
@@ -171,6 +171,57 @@
+
+
Top Played Artist (Naive Way)
+
+
+
+
+
+
+ | Artist |
+ Album Count |
+ Track Count |
+ Play Count |
+ Average Play |
+
+
+
+
+ | {{artist.Name}} |
+ {{artist.Album.length}} |
+ {{artist['Track Count']}} |
+ {{artist['Play Count']}} |
+ {{artist['Play Count'] / artist['Track Count']}} |
+
+
+
+
+
+
+
Top Played Artist (avg. play way)
+
+
+
+ | Artist |
+ Album Count |
+ Track Count |
+ Play Count |
+ Average Play |
+
+
+
+
+ | {{artist.Name}} |
+ {{artist.Album.length}} |
+ {{artist['Track Count']}} |
+ {{artist['Play Count']}} |
+ {{artist['Play Count'] / artist['Track Count']}} |
+
+
+
+
+
Top Genres
diff --git a/dashboard/src/app/dashboard.component.ts b/dashboard/src/app/dashboard.component.ts
index a91be23..0b36e5e 100644
--- a/dashboard/src/app/dashboard.component.ts
+++ b/dashboard/src/app/dashboard.component.ts
@@ -30,6 +30,9 @@ export class DashboardComponent implements OnInit {
mostPlayedAlbums: Album[] = [];
mostPlayedAlbumsNaive: Album[] = [];
+ mostPlayedArtists: Artist[] = [];
+ mostPlayedArtistsNaive: Artist[] = [];
+
lastAddedAlbums: Bucket[] = [];
albumArtists = [];
@@ -71,6 +74,19 @@ export class DashboardComponent implements OnInit {
// 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);
@@ -81,7 +97,7 @@ export class DashboardComponent implements OnInit {
const BreakException = {};
this.elsService.getLastAddedAlbums(6).subscribe(buckets => {
buckets.forEach(bucket => {
- console.log(bucket);
+ // console.log(bucket);
if (lastAddedAlbumsTemp.length === 0) {
lastAddedAlbumsTemp.push(bucket);
@@ -99,7 +115,7 @@ export class DashboardComponent implements OnInit {
}
});
// console.log("alors");
- console.log(lastAddedAlbumsTemp);
+ // console.log(lastAddedAlbumsTemp);
this.lastAddedAlbums = lastAddedAlbumsTemp;
this.lastAddedAlbums.forEach(bucket => this.getArtistName(bucket));
diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts
index e75559a..650ae8a 100644
--- a/dashboard/src/app/els.service.ts
+++ b/dashboard/src/app/els.service.ts
@@ -128,9 +128,6 @@ export class ElsService {
.post(this.elsUrl + 'album' + ElsService.ACTION_SEARCH,
JSON.stringify({
'sort': [
- {
- 'Play Count': 'desc'
- },
{
'_script': {
'type': 'number',
@@ -145,6 +142,35 @@ export class ElsService {
.map(res => this.responseToAlbums(res));
}
+ getMostPlayedArtistNaive(): Promise {
+ 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 {
+ 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 {
console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from);
return this.http
@@ -358,7 +384,7 @@ export class ElsService {
return result;
}
- /** Process a response to a array of songs.
+ /** Process a response to a array of songs.
*
* @param res Response to process
*/
@@ -370,6 +396,18 @@ export class ElsService {
return result;
}
+ /** Process a response to a array of songs.
+ *
+ * @param res Response to process
+ */
+ private responseToArtists(res: Response): Artist[] {
+ const result: Array = [];
+ res.json().hits.hits.forEach((hit) => {
+ result.push(hit._source);
+ });
+ return result;
+ }
+
/** Process an aggregation response to an array of Bucket.
*