From 8cb2d91af097ec9313944a2fe403d5b9ff8b68bc Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Sun, 14 May 2017 01:23:01 +0200 Subject: [PATCH] Add time for Album + pipe to convert Ms --- dashboard/src/app/album.component.html | 26 ++++++++++++++++---- dashboard/src/app/app.module.ts | 4 +++- dashboard/src/app/artist.component.html | 9 +++---- dashboard/src/app/dashboard.component.html | 12 +++++----- dashboard/src/app/dashboard.component.ts | 18 +------------- dashboard/src/app/els.service.ts | 28 +++++++++++----------- dashboard/src/app/object/album.ts | 1 + iTunesParser.py | 6 ++++- 8 files changed, 57 insertions(+), 47 deletions(-) diff --git a/dashboard/src/app/album.component.html b/dashboard/src/app/album.component.html index 42a8dbf..05b2c12 100644 --- a/dashboard/src/app/album.component.html +++ b/dashboard/src/app/album.component.html @@ -10,7 +10,7 @@
-
+
@@ -28,7 +28,7 @@
-
+
@@ -46,7 +46,7 @@
-
+
@@ -64,6 +64,24 @@
+
+
+
+
+
+ +
+
+
+

+

{{album['Total Time'] | convertMs}}

+
+

Album time
+
+
+
+
+
@@ -78,7 +96,7 @@ - + diff --git a/dashboard/src/app/app.module.ts b/dashboard/src/app/app.module.ts index d5507aa..33e77cb 100644 --- a/dashboard/src/app/app.module.ts +++ b/dashboard/src/app/app.module.ts @@ -19,7 +19,8 @@ import { ElsService } from './els.service'; import { AppRoutingModule } from './app-routing.module' -import { SortPipe } from './sortby.pipe' +import { ConvertMsPipe } from './convertms.pipe' +import { SortPipe } from './sortby.pipe' @NgModule({ imports: [ @@ -36,6 +37,7 @@ import { SortPipe } from './sortby.pipe' DashboardComponent, AlbumComponent, ArtistComponent, + ConvertMsPipe, SortPipe ], providers: [ diff --git a/dashboard/src/app/artist.component.html b/dashboard/src/app/artist.component.html index aee6378..cb73cb1 100644 --- a/dashboard/src/app/artist.component.html +++ b/dashboard/src/app/artist.component.html @@ -22,7 +22,7 @@

{{artist.Rating}}/100

-

Rating
+
Rating
@@ -40,7 +40,7 @@

{{artist.Album?.length}}

-

Albums
+
Albums
@@ -58,7 +58,7 @@

{{artist['Track Count']}}

-

Songs
+
Songs
@@ -76,7 +76,8 @@

{{artist['Play Count']}} list.

-

~{{artist['Play Count'] / artist['Track Count'] | number:'1.0-0'}} listening avg.
+
~{{artist['Play Count'] / artist['Track Count'] | number:'1.0-0'}} listening avg.
+
Listening
diff --git a/dashboard/src/app/dashboard.component.html b/dashboard/src/app/dashboard.component.html index eb43a64..68876bd 100644 --- a/dashboard/src/app/dashboard.component.html +++ b/dashboard/src/app/dashboard.component.html @@ -14,8 +14,8 @@
-

-

{{totalTimeSt}}

+

+

{{totalTime | convertMs}}


Total time
@@ -91,10 +91,10 @@ - - - - + + + +
{{song['Track Number'] ? (("0" + song['Track Number']).slice(-2)) : "--"}} {{song.Name}} {{song.Artist}}
{{song.Name}}{{song.Artist}}{{song.Album}}{{song['Play Count']}}{{song.Name}}{{song.Artist}}{{song.Album}}{{song['Play Count']}}
diff --git a/dashboard/src/app/dashboard.component.ts b/dashboard/src/app/dashboard.component.ts index b78a3a6..6e6c56b 100644 --- a/dashboard/src/app/dashboard.component.ts +++ b/dashboard/src/app/dashboard.component.ts @@ -4,6 +4,7 @@ import { Hero } from './hero' import { HeroService } from './hero.service' import { ElsService } from './els.service' import { Song } from './object/song'; +import { Bucket } from './object/bucket'; @Component({ selector: 'my-dashboard', @@ -12,7 +13,6 @@ import { Song } from './object/song'; }) export class DashboardComponent implements OnInit { - totalTimeSt = ""; totalTime: number = 0; totalSize: number = 0; totalSizeSt = ""; @@ -28,7 +28,6 @@ export class DashboardComponent implements OnInit { ngOnInit(): void { this.elsService.getTime().then(result => { this.totalTime = result; - this.totalTimeSt = this.convertMsToTime(this.totalTime); }); this.elsService.getSize().then(result => { @@ -56,21 +55,6 @@ export class DashboardComponent implements OnInit { * 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) { let units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB']; diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index dd6da39..c35c9c5 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -23,7 +23,7 @@ export class ElsService { constructor(private http: Http) { } getTime(): Promise { - 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() .then(res => res.json().aggregations.sum_time.value as number) .catch(this.handleError); @@ -84,7 +84,7 @@ export class ElsService { "Play Count": { "order": "desc" } } ], - "size": 10 + "size": 5 }), {headers: this.headers}) .map(res => { @@ -130,18 +130,18 @@ export class ElsService { return this.http .post(this.elsUrl + "song" + ElsService.ACTION_SEARCH, JSON.stringify( - { - "query": { - "bool": { - "should": [ - {"match_phrase" : { "Album Artist" : artistName }}, - {"match_phrase" : { "Artist" : artistName }} - ] - } - }, - "size": ElsService.DEFAULT_SIZE, - "from": from - }), + { + "query": { + "bool": { + "should": [ + {"match_phrase" : { "Album Artist" : artistName }}, + {"match_phrase" : { "Artist" : artistName }} + ] + } + }, + "size": ElsService.DEFAULT_SIZE, + "from": from + }), {headers: this.headers}) .map(res => { return res.json().hits.hits; diff --git a/dashboard/src/app/object/album.ts b/dashboard/src/app/object/album.ts index c514bd1..be5d3f8 100644 --- a/dashboard/src/app/object/album.ts +++ b/dashboard/src/app/object/album.ts @@ -9,4 +9,5 @@ export class Album { "Persistent ID": string; "Album Rating Computed": boolean; "Play Count": number; + "Total Time": number; } \ No newline at end of file diff --git a/iTunesParser.py b/iTunesParser.py index ccaba26..b49430c 100644 --- a/iTunesParser.py +++ b/iTunesParser.py @@ -184,7 +184,8 @@ class ITunesParser: 'Play Count': 0, 'Rating': 0, 'Genre': set(), - 'Artist': set() + 'Artist': set(), + 'Total Time': 0 } # Compute information @@ -193,9 +194,12 @@ class ITunesParser: rating = track['Rating'] if 'Rating' in track else 0 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]['Rating'] = rating self._albums[akey]['Play Count'] += play_count + self._albums[akey]['Total Time'] += total_time if 'Genre' in track: # Split up the Genres