Get last added album improved

- Take number of month
- Extract method to treat bucket
This commit is contained in:
2017-10-07 11:50:57 +02:00
parent 94e59930ee
commit 331458edbd
2 changed files with 25 additions and 16 deletions

View File

@@ -61,22 +61,31 @@ export class DashboardComponent implements OnInit {
this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data);
// this.elsService.getGenreCount().subscribe(data => console.log(data));
this.elsService.getLastAddedAlbums().subscribe(buckets => {
this.elsService.getLastAddedAlbums(6).subscribe(buckets => {
this.lastAddedAlbums = buckets;
buckets.forEach(bucket => {
this.elsService.getArtistFromAlbumName(bucket.key).subscribe(data => {
if (data.length > 1) {
data.forEach(album => {
if (album['Track Count'] === bucket.doc_count) {
console.log(album.Artist.toString());
this.albumArtists[album.Name] = album.Artist.toString();
}
});
} else {
this.albumArtists[data[0].Name] = data[0].Artist.toString();
buckets.forEach(bucket => this.getArtistName(bucket));
});
}
private getArtistName(albumBucket: Bucket) {
// For each bucket.key (album name), search artist.
// Use track count to compare
this.elsService.getArtistFromAlbumName(albumBucket.key).subscribe(albums => {
if (albums.length > 1) {
// More than one result for an album name
// Search good artist by track count
albums.forEach(album => {
if (album['Track Count'] === albumBucket.doc_count) {
this.albumArtists[album.Name] = album.Artist.toString();
}
});
});
} else {
// Just one artistresult for album name
this.albumArtists[albums[0].Name] = albums[0].Artist.toString();
}
if (this.albumArtists[albums[0].Name].length > 50) {
this.albumArtists[albums[0].Name] = this.albumArtists[albums[0].Name].substring(0, 50) + '...';
}
});
}

View File

@@ -270,14 +270,14 @@ export class ElsService {
.map(res => res.json().aggregations.genres.value);
}
getLastAddedAlbums(): Observable<Bucket[]> {
getLastAddedAlbums(month: number): Observable<Bucket[]> {
return this.http
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
JSON.stringify({
'query': {
'range' : {
'Date Added' : {
'gte' : 'now-6M/d',
'gte' : 'now-' + month + 'M/d',
'lte' : 'now/d'
}
}
@@ -286,7 +286,7 @@ export class ElsService {
'album' : {
'terms' : {
'field' : 'Album.original',
'size': 5
'size': 10
}
}
},