WIP Last added more precise
Translate correclty this commit message
This commit is contained in:
@@ -84,6 +84,8 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Album</th>
|
||||
<th>Track Count</th>
|
||||
<th>Album Artist</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@@ -57,9 +57,32 @@ export class DashboardComponent implements OnInit {
|
||||
this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data);
|
||||
// this.elsService.getGenreCount().subscribe(data => console.log(data));
|
||||
|
||||
const lastAddedAlbumsTemp: Bucket[] = [];
|
||||
const BreakException = {};
|
||||
this.elsService.getLastAddedAlbums(6).subscribe(buckets => {
|
||||
this.lastAddedAlbums = buckets;
|
||||
buckets.forEach(bucket => this.getArtistName(bucket));
|
||||
buckets.forEach(bucket => {
|
||||
console.log(bucket);
|
||||
|
||||
if (lastAddedAlbumsTemp.length === 0) {
|
||||
lastAddedAlbumsTemp.push(bucket);
|
||||
} else {
|
||||
let found = false;
|
||||
lastAddedAlbumsTemp.forEach(element => {
|
||||
if (element.key === bucket.key) {
|
||||
element.doc_count += bucket.doc_count;
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
if (!found) {
|
||||
lastAddedAlbumsTemp.push(bucket);
|
||||
}
|
||||
}
|
||||
});
|
||||
// console.log("alors");
|
||||
console.log(lastAddedAlbumsTemp);
|
||||
|
||||
this.lastAddedAlbums = lastAddedAlbumsTemp;
|
||||
this.lastAddedAlbums.forEach(bucket => this.getArtistName(bucket));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -227,24 +227,32 @@ export class ElsService {
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'range' : {
|
||||
'Date Added' : {
|
||||
'gte' : 'now-' + month + 'M/d',
|
||||
'lte' : 'now/d'
|
||||
}
|
||||
'range' : {
|
||||
'Date Added' : {
|
||||
'gte' : 'now-3M/d',
|
||||
'lte' : 'now/d'
|
||||
}
|
||||
},
|
||||
'aggs' : {
|
||||
'album' : {
|
||||
'terms' : {
|
||||
'field' : 'Album.original',
|
||||
'size': 150
|
||||
}
|
||||
},
|
||||
'size': 0,
|
||||
'aggs': {
|
||||
'date' : {
|
||||
'terms': {
|
||||
'field' : 'Date Added',
|
||||
'order': { '_term': 'desc' },
|
||||
'size': 20
|
||||
},
|
||||
'aggs': {
|
||||
'album': {
|
||||
'terms': {
|
||||
'field': 'Album.original'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'size': 0
|
||||
}), {headers: this.headers})
|
||||
.map(res => this.responseAggregationToBucket(res, 'album'));
|
||||
}
|
||||
}
|
||||
}), {headers: this.headers})
|
||||
.map(res => this.responseSubAggregationToBucket(res, 'date'));
|
||||
// TODO Take in consideration "sum_other_doc_count"
|
||||
}
|
||||
|
||||
@@ -332,6 +340,16 @@ export class ElsService {
|
||||
return result;
|
||||
}
|
||||
|
||||
private responseSubAggregationToBucket(res: Response, name: string): Bucket[] {
|
||||
const result: Array<Bucket> = [];
|
||||
res.json().aggregations[name].buckets.forEach((bucket) => {
|
||||
bucket['album'].buckets.forEach((subBucket) => {
|
||||
result.push(subBucket);
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private handleError(error: any): Promise<any> {
|
||||
console.error('An error occurred', error); // for demo purposes only
|
||||
return Promise.reject(error.message || error);
|
||||
|
||||
Reference in New Issue
Block a user