diff --git a/dashboard/src/app/dashboard.component.html b/dashboard/src/app/dashboard.component.html
index 68876bd..40c7773 100644
--- a/dashboard/src/app/dashboard.component.html
+++ b/dashboard/src/app/dashboard.component.html
@@ -98,4 +98,39 @@
+
+
+
Top Genres
+
+
+
+ | Genre |
+ Track Count |
+
+
+
+
+ | {{genre.key}} |
+ {{genre.doc_count}} |
+
+
+
+
+
+
Bottom Genres
+
+
+
+ | Genre |
+ Track Count |
+
+
+
+
+ | {{genre.key}} |
+ {{genre.doc_count}} |
+
+
+
+
\ No newline at end of file
diff --git a/dashboard/src/app/dashboard.component.ts b/dashboard/src/app/dashboard.component.ts
index 6e6c56b..9b368b7 100644
--- a/dashboard/src/app/dashboard.component.ts
+++ b/dashboard/src/app/dashboard.component.ts
@@ -21,6 +21,9 @@ export class DashboardComponent implements OnInit {
trackCountAlbum: number = 0;
neverListenSong: number = 0;
+ topGenres: Bucket[] = [];
+ bottomGenres: Bucket[] = [];
+
mostPlayedSongs: Song[] = [];
constructor(private elsService: ElsService) { }
@@ -48,6 +51,10 @@ export class DashboardComponent implements OnInit {
this.elsService.getMostPlayedTrack().subscribe(
data => this.mostPlayedSongs = data
);
+
+ 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));
}
diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts
index c35c9c5..8db6400 100644
--- a/dashboard/src/app/els.service.ts
+++ b/dashboard/src/app/els.service.ts
@@ -8,6 +8,7 @@ import 'rxjs/add/operator/map';
import { Song } from './object/song';
import { Album } from './object/album';
import { Artist } from './object/artist';
+import { Bucket } from './object/bucket';
@Injectable()
export class ElsService {
@@ -196,6 +197,53 @@ export class ElsService {
});
}
+ getGenres(ordering: string = 'desc'): Observable {
+ return this.http
+ .post(this.elsUrl + "song" + ElsService.ACTION_SEARCH,
+ JSON.stringify(
+ {
+ "aggs" : {
+ "genres" : {
+ "terms" : {
+ "field" : "Genre.original",
+ "size" : 10,
+ "missing": "N/A",
+ "order": { "_count" : ordering }
+ }
+ }
+ },
+ "size": 0
+ }),
+ {headers: this.headers})
+ .map(res => res.json().aggregations.genres.buckets)
+ .map((hits: Array) => {
+ let result:Array = [];
+ hits.forEach((bucket) => {
+ result.push(bucket);
+ });
+ return result;
+ });;
+ }
+
+ getGenreCount(): Observable {
+ return this.http
+ .post(this.elsUrl + "song" + ElsService.ACTION_SEARCH,
+ JSON.stringify(
+ {
+ "aggs" : {
+ "genres" : {
+ "cardinality" : {
+ "field" : "Genre.original",
+ "missing": "N/A",
+ }
+ }
+ },
+ "size": 0
+ }),
+ {headers: this.headers})
+ .map(res => res.json().aggregations.genres.value);
+ }
+
private handleError(error: any): Promise {
console.error('An error occurred', error); // for demo purposes only
return Promise.reject(error.message || error);
diff --git a/dashboard/src/app/object/bucket.ts b/dashboard/src/app/object/bucket.ts
new file mode 100644
index 0000000..68fde47
--- /dev/null
+++ b/dashboard/src/app/object/bucket.ts
@@ -0,0 +1,4 @@
+export class Bucket {
+ key: string;
+ doc_count: number;
+}
\ No newline at end of file