Calc size
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
<h4>{{totalTimeSt}}</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-pad">
|
||||
<div class="module hero">
|
||||
<h4>{{totalSizeSt}}</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-pad">
|
||||
<div class="module hero">
|
||||
<h4>{{trackCountSong}} chansons, {{trackCountArtist}} artistes, {{trackCountAlbum}} albums</h4>
|
||||
|
||||
@@ -14,6 +14,8 @@ import { Song } from './object/song';
|
||||
export class DashboardComponent implements OnInit {
|
||||
totalTimeSt = "";
|
||||
totalTime: number = 0;
|
||||
totalSize: number = 0;
|
||||
totalSizeSt = "";
|
||||
trackCountSong: number = 0;
|
||||
trackCountArtist: number = 0;
|
||||
trackCountAlbum: number = 0;
|
||||
@@ -23,22 +25,26 @@ export class DashboardComponent implements OnInit {
|
||||
constructor(private elsService: ElsService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.elsService.getTime()
|
||||
.then(result => {
|
||||
this.totalTime = result;
|
||||
this.totalTimeSt = this.convertMsToTime(this.totalTime);
|
||||
});
|
||||
this.elsService.getTime().then(result => {
|
||||
this.totalTime = result;
|
||||
this.totalTimeSt = this.convertMsToTime(this.totalTime);
|
||||
});
|
||||
|
||||
this.elsService.getTrackCount("song")
|
||||
.then(result => this.trackCountSong = result);
|
||||
this.elsService.getTrackCount("artist")
|
||||
.then(result => this.trackCountArtist = result);
|
||||
this.elsService.getTrackCount("album")
|
||||
.then(result => this.trackCountAlbum = result);
|
||||
this.elsService.getSize().then(result => {
|
||||
this.totalSize = result;
|
||||
this.totalSizeSt = this.convertSizeToString(result);
|
||||
});
|
||||
|
||||
this.elsService.getMostPlayedTrack().subscribe(
|
||||
data => this.mostPlayedSongs = data
|
||||
);
|
||||
this.elsService.getTrackCount("song")
|
||||
.then(result => this.trackCountSong = result);
|
||||
this.elsService.getTrackCount("artist")
|
||||
.then(result => this.trackCountArtist = result);
|
||||
this.elsService.getTrackCount("album")
|
||||
.then(result => this.trackCountAlbum = result);
|
||||
|
||||
this.elsService.getMostPlayedTrack().subscribe(
|
||||
data => this.mostPlayedSongs = data
|
||||
);
|
||||
}
|
||||
|
||||
convertMsToTime(ms: number): string {
|
||||
@@ -55,4 +61,17 @@ export class DashboardComponent implements OnInit {
|
||||
// return days + "d" + hours + "h" + minutes + ":" + seconds;
|
||||
return days + " days, " + hours + " hours, " + minutes + " minutes and " + seconds + " seconds";
|
||||
}
|
||||
|
||||
convertSizeToString(size: number) {
|
||||
let units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||
|
||||
if (size == 0)
|
||||
return '0 Byte';
|
||||
|
||||
let i = Math.floor(Math.log(size) / Math.log(1024));
|
||||
let calcSize = size / Math.pow(1024, i)
|
||||
calcSize = Math.round(calcSize * 100) / 100;
|
||||
|
||||
return calcSize + ' ' + units[i];
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Headers, Http } from '@angular/http';
|
||||
|
||||
import { Hits } from './object/hits';
|
||||
import { Song } from './object/song';
|
||||
|
||||
import 'rxjs/add/operator/toPromise';
|
||||
@@ -17,7 +16,14 @@ export class ElsService {
|
||||
constructor(private http: Http) { }
|
||||
|
||||
getTime(): Promise<number> {
|
||||
return this.http.post(this.elsUrl + "_search", JSON.stringify({aggs:{sum_time:{sum:{field:"Total Time"}}}}), {headers: this.headers})
|
||||
return this.http.post(this.elsUrl + "_search", JSON.stringify({aggs:{sum_time:{sum:{field:"Total Time"}}},"size":0}), {headers: this.headers})
|
||||
.toPromise()
|
||||
.then(res => res.json().aggregations.sum_time.value as number)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getSize(): Promise<number> {
|
||||
return this.http.post(this.elsUrl + "_search", JSON.stringify({aggs:{sum_time:{sum:{field:"Size"}}},"size":0}), {headers: this.headers})
|
||||
.toPromise()
|
||||
.then(res => res.json().aggregations.sum_time.value as number)
|
||||
.catch(this.handleError);
|
||||
|
||||
Reference in New Issue
Block a user