Calc size
This commit is contained in:
@@ -4,6 +4,11 @@
|
|||||||
<h4>{{totalTimeSt}}</h4>
|
<h4>{{totalTimeSt}}</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="grid grid-pad">
|
||||||
|
<div class="module hero">
|
||||||
|
<h4>{{totalSizeSt}}</h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="grid grid-pad">
|
<div class="grid grid-pad">
|
||||||
<div class="module hero">
|
<div class="module hero">
|
||||||
<h4>{{trackCountSong}} chansons, {{trackCountArtist}} artistes, {{trackCountAlbum}} albums</h4>
|
<h4>{{trackCountSong}} chansons, {{trackCountArtist}} artistes, {{trackCountAlbum}} albums</h4>
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import { Song } from './object/song';
|
|||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
totalTimeSt = "";
|
totalTimeSt = "";
|
||||||
totalTime: number = 0;
|
totalTime: number = 0;
|
||||||
|
totalSize: number = 0;
|
||||||
|
totalSizeSt = "";
|
||||||
trackCountSong: number = 0;
|
trackCountSong: number = 0;
|
||||||
trackCountArtist: number = 0;
|
trackCountArtist: number = 0;
|
||||||
trackCountAlbum: number = 0;
|
trackCountAlbum: number = 0;
|
||||||
@@ -23,22 +25,26 @@ export class DashboardComponent implements OnInit {
|
|||||||
constructor(private elsService: ElsService) { }
|
constructor(private elsService: ElsService) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.elsService.getTime()
|
this.elsService.getTime().then(result => {
|
||||||
.then(result => {
|
this.totalTime = result;
|
||||||
this.totalTime = result;
|
this.totalTimeSt = this.convertMsToTime(this.totalTime);
|
||||||
this.totalTimeSt = this.convertMsToTime(this.totalTime);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.elsService.getTrackCount("song")
|
this.elsService.getSize().then(result => {
|
||||||
.then(result => this.trackCountSong = result);
|
this.totalSize = result;
|
||||||
this.elsService.getTrackCount("artist")
|
this.totalSizeSt = this.convertSizeToString(result);
|
||||||
.then(result => this.trackCountArtist = result);
|
});
|
||||||
this.elsService.getTrackCount("album")
|
|
||||||
.then(result => this.trackCountAlbum = result);
|
|
||||||
|
|
||||||
this.elsService.getMostPlayedTrack().subscribe(
|
this.elsService.getTrackCount("song")
|
||||||
data => this.mostPlayedSongs = data
|
.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 {
|
convertMsToTime(ms: number): string {
|
||||||
@@ -55,4 +61,17 @@ export class DashboardComponent implements OnInit {
|
|||||||
// return days + "d" + hours + "h" + minutes + ":" + seconds;
|
// return days + "d" + hours + "h" + minutes + ":" + seconds;
|
||||||
return days + " days, " + hours + " hours, " + minutes + " minutes and " + seconds + " 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 { Injectable } from '@angular/core';
|
||||||
import { Headers, Http } from '@angular/http';
|
import { Headers, Http } from '@angular/http';
|
||||||
|
|
||||||
import { Hits } from './object/hits';
|
|
||||||
import { Song } from './object/song';
|
import { Song } from './object/song';
|
||||||
|
|
||||||
import 'rxjs/add/operator/toPromise';
|
import 'rxjs/add/operator/toPromise';
|
||||||
@@ -17,7 +16,14 @@ export class ElsService {
|
|||||||
constructor(private http: Http) { }
|
constructor(private http: Http) { }
|
||||||
|
|
||||||
getTime(): Promise<number> {
|
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()
|
.toPromise()
|
||||||
.then(res => res.json().aggregations.sum_time.value as number)
|
.then(res => res.json().aggregations.sum_time.value as number)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
|
|||||||
Reference in New Issue
Block a user