Add time for Album + pipe to convert Ms

This commit is contained in:
2017-05-14 01:23:01 +02:00
parent bf274e08d6
commit 8cb2d91af0
8 changed files with 57 additions and 47 deletions

View File

@@ -10,7 +10,7 @@
</div> </div>
<div class="row cardAdmin"> <div class="row cardAdmin">
<div class="col-lg-4 col-md-4"> <div class="col-lg-3 col-md-3">
<div class="panel panel-yellow"> <div class="panel panel-yellow">
<div class="panel-heading"> <div class="panel-heading">
<div class="row"> <div class="row">
@@ -28,7 +28,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-4 col-md-4"> <div class="col-lg-3 col-md-3">
<div class="panel panel-green"> <div class="panel panel-green">
<div class="panel-heading"> <div class="panel-heading">
<div class="row"> <div class="row">
@@ -46,7 +46,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-4 col-md-4"> <div class="col-lg-3 col-md-3">
<div class="panel panel-purple"> <div class="panel panel-purple">
<div class="panel-heading"> <div class="panel-heading">
<div class="row"> <div class="row">
@@ -64,6 +64,24 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-3 col-md-3">
<div class="panel panel-blue">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<span class="glyphicon glyphicon-time stats_icon"></span>
</div>
<div class="col-xs-9 text-right">
<div>
<h3 *ngIf="!album"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="album">{{album['Total Time'] | convertMs}}</h3>
</div>
<div><br>Album time</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
<table class="table table-striped" (window:scroll)="onScroll($event)"> <table class="table table-striped" (window:scroll)="onScroll($event)">
@@ -78,7 +96,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let song of songs | sortBy : 'Artist':'Track Number'"> <tr *ngFor="let song of songs | sortBy : 'Track Number'">
<td>{{song['Track Number'] ? (("0" + song['Track Number']).slice(-2)) : "--"}}</td> <td>{{song['Track Number'] ? (("0" + song['Track Number']).slice(-2)) : "--"}}</td>
<td [title]="song.Name">{{song.Name}}</td> <td [title]="song.Name">{{song.Name}}</td>
<td [title]="song.Artist"><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td> <td [title]="song.Artist"><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td>

View File

@@ -19,7 +19,8 @@ import { ElsService } from './els.service';
import { AppRoutingModule } from './app-routing.module' import { AppRoutingModule } from './app-routing.module'
import { SortPipe } from './sortby.pipe' import { ConvertMsPipe } from './convertms.pipe'
import { SortPipe } from './sortby.pipe'
@NgModule({ @NgModule({
imports: [ imports: [
@@ -36,6 +37,7 @@ import { SortPipe } from './sortby.pipe'
DashboardComponent, DashboardComponent,
AlbumComponent, AlbumComponent,
ArtistComponent, ArtistComponent,
ConvertMsPipe,
SortPipe SortPipe
], ],
providers: [ providers: [

View File

@@ -22,7 +22,7 @@
<h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3> <h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="artist">{{artist.Rating}}/100</h3> <h3 *ngIf="artist">{{artist.Rating}}/100</h3>
</div> </div>
<div><br>Rating</div> <div>Rating</div>
</div> </div>
</div> </div>
</div> </div>
@@ -40,7 +40,7 @@
<h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3> <h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="artist">{{artist.Album?.length}}</h3> <h3 *ngIf="artist">{{artist.Album?.length}}</h3>
</div> </div>
<div><br>Albums</div> <div>Albums</div>
</div> </div>
</div> </div>
</div> </div>
@@ -58,7 +58,7 @@
<h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3> <h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="artist">{{artist['Track Count']}}</h3> <h3 *ngIf="artist">{{artist['Track Count']}}</h3>
</div> </div>
<div><br>Songs</div> <div>Songs</div>
</div> </div>
</div> </div>
</div> </div>
@@ -76,7 +76,8 @@
<h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3> <h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="artist">{{artist['Play Count']}} list.</h3> <h3 *ngIf="artist">{{artist['Play Count']}} list.</h3>
</div> </div>
<div><br>~{{artist['Play Count'] / artist['Track Count'] | number:'1.0-0'}} listening avg.</div> <div *ngIf="artist">~{{artist['Play Count'] / artist['Track Count'] | number:'1.0-0'}} listening avg.</div>
<div *ngIf="!artist">Listening</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -14,8 +14,8 @@
</div> </div>
<div class="col-xs-9 text-right"> <div class="col-xs-9 text-right">
<div> <div>
<h3 *ngIf="!totalTimeSt"><span class="glyphicon glyphicon-refresh loading"></span></h3> <h3 *ngIf="!totalTime"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="totalTimeSt">{{totalTimeSt}}</h3> <h3 *ngIf="totalTime">{{totalTime | convertMs}}</h3>
</div> </div>
<div><br>Total time</div> <div><br>Total time</div>
</div> </div>
@@ -91,10 +91,10 @@
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let song of mostPlayedSongs"> <tr *ngFor="let song of mostPlayedSongs">
<td [title]="song.Name"><b>{{song.Name}}</b></td> <td><b>{{song.Name}}</b></td>
<td [title]="song.Artist"><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td> <td><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td>
<td [title]="song.Album"><a [routerLink]="['/album', song.Album]">{{song.Album}}</a></td> <td><a [routerLink]="['/album', song.Album]">{{song.Album}}</a></td>
<td [title]="song['Play Count']">{{song['Play Count']}}</td> <td>{{song['Play Count']}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@@ -4,6 +4,7 @@ import { Hero } from './hero'
import { HeroService } from './hero.service' import { HeroService } from './hero.service'
import { ElsService } from './els.service' import { ElsService } from './els.service'
import { Song } from './object/song'; import { Song } from './object/song';
import { Bucket } from './object/bucket';
@Component({ @Component({
selector: 'my-dashboard', selector: 'my-dashboard',
@@ -12,7 +13,6 @@ import { Song } from './object/song';
}) })
export class DashboardComponent implements OnInit { export class DashboardComponent implements OnInit {
totalTimeSt = "";
totalTime: number = 0; totalTime: number = 0;
totalSize: number = 0; totalSize: number = 0;
totalSizeSt = ""; totalSizeSt = "";
@@ -28,7 +28,6 @@ export class DashboardComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.elsService.getTime().then(result => { this.elsService.getTime().then(result => {
this.totalTime = result; this.totalTime = result;
this.totalTimeSt = this.convertMsToTime(this.totalTime);
}); });
this.elsService.getSize().then(result => { this.elsService.getSize().then(result => {
@@ -56,21 +55,6 @@ export class DashboardComponent implements OnInit {
* UTILS FUNCTION - TODO MOVE * UTILS FUNCTION - TODO MOVE
*/ */
convertMsToTime(ms: number): string {
let x = ms / 1000
let seconds = Math.round(x % 60)
x /= 60
let minutes = Math.round(x % 60)
x /= 60
let hours = Math.round(x % 24)
// TODO Enable/disable day
x /= 24
let days = Math.round(x);
return days + ":" + hours + ":" + minutes + "." + seconds;
// return days + " days, " + hours + " hours, " + minutes + " minutes and " + seconds + " seconds";
}
convertSizeToString(size: number) { convertSizeToString(size: number) {
let units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB']; let units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'];

View File

@@ -23,7 +23,7 @@ export class ElsService {
constructor(private http: Http) { } constructor(private http: Http) { }
getTime(): Promise<number> { getTime(): Promise<number> {
return this.http.post(this.elsUrl + ElsService.ACTION_SEARCH, JSON.stringify({aggs:{sum_time:{sum:{field:"Total Time"}}},"size":0}), {headers: this.headers}) return this.http.post(this.elsUrl + 'song/' + ElsService.ACTION_SEARCH, JSON.stringify({aggs:{sum_time:{sum:{field:"Total Time"}}},"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);
@@ -84,7 +84,7 @@ export class ElsService {
"Play Count": { "Play Count": {
"order": "desc" "order": "desc"
} } ], } } ],
"size": 10 "size": 5
}), }),
{headers: this.headers}) {headers: this.headers})
.map(res => { .map(res => {
@@ -130,18 +130,18 @@ export class ElsService {
return this.http return this.http
.post(this.elsUrl + "song" + ElsService.ACTION_SEARCH, .post(this.elsUrl + "song" + ElsService.ACTION_SEARCH,
JSON.stringify( JSON.stringify(
{ {
"query": { "query": {
"bool": { "bool": {
"should": [ "should": [
{"match_phrase" : { "Album Artist" : artistName }}, {"match_phrase" : { "Album Artist" : artistName }},
{"match_phrase" : { "Artist" : artistName }} {"match_phrase" : { "Artist" : artistName }}
] ]
} }
}, },
"size": ElsService.DEFAULT_SIZE, "size": ElsService.DEFAULT_SIZE,
"from": from "from": from
}), }),
{headers: this.headers}) {headers: this.headers})
.map(res => { .map(res => {
return res.json().hits.hits; return res.json().hits.hits;

View File

@@ -9,4 +9,5 @@ export class Album {
"Persistent ID": string; "Persistent ID": string;
"Album Rating Computed": boolean; "Album Rating Computed": boolean;
"Play Count": number; "Play Count": number;
"Total Time": number;
} }

View File

@@ -184,7 +184,8 @@ class ITunesParser:
'Play Count': 0, 'Play Count': 0,
'Rating': 0, 'Rating': 0,
'Genre': set(), 'Genre': set(),
'Artist': set() 'Artist': set(),
'Total Time': 0
} }
# Compute information # Compute information
@@ -193,9 +194,12 @@ class ITunesParser:
rating = track['Rating'] if 'Rating' in track else 0 rating = track['Rating'] if 'Rating' in track else 0
rating = self.calc_rating(rating, self._albums[akey]['Rating'], self._albums[akey]['Track Count']) rating = self.calc_rating(rating, self._albums[akey]['Rating'], self._albums[akey]['Track Count'])
total_time = track['Total Time'] if 'Total Time' in track else 0
self._albums[akey]['Track Count'] += 1 self._albums[akey]['Track Count'] += 1
self._albums[akey]['Rating'] = rating self._albums[akey]['Rating'] = rating
self._albums[akey]['Play Count'] += play_count self._albums[akey]['Play Count'] += play_count
self._albums[akey]['Total Time'] += total_time
if 'Genre' in track: if 'Genre' in track:
# Split up the Genres # Split up the Genres