Compare commits
52 Commits
script_sta
...
feature/wo
| Author | SHA1 | Date | |
|---|---|---|---|
| 0417604587 | |||
| e4aadd72f9 | |||
| b886577361 | |||
| d27732f97e | |||
| b10c106a5f | |||
| 1e6d388596 | |||
| f9acea1e9c | |||
| 0a73002871 | |||
| 94480a27d2 | |||
| 11c64405eb | |||
| 331458edbd | |||
| 94e59930ee | |||
| 50bc795d5f | |||
| 95f80b6b11 | |||
| 31fd9f27e9 | |||
| b9bcc26258 | |||
| 7b3c236416 | |||
| 95438ec7a0 | |||
| 60f839f698 | |||
| 28f4ea41d1 | |||
| 40f2f4fc5e | |||
| 28641848e5 | |||
| fb092f3b9b | |||
| 8cb2d91af0 | |||
| bf274e08d6 | |||
| 29841820e6 | |||
| 11348abb81 | |||
| 8693c2ec7e | |||
| d099353aed | |||
| f58113ca22 | |||
| c0d6459d0b | |||
| 6c55117c0d | |||
| 879647564c | |||
| c9a55c8217 | |||
| 9cdd69bfd0 | |||
| cba0f110ff | |||
| ed9f6020dc | |||
| 6f38b9ddd3 | |||
| 9ff2e86c65 | |||
| 87bcdf48a5 | |||
| 7b796dceaf | |||
| ae02d37385 | |||
| 1abf0b6a0f | |||
| 9793bc8763 | |||
| 264356e5a1 | |||
| 302afb6675 | |||
| fe9638bcb5 | |||
| ecc216d15d | |||
| 87df9af88a | |||
| 84f254d378 | |||
| 49aed4575b | |||
| 726cf70a84 |
63
dashboard/.angular-cli.json
Normal file
63
dashboard/.angular-cli.json
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"project": {
|
||||
"name": "dashboard"
|
||||
},
|
||||
"apps": [
|
||||
{
|
||||
"root": "src",
|
||||
"outDir": "dist",
|
||||
"assets": [
|
||||
"assets",
|
||||
"favicon.ico"
|
||||
],
|
||||
"index": "index.html",
|
||||
"main": "main.ts",
|
||||
"polyfills": "polyfills.ts",
|
||||
"test": "test.ts",
|
||||
"tsconfig": "tsconfig.app.json",
|
||||
"testTsconfig": "tsconfig.spec.json",
|
||||
"prefix": "app",
|
||||
"styles": [
|
||||
"styles.css",
|
||||
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
|
||||
],
|
||||
"scripts": [
|
||||
"../node_modules/angular4-word-cloud/d3.min.js"
|
||||
],
|
||||
"environmentSource": "environments/environment.ts",
|
||||
"environments": {
|
||||
"dev": "environments/environment.ts",
|
||||
"prod": "environments/environment.prod.ts"
|
||||
}
|
||||
}
|
||||
],
|
||||
"e2e": {
|
||||
"protractor": {
|
||||
"config": "./protractor.conf.js"
|
||||
}
|
||||
},
|
||||
"lint": [
|
||||
{
|
||||
"project": "src/tsconfig.app.json",
|
||||
"exclude": "**/node_modules/**"
|
||||
},
|
||||
{
|
||||
"project": "src/tsconfig.spec.json",
|
||||
"exclude": "**/node_modules/**"
|
||||
},
|
||||
{
|
||||
"project": "e2e/tsconfig.e2e.json",
|
||||
"exclude": "**/node_modules/**"
|
||||
}
|
||||
],
|
||||
"test": {
|
||||
"karma": {
|
||||
"config": "./karma.conf.js"
|
||||
}
|
||||
},
|
||||
"defaults": {
|
||||
"styleExt": "css",
|
||||
"component": {}
|
||||
}
|
||||
}
|
||||
13
dashboard/.editorconfig
Normal file
13
dashboard/.editorconfig
Normal file
@@ -0,0 +1,13 @@
|
||||
# Editor configuration, see http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
43
dashboard/.gitignore
vendored
Normal file
43
dashboard/.gitignore
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# compiled output
|
||||
/dist
|
||||
/tmp
|
||||
/out-tsc
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# misc
|
||||
/.sass-cache
|
||||
/connect.lock
|
||||
/coverage
|
||||
/libpeerconnection.log
|
||||
npm-debug.log
|
||||
testem.log
|
||||
/typings
|
||||
yarn-error.log
|
||||
|
||||
# e2e
|
||||
/e2e/*.js
|
||||
/e2e/*.map
|
||||
|
||||
# System Files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
14
dashboard/e2e/app.e2e-spec.ts
Normal file
14
dashboard/e2e/app.e2e-spec.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { AppPage } from './app.po';
|
||||
|
||||
describe('dashboard App', () => {
|
||||
let page: AppPage;
|
||||
|
||||
beforeEach(() => {
|
||||
page = new AppPage();
|
||||
});
|
||||
|
||||
it('should display welcome message', () => {
|
||||
page.navigateTo();
|
||||
expect(page.getParagraphText()).toEqual('Welcome to app!');
|
||||
});
|
||||
});
|
||||
11
dashboard/e2e/app.po.ts
Normal file
11
dashboard/e2e/app.po.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { browser, by, element } from 'protractor';
|
||||
|
||||
export class AppPage {
|
||||
navigateTo() {
|
||||
return browser.get('/');
|
||||
}
|
||||
|
||||
getParagraphText() {
|
||||
return element(by.css('app-root h1')).getText();
|
||||
}
|
||||
}
|
||||
14
dashboard/e2e/tsconfig.e2e.json
Normal file
14
dashboard/e2e/tsconfig.e2e.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../out-tsc/e2e",
|
||||
"baseUrl": "./",
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"types": [
|
||||
"jasmine",
|
||||
"jasminewd2",
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
||||
33
dashboard/karma.conf.js
Normal file
33
dashboard/karma.conf.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', '@angular/cli'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-jasmine-html-reporter'),
|
||||
require('karma-coverage-istanbul-reporter'),
|
||||
require('@angular/cli/plugins/karma')
|
||||
],
|
||||
client:{
|
||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||
},
|
||||
coverageIstanbulReporter: {
|
||||
reports: [ 'html', 'lcovonly' ],
|
||||
fixWebpackSourcePaths: true
|
||||
},
|
||||
angularCli: {
|
||||
environment: 'dev'
|
||||
},
|
||||
reporters: ['progress', 'kjhtml'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: false
|
||||
});
|
||||
};
|
||||
53
dashboard/package.json
Normal file
53
dashboard/package.json
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"name": "dashboard",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"test": "ng test",
|
||||
"lint": "ng lint",
|
||||
"e2e": "ng e2e"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^4.2.4",
|
||||
"@angular/common": "^4.2.4",
|
||||
"@angular/compiler": "^4.2.4",
|
||||
"@angular/core": "^4.2.4",
|
||||
"@angular/forms": "^4.2.4",
|
||||
"@angular/http": "^4.2.4",
|
||||
"@angular/platform-browser": "^4.2.4",
|
||||
"@angular/platform-browser-dynamic": "^4.2.4",
|
||||
"@angular/router": "^4.2.4",
|
||||
"angular-tag-cloud-module": "^1.4.0",
|
||||
"angular4-word-cloud": "^0.1.2",
|
||||
"bootstrap": "3.3.7",
|
||||
"core-js": "^2.4.1",
|
||||
"d3": "^4.11.0",
|
||||
"rxjs": "^5.4.2",
|
||||
"zone.js": "^0.8.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/cli": "1.3.2",
|
||||
"@angular/compiler-cli": "^4.2.4",
|
||||
"@angular/language-service": "^4.2.4",
|
||||
"@types/jasmine": "~2.5.53",
|
||||
"@types/jasminewd2": "~2.0.2",
|
||||
"@types/node": "~6.0.60",
|
||||
"codelyzer": "~3.1.1",
|
||||
"jasmine-core": "~2.6.2",
|
||||
"jasmine-spec-reporter": "~4.1.0",
|
||||
"karma": "~1.7.0",
|
||||
"karma-chrome-launcher": "~2.1.1",
|
||||
"karma-cli": "~1.0.1",
|
||||
"karma-coverage-istanbul-reporter": "^1.2.1",
|
||||
"karma-jasmine": "~1.1.0",
|
||||
"karma-jasmine-html-reporter": "^0.2.2",
|
||||
"protractor": "~5.1.2",
|
||||
"ts-node": "~3.2.0",
|
||||
"tslint": "~5.3.2",
|
||||
"typescript": "~2.3.3"
|
||||
}
|
||||
}
|
||||
28
dashboard/protractor.conf.js
Normal file
28
dashboard/protractor.conf.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// Protractor configuration file, see link for more information
|
||||
// https://github.com/angular/protractor/blob/master/lib/config.ts
|
||||
|
||||
const { SpecReporter } = require('jasmine-spec-reporter');
|
||||
|
||||
exports.config = {
|
||||
allScriptsTimeout: 11000,
|
||||
specs: [
|
||||
'./e2e/**/*.e2e-spec.ts'
|
||||
],
|
||||
capabilities: {
|
||||
'browserName': 'chrome'
|
||||
},
|
||||
directConnect: true,
|
||||
baseUrl: 'http://localhost:4200/',
|
||||
framework: 'jasmine',
|
||||
jasmineNodeOpts: {
|
||||
showColors: true,
|
||||
defaultTimeoutInterval: 30000,
|
||||
print: function() {}
|
||||
},
|
||||
onPrepare() {
|
||||
require('ts-node').register({
|
||||
project: 'e2e/tsconfig.e2e.json'
|
||||
});
|
||||
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
|
||||
}
|
||||
};
|
||||
63
dashboard/requestAlbum.txt
Normal file
63
dashboard/requestAlbum.txt
Normal file
@@ -0,0 +1,63 @@
|
||||
POST http://localhost:9200/itunessongs/album/_search
|
||||
content-type: application/json
|
||||
User-Agent: vscode-restclient
|
||||
|
||||
{
|
||||
"query": {
|
||||
"match" : {
|
||||
"Album" : {
|
||||
"query": "Crystal Castles",
|
||||
"operator" : "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
"size": 20
|
||||
}
|
||||
|
||||
POST http://localhost:9200/itunessongs/song/_search
|
||||
content-type: application/json
|
||||
User-Agent: vscode-restclient
|
||||
|
||||
{
|
||||
"query": {
|
||||
"match_phrase" : {
|
||||
"Album" : "Crystal Castles"
|
||||
}
|
||||
},
|
||||
"size": 20
|
||||
}
|
||||
|
||||
POST http://localhost:9200/itunessongs/song/_search
|
||||
content-type: application/json
|
||||
User-Agent: vscode-restclient
|
||||
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{"match_phrase" : { "Album" : "Crystal Castles" }},
|
||||
{"match_phrase" : { "Artist" : "Crystal Castles" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"size": 20
|
||||
}
|
||||
|
||||
POST http://localhost:9200/itunessongs/song/_search
|
||||
content-type: application/json
|
||||
User-Agent: vscode-restclient
|
||||
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": {
|
||||
"match_phrase" : { "Album" : "Crystal Castles" }
|
||||
},
|
||||
"should" : [
|
||||
{"match_phrase" : { "Artist" : "Crystal Castles" }},
|
||||
{"match_phrase" : { "Album Artist" : "Crystal Castles" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"size": 20
|
||||
}
|
||||
37
dashboard/src/app/album/album.component.css
Normal file
37
dashboard/src/app/album/album.component.css
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Thank to https://codyhouse.co/gem/back-to-top/ */
|
||||
|
||||
.btn-top {
|
||||
display: inline-block;
|
||||
height: 40px;
|
||||
width: 40px;
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
|
||||
/* image replacement properties */
|
||||
/*overflow: hidden;*/
|
||||
/*text-indent: 100%;*/
|
||||
/*white-space: nowrap;*/
|
||||
/*background: rgba(232, 98, 86, 0.8);*/
|
||||
/*background: #ff9000;*/
|
||||
visibility: hidden;
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity .3s 0s, visibility 0s .3s;
|
||||
-moz-transition: opacity .3s 0s, visibility 0s .3s;
|
||||
transition: opacity .3s 0s, visibility 0s .3s;
|
||||
}
|
||||
.btn-top.btn-top-is-visible, .no-touch .btn-top:hover {
|
||||
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
|
||||
-moz-transition: opacity .3s 0s, visibility 0s 0s;
|
||||
transition: opacity .3s 0s, visibility 0s 0s;
|
||||
}
|
||||
.btn-top.btn-top-is-visible {
|
||||
/* the button becomes visible */
|
||||
visibility: visible;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.btn-sort {
|
||||
bottom: 20px;
|
||||
right: 70px;
|
||||
}
|
||||
121
dashboard/src/app/album/album.component.html
Normal file
121
dashboard/src/app/album/album.component.html
Normal file
@@ -0,0 +1,121 @@
|
||||
<div class="container">
|
||||
<h1>{{albumName}}</h1>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
<h3>Debug Zone</h3>
|
||||
Returned song: {{songs.length}}<br />
|
||||
Theorical number song: {{ album ? album['Track Count'] : "" }}
|
||||
<span *ngIf="album && (songs.length == album['Track Count'])" class="glyphicon glyphicon-ok" style="color:green"></span>
|
||||
<span *ngIf="album && (songs.length != album['Track Count'])" class="glyphicon glyphicon-remove" style="color:red"></span>
|
||||
</div>
|
||||
|
||||
<div class="row cardAdmin">
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-yellow">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-star 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.Rating}}/100</h3>
|
||||
</div>
|
||||
<div><br>Rating</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-green">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-list-alt 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['Track Count']}}</h3>
|
||||
</div>
|
||||
<div><br>Songs</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-purple">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-headphones 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['Play Count']}} list.</h3>
|
||||
</div>
|
||||
<div><br>~{{album['Play Count'] / album['Track Count'] | number:'1.0-0'}} listening avg.</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>
|
||||
|
||||
<table class="table table-striped" (window:scroll)="onScroll($event)">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Name</th>
|
||||
<th>Artist</th>
|
||||
<th>Album</th>
|
||||
<th>Album Artist</th>
|
||||
<th>Play Count</th>
|
||||
<th>Genre</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let song of songs | sortBy : 'Track Number'">
|
||||
<td>{{song['Track Number'] ? (("0" + song['Track Number']).slice(-2)) : "--"}}</td>
|
||||
<td>{{song.Name}}</td>
|
||||
<td><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td>
|
||||
<td><a [routerLink]="['/album', song.Album]">{{song.Album}}</a></td>
|
||||
<td>{{song['Album Artist']}}</td>
|
||||
<td>{{song['Play Count']}}</td>
|
||||
<td><a [routerLink]="['/genre', song.Genre]">{{song.Genre}}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="button" *ngIf="moreDataAvailable" class="btn btn-default" aria-label="More" (click)="loadSongs()">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> More...
|
||||
</button>
|
||||
|
||||
<!-- Go to Top Button-->
|
||||
<button type="button" class="btn btn-warning btn-top" [class.btn-top-is-visible]="atBottom"
|
||||
aria-label="Top" (click)="scrollTop()">
|
||||
<span class="glyphicon glyphicon-menu-up" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
25
dashboard/src/app/album/album.component.spec.ts
Normal file
25
dashboard/src/app/album/album.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AlbumComponent } from './album.component';
|
||||
|
||||
describe('AlbumComponent', () => {
|
||||
let component: AlbumComponent;
|
||||
let fixture: ComponentFixture<AlbumComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ AlbumComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AlbumComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
80
dashboard/src/app/album/album.component.ts
Normal file
80
dashboard/src/app/album/album.component.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { Location } from '@angular/common';
|
||||
|
||||
import { ElsService } from './../els.service';
|
||||
import { Song } from './../object/song';
|
||||
import { Album } from './../object/album';
|
||||
|
||||
@Component({
|
||||
selector: 'app-album',
|
||||
templateUrl: './album.component.html',
|
||||
styleUrls: [ './album.component.css', './../dashboard.component.css' ]
|
||||
})
|
||||
|
||||
export class AlbumComponent implements OnInit {
|
||||
albumName = '';
|
||||
songs: Array<Song> = [];
|
||||
album: Album = new Album(); // If album not found, will be replaced by 'undefined'
|
||||
moreDataAvailable = false;
|
||||
atBottom = false;
|
||||
|
||||
constructor(
|
||||
private elsService: ElsService,
|
||||
private route: ActivatedRoute,
|
||||
private location: Location
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.params
|
||||
.subscribe((params: Params) => this.albumName = params['name']);
|
||||
|
||||
this.loadSongs();
|
||||
|
||||
this.elsService.getAlbum(this.albumName).subscribe(data => this.album = data);
|
||||
}
|
||||
|
||||
loadSongs(): void {
|
||||
this.elsService.getAlbumSongs(this.albumName, this.songs.length).subscribe(
|
||||
data => {
|
||||
this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
|
||||
|
||||
// Erase song array with result for first load, then add elements one by one
|
||||
// instead use concat => concat will sort table at each load, very consuming! and not user friendly
|
||||
if (this.songs.length === 0) {
|
||||
this.songs = data;
|
||||
} else {
|
||||
data.forEach(song => {
|
||||
this.songs.push(song);
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
scrollTop(): void {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle scroll:
|
||||
* - load data if at bottom of screen (if needed)
|
||||
* - hide/show "go to top" button
|
||||
*
|
||||
* @param event scroll event
|
||||
*/
|
||||
onScroll(event: any) {
|
||||
if (this.moreDataAvailable &&
|
||||
(window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
|
||||
this.loadSongs();
|
||||
}
|
||||
|
||||
if (window.scrollY > window.innerHeight) {
|
||||
this.atBottom = true;
|
||||
}
|
||||
|
||||
if (window.scrollY === 0) {
|
||||
this.atBottom = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
dashboard/src/app/app-routing.module.ts
Normal file
22
dashboard/src/app/app-routing.module.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { DashboardComponent } from './dashboard.component';
|
||||
import { AlbumComponent } from './album/album.component';
|
||||
import { ArtistComponent } from './artist/artist.component';
|
||||
import { GenreComponent } from './genre/genre.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
|
||||
{ path: 'dashboard', component: DashboardComponent },
|
||||
{ path: 'album/:name', component: AlbumComponent },
|
||||
{ path: 'artist/:name', component: ArtistComponent },
|
||||
{ path: 'genre/:name', component: GenreComponent }
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [ RouterModule.forRoot(routes) ],
|
||||
exports: [ RouterModule ]
|
||||
})
|
||||
|
||||
export class AppRoutingModule {}
|
||||
45
dashboard/src/app/app.component.css
Normal file
45
dashboard/src/app/app.component.css
Normal file
@@ -0,0 +1,45 @@
|
||||
h1 {
|
||||
font-size: 1.2em;
|
||||
color: #999;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 2em;
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
nav a {
|
||||
padding: 5px 10px;
|
||||
text-decoration: none;
|
||||
margin-top: 10px;
|
||||
margin-left: 10px;
|
||||
display: inline-block;
|
||||
background-color: #eee;
|
||||
border-radius: 4px;
|
||||
}
|
||||
/*
|
||||
nav a:visited, a:link {
|
||||
color: #607D8B;
|
||||
}
|
||||
|
||||
nav a:hover {
|
||||
color: #039be5;
|
||||
background-color: #CFD8DC;
|
||||
}
|
||||
|
||||
nav a.active {
|
||||
color: #039be5;
|
||||
} */
|
||||
|
||||
|
||||
/* FIXME Code Repetition */
|
||||
.btn-top {
|
||||
display: inline-block;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
|
||||
-moz-transition: opacity .3s 0s, visibility 0s 0s;
|
||||
transition: opacity .3s 0s, visibility 0s 0s;
|
||||
}
|
||||
4
dashboard/src/app/app.component.html
Normal file
4
dashboard/src/app/app.component.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<nav>
|
||||
<a class="btn-top" routerLink="/dashboard" routerLinkActive="active"><span class="glyphicon glyphicon-home"></span></a>
|
||||
</nav>
|
||||
<router-outlet></router-outlet>
|
||||
32
dashboard/src/app/app.component.spec.ts
Normal file
32
dashboard/src/app/app.component.spec.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create the app', async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
}));
|
||||
|
||||
it(`should have as title 'app'`, async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app.title).toEqual('app');
|
||||
}));
|
||||
|
||||
it('should render title in a h1 tag', async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.debugElement.nativeElement;
|
||||
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
|
||||
}));
|
||||
});
|
||||
10
dashboard/src/app/app.component.ts
Normal file
10
dashboard/src/app/app.component.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.css']
|
||||
})
|
||||
export class AppComponent {
|
||||
title = 'app';
|
||||
}
|
||||
43
dashboard/src/app/app.module.ts
Normal file
43
dashboard/src/app/app.module.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { HttpModule } from '@angular/http';
|
||||
|
||||
import { TagCloudModule } from 'angular-tag-cloud-module';
|
||||
import { AgWordCloudModule } from 'angular4-word-cloud';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
import { DashboardComponent } from './dashboard.component';
|
||||
import { AlbumComponent } from './album/album.component';
|
||||
import { ArtistComponent } from './artist/artist.component';
|
||||
import { GenreComponent } from './genre/genre.component';
|
||||
|
||||
import { ElsService } from './els.service';
|
||||
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
|
||||
import { ConvertMsPipe } from './convertms.pipe';
|
||||
import { SortByPipe } from './sort-by.pipe';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
HttpModule,
|
||||
TagCloudModule,
|
||||
AgWordCloudModule.forRoot(),
|
||||
AppRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
AppComponent,
|
||||
DashboardComponent,
|
||||
AlbumComponent,
|
||||
ArtistComponent,
|
||||
GenreComponent,
|
||||
ConvertMsPipe,
|
||||
SortByPipe
|
||||
],
|
||||
providers: [
|
||||
ElsService
|
||||
],
|
||||
bootstrap: [ AppComponent ]
|
||||
})
|
||||
export class AppModule { }
|
||||
0
dashboard/src/app/artist/artist.component.css
Normal file
0
dashboard/src/app/artist/artist.component.css
Normal file
128
dashboard/src/app/artist/artist.component.html
Normal file
128
dashboard/src/app/artist/artist.component.html
Normal file
@@ -0,0 +1,128 @@
|
||||
<div class="container">
|
||||
<h1>{{artistName}}</h1>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
<h3>Debug Zone</h3>
|
||||
Returned song: {{songs.length}}<br />
|
||||
Theorical song: {{ artist ? artist['Track Count'] : "" }}
|
||||
<span *ngIf="artist && (songs.length == artist['Track Count'])" class="glyphicon glyphicon-ok" style="color:green"></span>
|
||||
<span *ngIf="artist && (songs.length != artist['Track Count'])" class="glyphicon glyphicon-remove" style="color:red"></span>
|
||||
</div>
|
||||
|
||||
<div class="row cardAdmin">
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-yellow">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-star stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="artist">{{artist.Rating}}/100</h3>
|
||||
</div>
|
||||
<div>Rating</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-cd stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="artist">{{artist.Album?.length}}</h3>
|
||||
</div>
|
||||
<div>Albums</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-green">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-list-alt stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="artist">{{artist['Track Count']}}</h3>
|
||||
</div>
|
||||
<div>Songs</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-purple">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-headphones stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!artist"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="artist">{{artist['Play Count']}} list.</h3>
|
||||
</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>
|
||||
|
||||
<table class="table table-striped" (window:scroll)="onScroll($event)">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Name</th>
|
||||
<th>Album</th>
|
||||
<th>Year</th>
|
||||
<th>Artist</th>
|
||||
<th>Album Artist</th>
|
||||
<th>Play Count</th>
|
||||
<th>Genre</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let song of songs | sortBy : 'Year':'Album':'Track Number'">
|
||||
<td>{{song['Track Number'] ? (("0" + song['Track Number']).slice(-2)) : "--"}}</td>
|
||||
<td>{{song.Name}}</td>
|
||||
<td><a [routerLink]="['/album', song.Album]">{{song.Album}}</a></td>
|
||||
<td>{{song.Year}}</td>
|
||||
<td><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td>
|
||||
<td>{{song['Album Artist'] ? song['Album Artist'] : "-" }}</td>
|
||||
<td>{{song['Play Count']}}</td>
|
||||
<td><a [routerLink]="['/genre', song.Genre]">{{song.Genre}}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="button" *ngIf="moreDataAvailable" class="btn btn-default" aria-label="More" (click)="loadSongs()">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> More...
|
||||
</button>
|
||||
|
||||
<!-- Go to Top Button-->
|
||||
<button type="button" class="btn btn-warning btn-top" [class.btn-top-is-visible]="atBottom"
|
||||
aria-label="Top" (click)="scrollTop()" title="Go back to Top!">
|
||||
<span class="glyphicon glyphicon-menu-up" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary btn-top btn-sort" [class.btn-top-is-visible]="sortable"
|
||||
aria-label="Top" (click)="sort()" title="Sort by Album & Track Number">
|
||||
<span class="glyphicon glyphicon-sort-by-attributes" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
25
dashboard/src/app/artist/artist.component.spec.ts
Normal file
25
dashboard/src/app/artist/artist.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ArtistComponent } from './artist.component';
|
||||
|
||||
describe('ArtistComponent', () => {
|
||||
let component: ArtistComponent;
|
||||
let fixture: ComponentFixture<ArtistComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ArtistComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ArtistComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
99
dashboard/src/app/artist/artist.component.ts
Normal file
99
dashboard/src/app/artist/artist.component.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { Location } from '@angular/common';
|
||||
|
||||
import { ElsService } from './../els.service';
|
||||
import { Song } from './../object/song';
|
||||
import { Artist } from './../object/artist';
|
||||
|
||||
import { SortByPipe } from './../sort-by.pipe';
|
||||
|
||||
@Component({
|
||||
selector: 'app-artist',
|
||||
templateUrl: './artist.component.html',
|
||||
styleUrls: [ './../album/album.component.css', './../dashboard.component.css' ]
|
||||
})
|
||||
|
||||
export class ArtistComponent implements OnInit {
|
||||
artistName = '';
|
||||
songs: Array<Song> = [];
|
||||
artist: Artist = new Artist();
|
||||
// To activate button in interface var
|
||||
moreDataAvailable = false;
|
||||
atBottom = false;
|
||||
sortable = false;
|
||||
|
||||
lockLoadData = false;
|
||||
|
||||
constructor(
|
||||
private elsService: ElsService,
|
||||
private route: ActivatedRoute,
|
||||
private location: Location
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.params.subscribe((params: Params) => this.artistName = params['name']);
|
||||
|
||||
this.elsService.getArtist(this.artistName).subscribe(data => this.artist = data);
|
||||
this.loadSongs();
|
||||
}
|
||||
|
||||
// TODO Duplicate code!
|
||||
loadSongs(): void {
|
||||
if (this.lockLoadData) {
|
||||
console.log('Loading data locked');
|
||||
return;
|
||||
}
|
||||
|
||||
this.lockLoadData = true;
|
||||
this.elsService.getArtistSongs(this.artistName, this.songs.length).subscribe(
|
||||
data => {
|
||||
this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
|
||||
|
||||
// Erase song array with result for first load, then add elements one by one
|
||||
// instead use concat => concat will sort table at each load, very consuming! and not user friendly
|
||||
if (this.songs.length === 0) {
|
||||
this.songs = data;
|
||||
} else {
|
||||
this.sortable = true;
|
||||
data.forEach(song => {
|
||||
this.songs.push(song);
|
||||
});
|
||||
}
|
||||
console.log('Unlock load data');
|
||||
this.lockLoadData = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
scrollTop(): void {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle scroll:
|
||||
* - load data if at bottom of screen (if needed)
|
||||
* - hide/show "go to top" button
|
||||
*
|
||||
* @param event scroll event
|
||||
*/
|
||||
onScroll(event: any) {
|
||||
if (this.moreDataAvailable &&
|
||||
(window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
|
||||
this.loadSongs();
|
||||
}
|
||||
|
||||
if (window.scrollY > window.innerHeight) {
|
||||
this.atBottom = true;
|
||||
}
|
||||
|
||||
if (window.scrollY === 0) {
|
||||
this.atBottom = false;
|
||||
}
|
||||
}
|
||||
|
||||
sort(): void {
|
||||
this.songs = new SortByPipe().transform(this.songs, 'Year', 'Album', 'Track Number', 'Play Count');
|
||||
this.sortable = false;
|
||||
}
|
||||
}
|
||||
8
dashboard/src/app/convertms.pipe.spec.ts
Normal file
8
dashboard/src/app/convertms.pipe.spec.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { ConvertmsPipe } from './convertms.pipe';
|
||||
|
||||
describe('ConvertmsPipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new ConvertmsPipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
34
dashboard/src/app/convertms.pipe.ts
Normal file
34
dashboard/src/app/convertms.pipe.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'convertMs'
|
||||
})
|
||||
export class ConvertMsPipe implements PipeTransform {
|
||||
|
||||
transform(timeMs: number): string {
|
||||
let x = timeMs / 1000;
|
||||
|
||||
const seconds = Math.round(x % 60);
|
||||
x /= 60;
|
||||
|
||||
let minutes = 0;
|
||||
if (x > 1) { minutes = Math.round(x % 60); }
|
||||
x /= 60;
|
||||
|
||||
let hours = 0;
|
||||
if (x > 1) { hours = Math.round(x % 24); }
|
||||
// TODO Enable/disable day
|
||||
x /= 24;
|
||||
const days = Math.round(x);
|
||||
|
||||
// Final string
|
||||
let ret = '';
|
||||
if (days > 0) { ret += ('0' + days).slice(-2) + ':'; }
|
||||
if (hours > 0) { ret += ('0' + hours).slice(-2) + ':'; }
|
||||
if (minutes > 0) { ret += ('0' + minutes).slice(-2) + ':'; }
|
||||
if (seconds > 0) { ret += ('0' + seconds).slice(-2); }
|
||||
|
||||
return ret;
|
||||
// return ('0' + days).slice(-2) + ':' + ('0' + hours).slice(-2) + ':' + ('0' + minutes).slice(-2) + ':' + ('0' + seconds).slice(-2);
|
||||
}
|
||||
}
|
||||
38
dashboard/src/app/dashboard.component.css
Normal file
38
dashboard/src/app/dashboard.component.css
Normal file
@@ -0,0 +1,38 @@
|
||||
.panel-stat {
|
||||
min-height: 102px;
|
||||
}
|
||||
|
||||
.panel-green {
|
||||
background-color: #16a085;
|
||||
color:white;
|
||||
}
|
||||
.panel-yellow {
|
||||
background-color: #f1c40f;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.panel-red {
|
||||
background-color: #d9534f;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.panel-purple {
|
||||
background-color: #9b59b6;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.panel-blue {
|
||||
background-color: #3498db;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.stats_icon {
|
||||
font-size: 3em;
|
||||
}
|
||||
|
||||
.circle {
|
||||
border-radius: 50%;
|
||||
background-color: #9b59b6;
|
||||
margin: 0 auto;
|
||||
|
||||
}
|
||||
171
dashboard/src/app/dashboard.component.html
Normal file
171
dashboard/src/app/dashboard.component.html
Normal file
@@ -0,0 +1,171 @@
|
||||
<div class="container">
|
||||
<h1>iTunes stats</h1>
|
||||
|
||||
<br />
|
||||
<div class="row cardAdmin">
|
||||
<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="!totalTime"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="totalTime">{{totalTime | convertMs}}</h3>
|
||||
</div>
|
||||
<div><br>Total time</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-green">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-hdd stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!totalSizeSt"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="totalSizeSt">{{totalSizeSt}}</h3>
|
||||
</div>
|
||||
<div><br>Total size</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-yellow">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-play stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!trackCountSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="trackCountSong">{{trackCountSong}}</h3>
|
||||
</div>
|
||||
<div><br>Total Songs</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-red">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-stop stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!neverListenSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="neverListenSong">{{neverListenSong}}</h3>
|
||||
</div>
|
||||
<div><br>Never list. songs</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<h3>Last added albums</h3>
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Album</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let album of lastAddedAlbums">
|
||||
<td><a [routerLink]="['/album', album.key]">{{album.key}}</a></td>
|
||||
<td>{{album.doc_count}}</td>
|
||||
<td><a [routerLink]="['/artist', albumArtists[album.key]]">{{albumArtists[album.key]}}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h3>Top Played Songs</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Track Name</th>
|
||||
<th>Artist</th>
|
||||
<th>Album</th>
|
||||
<th>Play Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let song of mostPlayedSongs">
|
||||
<td><b>{{song.Name}}</b></td>
|
||||
<td><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td>
|
||||
<td><a [routerLink]="['/album', song.Album]">{{song.Album}}</a></td>
|
||||
<td>{{song['Play Count']}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="col-md-6">
|
||||
<h3>Top Genres</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Genre</th>
|
||||
<th>Track Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let genre of topGenres">
|
||||
<td><a [routerLink]="['/genre', genre.key]">{{genre.key}}</a></td>
|
||||
<td>{{genre.doc_count}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h3>Bottom Genres</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Genre</th>
|
||||
<th>Track Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let genre of bottomGenres">
|
||||
<td><a [routerLink]="['/genre', genre.key]">{{genre.key}}</a></td>
|
||||
<td>{{genre.doc_count}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<angular-tag-cloud
|
||||
[data]="wordCloud"
|
||||
[width]="options.width"
|
||||
[height]="options.height"
|
||||
[overflow]="options.overflow">
|
||||
</angular-tag-cloud>
|
||||
</div>
|
||||
|
||||
|
||||
<div AgWordCloud
|
||||
#word_cloud_chart=ag-word-cloud
|
||||
[wordData]="word_cloud">
|
||||
</div>
|
||||
|
||||
<button (click)="word_cloud_chart.update()">Toggle tooltip</button>
|
||||
|
||||
</div>
|
||||
148
dashboard/src/app/dashboard.component.ts
Normal file
148
dashboard/src/app/dashboard.component.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { Component, OnInit, ViewChild, ViewChildren } from '@angular/core';
|
||||
|
||||
import { CloudData, CloudOptions } from 'angular-tag-cloud-module';
|
||||
import { AgWordCloudData, AgWordCloudDirective } from 'angular4-word-cloud';
|
||||
|
||||
import { ElsService } from './els.service';
|
||||
import { Song } from './object/song';
|
||||
import { Bucket } from './object/bucket';
|
||||
import { Album } from './object/album';
|
||||
import { Artist } from './object/artist';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard',
|
||||
templateUrl: './dashboard.component.html',
|
||||
styleUrls: [ './dashboard.component.css' ]
|
||||
})
|
||||
|
||||
export class DashboardComponent implements OnInit {
|
||||
totalTime = 0;
|
||||
totalSize = 0;
|
||||
totalSizeSt = '';
|
||||
trackCountSong = 0;
|
||||
trackCountArtist = 0;
|
||||
trackCountAlbum = 0;
|
||||
neverListenSong = 0;
|
||||
|
||||
albumArtistCount = 0;
|
||||
|
||||
topGenres: Bucket[] = [];
|
||||
bottomGenres: Bucket[] = [];
|
||||
|
||||
mostPlayedSongs: Song[] = [];
|
||||
|
||||
lastAddedAlbums: Bucket[] = [];
|
||||
albumArtists = [];
|
||||
|
||||
/**
|
||||
* Test of angular-tag-cloud-module (https://www.npmjs.com/package/angular-tag-cloud-module)
|
||||
*/
|
||||
options: CloudOptions = {
|
||||
// if width is between 0 and 1 it will be set to the size of the upper element multiplied by the value
|
||||
width : 1,
|
||||
height : 400,
|
||||
overflow: false,
|
||||
};
|
||||
|
||||
wordCloud: Array<CloudData> = [];
|
||||
|
||||
/**
|
||||
* Test of angular4-word-cloud (https://www.npmjs.com/package/angular4-word-cloud)
|
||||
*/
|
||||
word_cloud: Array<AgWordCloudData> = [];
|
||||
|
||||
@ViewChild('word_cloud_chart') testTruc: AgWordCloudDirective;
|
||||
|
||||
constructor(private elsService: ElsService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.elsService.getTime().then(result => {
|
||||
this.totalTime = result;
|
||||
});
|
||||
|
||||
this.elsService.getSize().then(result => {
|
||||
this.totalSize = result;
|
||||
this.totalSizeSt = this.convertSizeToString(result);
|
||||
});
|
||||
|
||||
this.elsService.getCountSong('song')
|
||||
.then(result => this.trackCountSong = result);
|
||||
this.elsService.getCountSong('artist')
|
||||
.then(result => this.trackCountArtist = result);
|
||||
this.elsService.getCountSong('album')
|
||||
.then(result => this.trackCountAlbum = result);
|
||||
|
||||
this.elsService.getCountNeverListenSong()
|
||||
.then(result => this.neverListenSong = result);
|
||||
|
||||
this.elsService.getMostPlayedTrack().subscribe(
|
||||
data => this.mostPlayedSongs = data
|
||||
);
|
||||
|
||||
this.elsService.getGenres().subscribe(data => {
|
||||
this.topGenres = data.slice(0, 10);
|
||||
|
||||
/** angular-tag-cloud-module **/
|
||||
const changedData: Observable<Array<CloudData>> = Observable.of(
|
||||
data.map(element => {
|
||||
return {weight: element.doc_count, text: element.key, link: '/genre/' + element.key};
|
||||
})
|
||||
);
|
||||
changedData.subscribe(res => this.wordCloud = res);
|
||||
|
||||
data.forEach((el) => {
|
||||
this.word_cloud.push({size: el.doc_count, text: el.key});
|
||||
});
|
||||
this.testTruc.update();
|
||||
});
|
||||
this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data.slice(0, 10).reverse());
|
||||
// this.elsService.getGenreCount().subscribe(data => console.log(data));
|
||||
|
||||
this.elsService.getLastAddedAlbums(6).subscribe(buckets => {
|
||||
this.lastAddedAlbums = buckets;
|
||||
buckets.forEach(bucket => this.getArtistName(bucket));
|
||||
});
|
||||
}
|
||||
|
||||
private getArtistName(albumBucket: Bucket) {
|
||||
// For each bucket.key (album name), search artist.
|
||||
// Use track count to compare
|
||||
this.elsService.getArtistFromAlbumName(albumBucket.key).subscribe(albums => {
|
||||
if (albums.length > 1) {
|
||||
// More than one result for an album name
|
||||
// Search good artist by track count
|
||||
albums.forEach(album => {
|
||||
if (album['Track Count'] === albumBucket.doc_count) {
|
||||
this.albumArtists[album.Name] = album.Artist.toString();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Just one artistresult for album name
|
||||
this.albumArtists[albums[0].Name] = albums[0].Artist.toString();
|
||||
}
|
||||
if (this.albumArtists[albums[0].Name].length > 50) {
|
||||
this.albumArtists[albums[0].Name] = this.albumArtists[albums[0].Name].substring(0, 50) + '...';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* UTILS FUNCTION - TODO MOVE
|
||||
*/
|
||||
|
||||
convertSizeToString(size: number) {
|
||||
const units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||
|
||||
if (size === 0) {
|
||||
return '0 Byte';
|
||||
}
|
||||
|
||||
const 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];
|
||||
}
|
||||
}
|
||||
15
dashboard/src/app/els.service.spec.ts
Normal file
15
dashboard/src/app/els.service.spec.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { ElsService } from './els.service';
|
||||
|
||||
describe('ElsService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ElsService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ElsService], (service: ElsService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
390
dashboard/src/app/els.service.ts
Normal file
390
dashboard/src/app/els.service.ts
Normal file
@@ -0,0 +1,390 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Headers, Http } from '@angular/http';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/toPromise';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
import { Song } from './object/song';
|
||||
import { Album } from './object/album';
|
||||
import { Artist } from './object/artist';
|
||||
import { Bucket } from './object/bucket';
|
||||
|
||||
@Injectable()
|
||||
export class ElsService {
|
||||
public static readonly DEFAULT_SIZE: number = 50;
|
||||
private static readonly INDEX_NAME = 'itunessongs';
|
||||
|
||||
private static readonly ACTION_SEARCH = '/_search';
|
||||
private static readonly ACTION_COUNT = '/_count';
|
||||
|
||||
private elsUrl = 'http://localhost:9200/' + ElsService.INDEX_NAME + '/';
|
||||
private headers = new Headers({'Content-Type': 'application/json'});
|
||||
|
||||
constructor(private http: Http) { }
|
||||
|
||||
getTime(): Promise<number> {
|
||||
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);
|
||||
}
|
||||
|
||||
getTimeSlowly(): Promise<number> {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(this.getTime()), 2000);
|
||||
});
|
||||
}
|
||||
|
||||
getSize(): Promise<number> {
|
||||
return this.http
|
||||
.post(this.elsUrl + ElsService.ACTION_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);
|
||||
}
|
||||
|
||||
getSizeSlowly(): Promise<number> {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(this.getSize()), 2000);
|
||||
});
|
||||
}
|
||||
|
||||
getCountSong(type: string): Promise<number> {
|
||||
return this.http
|
||||
.get(this.elsUrl + type + ElsService.ACTION_COUNT)
|
||||
.toPromise()
|
||||
.then(res => res.json().count as number)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getCountNeverListenSong(): Promise<number> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_COUNT,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'bool': {
|
||||
'must_not': {
|
||||
'exists': { 'field': 'Play Count'}
|
||||
}
|
||||
}
|
||||
}
|
||||
}), {headers: this.headers})
|
||||
.toPromise()
|
||||
.then(res => res.json().count as number)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getTrackCountSlowly(type: string): Promise<number> {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(this.getCountSong(type)), 2000);
|
||||
});
|
||||
}
|
||||
|
||||
getMostPlayedTrack(): Observable<Song[]> {
|
||||
// Thank to http://chariotsolutions.com/blog/post/angular2-observables-http-separating-services-components/
|
||||
// for the map part
|
||||
|
||||
// Could be shorter but I think it's more readable like this.
|
||||
return this.http
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'sort': [ {
|
||||
'Play Count': {
|
||||
'order': 'desc'
|
||||
}
|
||||
} ],
|
||||
'size': 5
|
||||
}), {headers: this.headers})
|
||||
.map(res => {
|
||||
return res.json().hits.hits;
|
||||
})
|
||||
.map((hits: Array<any>) => {
|
||||
const result: Array<Song> = [];
|
||||
hits.forEach((hit) => {
|
||||
result.push(hit._source);
|
||||
});
|
||||
return result;
|
||||
});
|
||||
// Shorter way:
|
||||
// .map(res => {
|
||||
// let result: Array<Song> = [];
|
||||
// res.json().hits.hits.forEach(element => {
|
||||
// result.push(element._source);
|
||||
// });
|
||||
// return result;
|
||||
// });
|
||||
}
|
||||
|
||||
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
|
||||
console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from);
|
||||
return this.http
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'match_phrase': { 'Album': albumName }
|
||||
},
|
||||
'size': ElsService.DEFAULT_SIZE,
|
||||
'from': from
|
||||
}), {headers: this.headers})
|
||||
.map(res => {
|
||||
return res.json().hits.hits;
|
||||
})
|
||||
.map((hits: Array<any>) => {
|
||||
const result: Array<Song> = [];
|
||||
hits.forEach((hit) => {
|
||||
result.push(hit._source);
|
||||
});
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
getGenreSongs(genreName: string, from: number = 0): Observable<Song[]> {
|
||||
console.info('getGenreSongs- Genre name: ' + genreName + ' - from: ' + from);
|
||||
// TODO Code repetition => to refactor
|
||||
return this.http
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'match_phrase': { 'Genre': genreName }
|
||||
},
|
||||
'size': ElsService.DEFAULT_SIZE,
|
||||
'from': from
|
||||
}), {headers: this.headers})
|
||||
.map(res => {
|
||||
return res.json().hits.hits;
|
||||
})
|
||||
.map((hits: Array<any>) => {
|
||||
const result: Array<Song> = [];
|
||||
hits.forEach((hit) => {
|
||||
result.push(hit._source);
|
||||
});
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
getArtistSongs(artistName: string, from: number = 0): Observable<Song[]> {
|
||||
console.info('getArtistSongs- Artist name: ' + artistName + ' - from: ' + from);
|
||||
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
|
||||
}), {headers: this.headers})
|
||||
.map(res => {
|
||||
return res.json().hits.hits;
|
||||
})
|
||||
.map((hits: Array<any>) => {
|
||||
const result: Array<Song> = [];
|
||||
hits.forEach((hit) => {
|
||||
result.push(hit._source);
|
||||
});
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
getAlbum(albumName: string): Observable<Album> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'album' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'match_phrase': { 'Album': albumName }
|
||||
},
|
||||
'size': ElsService.DEFAULT_SIZE
|
||||
}), {headers: this.headers})
|
||||
.map(res => {
|
||||
return res.json().hits.hits;
|
||||
})
|
||||
.map((hits: Array<any>) => {
|
||||
if (hits.length < 1) {
|
||||
console.info('No album "' + albumName + '" found.');
|
||||
return undefined;
|
||||
}
|
||||
if (hits.length > 1) {
|
||||
console.error('More than one album "' + albumName + '" found (' + hits.length + '), return the first.');
|
||||
}
|
||||
return hits[0]._source;
|
||||
});
|
||||
}
|
||||
|
||||
getArtist(artistName: string): Observable<Artist> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'artist' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'match_phrase': { 'Artist': artistName }
|
||||
},
|
||||
'size': ElsService.DEFAULT_SIZE
|
||||
}), {headers: this.headers})
|
||||
.map(res => res.json().hits.hits)
|
||||
.map((hits: Array<any>) => {
|
||||
// Theorically, my script prevent to found two documents with this query.
|
||||
// But Prevention is better than cure as Shakespeare said
|
||||
if (hits.length < 1) {
|
||||
console.info('No artist "' + artistName + '" found.');
|
||||
return undefined;
|
||||
}
|
||||
if (hits.length > 1) {
|
||||
console.error('More than one artist "' + artistName + '" found (' + hits.length + '), return the first.');
|
||||
console.error('This is not normal!');
|
||||
}
|
||||
return hits[0]._source;
|
||||
});
|
||||
}
|
||||
|
||||
getGenres(ordering: string = 'desc'): Observable<Bucket[]> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'aggs' : {
|
||||
'genres' : {
|
||||
'terms' : {
|
||||
'field' : 'Genre.original',
|
||||
'size' : 100,
|
||||
'missing': 'N/A',
|
||||
'order': { '_count' : ordering }
|
||||
}
|
||||
}
|
||||
},
|
||||
'size': 0
|
||||
}), {headers: this.headers})
|
||||
.map(res => res.json().aggregations.genres.buckets)
|
||||
.map((hits: Array<any>) => this.hitsToBuckets(hits));
|
||||
}
|
||||
|
||||
getArtists(): Observable<Bucket[]> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'artist' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'size': 100,
|
||||
'_source': [
|
||||
'Artist',
|
||||
'Track Count'
|
||||
],
|
||||
'sort': [
|
||||
{
|
||||
'Track Count': {
|
||||
'order': 'desc'
|
||||
}
|
||||
}
|
||||
]
|
||||
}), {headers: this.headers})
|
||||
.map(res => {
|
||||
return res.json().hits.hits;
|
||||
})
|
||||
.map((hits: Array<any>) => {
|
||||
const result: Array<Bucket> = [];
|
||||
hits.forEach((hit) => {
|
||||
const bucket = new Bucket;
|
||||
bucket.doc_count = hit._source['Track Count'];
|
||||
bucket.key = hit._source.Artist;
|
||||
result.push(bucket);
|
||||
});
|
||||
console.log(result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
getGenreCount(): Observable<number> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'aggs' : {
|
||||
'genres' : {
|
||||
'cardinality' : {
|
||||
'field' : 'Genre.original',
|
||||
'missing': 'N/A',
|
||||
}
|
||||
}
|
||||
},
|
||||
'size': 0
|
||||
}), {headers: this.headers})
|
||||
.map(res => res.json().aggregations.genres.value);
|
||||
}
|
||||
|
||||
getLastAddedAlbums(month: number): Observable<Bucket[]> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'range' : {
|
||||
'Date Added' : {
|
||||
'gte' : 'now-' + month + 'M/d',
|
||||
'lte' : 'now/d'
|
||||
}
|
||||
}
|
||||
},
|
||||
'aggs' : {
|
||||
'album' : {
|
||||
'terms' : {
|
||||
'field' : 'Album.original',
|
||||
'size': 10
|
||||
}
|
||||
}
|
||||
},
|
||||
'size': 0
|
||||
}), {headers: this.headers})
|
||||
.map(res => res.json().aggregations.album.buckets)
|
||||
// TODO Take in consideration "sum_other_doc_count"
|
||||
.map((hits: Array<any>) => this.hitsToBuckets(hits));
|
||||
}
|
||||
|
||||
getArtistFromAlbumName(albumname: string): Observable<Album[]> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'album' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'match_phrase' : {
|
||||
'Album' : albumname
|
||||
}
|
||||
}
|
||||
}), {headers: this.headers})
|
||||
.map(res => res.json().hits.hits)
|
||||
.map((hits: Array<any>) => {
|
||||
// TODO Use a method (duplicated code ?)
|
||||
const result: Array<Album> = [];
|
||||
hits.forEach((hit) => {
|
||||
result.push(hit._source);
|
||||
});
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
private hitsToBuckets(hits: Array<any>): Bucket[] {
|
||||
const result: Array<Bucket> = [];
|
||||
hits.forEach((bucket) => {
|
||||
result.push(bucket);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private handleError(error: any): Promise<any> {
|
||||
console.error('An error occurred', error); // for demo purposes only
|
||||
return Promise.reject(error.message || error);
|
||||
}
|
||||
}
|
||||
0
dashboard/src/app/genre/genre.component.css
Normal file
0
dashboard/src/app/genre/genre.component.css
Normal file
28
dashboard/src/app/genre/genre.component.html
Normal file
28
dashboard/src/app/genre/genre.component.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<div class="container">
|
||||
<h1>{{genreName}}</h1>
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Name</th>
|
||||
<th>Artist</th>
|
||||
<th>Album</th>
|
||||
<th>Album Artist</th>
|
||||
<th>Play Count</th>
|
||||
<th>Genre</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let song of songs | sortBy : 'Track Number'">
|
||||
<td>{{song['Track Number'] ? (("0" + song['Track Number']).slice(-2)) : "--"}}</td>
|
||||
<td>{{song.Name}}</td>
|
||||
<td><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td>
|
||||
<td><a [routerLink]="['/album', song.Album]">{{song.Album}}</a></td>
|
||||
<td>{{song['Album Artist']}}</td>
|
||||
<td>{{song['Play Count']}}</td>
|
||||
<td>{{song.Genre}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
25
dashboard/src/app/genre/genre.component.spec.ts
Normal file
25
dashboard/src/app/genre/genre.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { GenreComponent } from './genre.component';
|
||||
|
||||
describe('GenreComponent', () => {
|
||||
let component: GenreComponent;
|
||||
let fixture: ComponentFixture<GenreComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ GenreComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(GenreComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
47
dashboard/src/app/genre/genre.component.ts
Normal file
47
dashboard/src/app/genre/genre.component.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
|
||||
import { ElsService } from '../els.service';
|
||||
|
||||
import { Song } from '../object/song';
|
||||
|
||||
@Component({
|
||||
selector: 'app-genre',
|
||||
templateUrl: './genre.component.html',
|
||||
styleUrls: ['./genre.component.css']
|
||||
})
|
||||
export class GenreComponent implements OnInit {
|
||||
genreName = '';
|
||||
songs: Array<Song> = [];
|
||||
|
||||
constructor(
|
||||
private elsService: ElsService,
|
||||
private route: ActivatedRoute
|
||||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.route.params
|
||||
.subscribe((params: Params) => this.genreName = params['name']);
|
||||
|
||||
this.loadSongs();
|
||||
}
|
||||
|
||||
loadSongs(): any {
|
||||
this.elsService.getGenreSongs(this.genreName, this.songs.length).subscribe(
|
||||
data => {
|
||||
// this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
|
||||
|
||||
// Erase song array with result for first load, then add elements one by one
|
||||
// instead use concat => concat will sort table at each load, very consuming! and not user friendly
|
||||
if (this.songs.length === 0) {
|
||||
this.songs = data;
|
||||
} else {
|
||||
data.forEach(song => {
|
||||
this.songs.push(song);
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
13
dashboard/src/app/object/album.ts
Normal file
13
dashboard/src/app/object/album.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export class Album {
|
||||
Name: string;
|
||||
Album: string;
|
||||
Artist: Array<string>;
|
||||
Rating: number;
|
||||
Genre: Array<string>;
|
||||
'Track Count': number;
|
||||
'Album Rating': number;
|
||||
'Persistent ID': string;
|
||||
'Album Rating Computed': boolean;
|
||||
'Play Count': number;
|
||||
'Total Time': number;
|
||||
}
|
||||
10
dashboard/src/app/object/artist.ts
Normal file
10
dashboard/src/app/object/artist.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export class Artist {
|
||||
Name: string;
|
||||
Album: string[];
|
||||
Artist: string;
|
||||
Rating: number;
|
||||
Genre: Array<string>;
|
||||
'Track Count': number;
|
||||
'Persistent ID': string;
|
||||
'Play Count': number;
|
||||
}
|
||||
4
dashboard/src/app/object/bucket.ts
Normal file
4
dashboard/src/app/object/bucket.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export class Bucket {
|
||||
key: string;
|
||||
doc_count: number;
|
||||
}
|
||||
7
dashboard/src/app/object/song.ts
Normal file
7
dashboard/src/app/object/song.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export class Song {
|
||||
Name: string;
|
||||
Artist: string;
|
||||
'Play Count': number;
|
||||
Album: string;
|
||||
'Track Number': number; // TODO Default property
|
||||
}
|
||||
8
dashboard/src/app/sort-by.pipe.spec.ts
Normal file
8
dashboard/src/app/sort-by.pipe.spec.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SortByPipe } from './sort-by.pipe';
|
||||
|
||||
describe('SortByPipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new SortByPipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
24
dashboard/src/app/sort-by.pipe.ts
Normal file
24
dashboard/src/app/sort-by.pipe.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'sortBy'
|
||||
})
|
||||
export class SortByPipe implements PipeTransform {
|
||||
|
||||
transform(array: Array<any>, ...args: any[]): Array<any> {
|
||||
array.sort((a: any, b: any) => {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const arg = args[i];
|
||||
|
||||
if (a[arg] === undefined && b[arg] !== undefined) { return -1; }
|
||||
if (a[arg] !== undefined && b[arg] === undefined) { return 1; }
|
||||
|
||||
if (a[arg] < b[arg]) { return -1; }
|
||||
if (a[arg] > b[arg]) { return 1; }
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
return array;
|
||||
}
|
||||
|
||||
}
|
||||
0
dashboard/src/assets/.gitkeep
Normal file
0
dashboard/src/assets/.gitkeep
Normal file
3
dashboard/src/environments/environment.prod.ts
Normal file
3
dashboard/src/environments/environment.prod.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const environment = {
|
||||
production: true
|
||||
};
|
||||
8
dashboard/src/environments/environment.ts
Normal file
8
dashboard/src/environments/environment.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// The file contents for the current environment will overwrite these during build.
|
||||
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
|
||||
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
|
||||
// The list of which env maps to which file can be found in `.angular-cli.json`.
|
||||
|
||||
export const environment = {
|
||||
production: false
|
||||
};
|
||||
BIN
dashboard/src/favicon.ico
Normal file
BIN
dashboard/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
14
dashboard/src/index.html
Normal file
14
dashboard/src/index.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Dashboard</title>
|
||||
<base href="/">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
11
dashboard/src/main.ts
Normal file
11
dashboard/src/main.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { enableProdMode } from '@angular/core';
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
|
||||
import { AppModule } from './app/app.module';
|
||||
import { environment } from './environments/environment';
|
||||
|
||||
if (environment.production) {
|
||||
enableProdMode();
|
||||
}
|
||||
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
72
dashboard/src/polyfills.ts
Normal file
72
dashboard/src/polyfills.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* This file includes polyfills needed by Angular and is loaded before the app.
|
||||
* You can add your own extra polyfills to this file.
|
||||
*
|
||||
* This file is divided into 2 sections:
|
||||
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
||||
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
||||
* file.
|
||||
*
|
||||
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
||||
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
||||
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
||||
*
|
||||
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
|
||||
*/
|
||||
|
||||
/***************************************************************************************************
|
||||
* BROWSER POLYFILLS
|
||||
*/
|
||||
|
||||
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
|
||||
// import 'core-js/es6/symbol';
|
||||
// import 'core-js/es6/object';
|
||||
// import 'core-js/es6/function';
|
||||
// import 'core-js/es6/parse-int';
|
||||
// import 'core-js/es6/parse-float';
|
||||
// import 'core-js/es6/number';
|
||||
// import 'core-js/es6/math';
|
||||
// import 'core-js/es6/string';
|
||||
// import 'core-js/es6/date';
|
||||
// import 'core-js/es6/array';
|
||||
// import 'core-js/es6/regexp';
|
||||
// import 'core-js/es6/map';
|
||||
// import 'core-js/es6/weak-map';
|
||||
// import 'core-js/es6/set';
|
||||
|
||||
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
|
||||
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
||||
|
||||
/** Evergreen browsers require these. **/
|
||||
import 'core-js/es6/reflect';
|
||||
import 'core-js/es7/reflect';
|
||||
|
||||
|
||||
/**
|
||||
* Required to support Web Animations `@angular/animation`.
|
||||
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
|
||||
**/
|
||||
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
* Zone JS is required by Angular itself.
|
||||
*/
|
||||
import 'zone.js/dist/zone'; // Included with Angular CLI.
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
* APPLICATION IMPORTS
|
||||
*/
|
||||
|
||||
/**
|
||||
* Date, currency, decimal and percent pipes.
|
||||
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
|
||||
*/
|
||||
// import 'intl'; // Run `npm install --save intl`.
|
||||
/**
|
||||
* Need to import at least one locale-data with intl.
|
||||
*/
|
||||
// import 'intl/locale-data/jsonp/en';
|
||||
38
dashboard/src/styles.css
Normal file
38
dashboard/src/styles.css
Normal file
@@ -0,0 +1,38 @@
|
||||
/* Master Styles */
|
||||
h1 {
|
||||
color: #369;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-size: 250%;
|
||||
}
|
||||
|
||||
h2, h3 {
|
||||
color: #444;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-weight: lighter;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 2em;
|
||||
}
|
||||
|
||||
body, input[text], button {
|
||||
color: #888;
|
||||
font-family: Cambria, Georgia;
|
||||
}
|
||||
|
||||
.loading {
|
||||
-animation: spin 1.5s infinite linear;
|
||||
-webkit-animation: spin2 1.5s infinite linear;
|
||||
}
|
||||
|
||||
@-webkit-keyframes spin2 {
|
||||
from { -webkit-transform: rotate(0deg);}
|
||||
to { -webkit-transform: rotate(360deg);}
|
||||
}
|
||||
|
||||
|
||||
/* . . . */
|
||||
/* everywhere else */
|
||||
* {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
32
dashboard/src/test.ts
Normal file
32
dashboard/src/test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||
|
||||
import 'zone.js/dist/long-stack-trace-zone';
|
||||
import 'zone.js/dist/proxy.js';
|
||||
import 'zone.js/dist/sync-test';
|
||||
import 'zone.js/dist/jasmine-patch';
|
||||
import 'zone.js/dist/async-test';
|
||||
import 'zone.js/dist/fake-async-test';
|
||||
import { getTestBed } from '@angular/core/testing';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
|
||||
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
|
||||
declare const __karma__: any;
|
||||
declare const require: any;
|
||||
|
||||
// Prevent Karma from running prematurely.
|
||||
__karma__.loaded = function () {};
|
||||
|
||||
// First, initialize the Angular testing environment.
|
||||
getTestBed().initTestEnvironment(
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting()
|
||||
);
|
||||
// Then we find all the tests.
|
||||
const context = require.context('./', true, /\.spec\.ts$/);
|
||||
// And load the modules.
|
||||
context.keys().map(context);
|
||||
// Finally, start Karma to run the tests.
|
||||
__karma__.start();
|
||||
13
dashboard/src/tsconfig.app.json
Normal file
13
dashboard/src/tsconfig.app.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../out-tsc/app",
|
||||
"baseUrl": "./",
|
||||
"module": "es2015",
|
||||
"types": []
|
||||
},
|
||||
"exclude": [
|
||||
"test.ts",
|
||||
"**/*.spec.ts"
|
||||
]
|
||||
}
|
||||
20
dashboard/src/tsconfig.spec.json
Normal file
20
dashboard/src/tsconfig.spec.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../out-tsc/spec",
|
||||
"baseUrl": "./",
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"types": [
|
||||
"jasmine",
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"test.ts"
|
||||
],
|
||||
"include": [
|
||||
"**/*.spec.ts",
|
||||
"**/*.d.ts"
|
||||
]
|
||||
}
|
||||
5
dashboard/src/typings.d.ts
vendored
Normal file
5
dashboard/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/* SystemJS module definition */
|
||||
declare var module: NodeModule;
|
||||
interface NodeModule {
|
||||
id: string;
|
||||
}
|
||||
19
dashboard/tsconfig.json
Normal file
19
dashboard/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist/out-tsc",
|
||||
"sourceMap": true,
|
||||
"declaration": false,
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"target": "es5",
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
],
|
||||
"lib": [
|
||||
"es2017",
|
||||
"dom"
|
||||
]
|
||||
}
|
||||
}
|
||||
141
dashboard/tslint.json
Normal file
141
dashboard/tslint.json
Normal file
@@ -0,0 +1,141 @@
|
||||
{
|
||||
"rulesDirectory": [
|
||||
"node_modules/codelyzer"
|
||||
],
|
||||
"rules": {
|
||||
"arrow-return-shorthand": true,
|
||||
"callable-types": true,
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"curly": true,
|
||||
"eofline": true,
|
||||
"forin": true,
|
||||
"import-blacklist": [
|
||||
true,
|
||||
"rxjs"
|
||||
],
|
||||
"import-spacing": true,
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"interface-over-type-literal": true,
|
||||
"label-position": true,
|
||||
"max-line-length": [
|
||||
true,
|
||||
140
|
||||
],
|
||||
"member-access": false,
|
||||
"member-ordering": [
|
||||
true,
|
||||
{
|
||||
"order": [
|
||||
"static-field",
|
||||
"instance-field",
|
||||
"static-method",
|
||||
"instance-method"
|
||||
]
|
||||
}
|
||||
],
|
||||
"no-arg": true,
|
||||
"no-bitwise": true,
|
||||
"no-console": [
|
||||
true,
|
||||
"debug",
|
||||
"time",
|
||||
"timeEnd",
|
||||
"trace"
|
||||
],
|
||||
"no-construct": true,
|
||||
"no-debugger": true,
|
||||
"no-duplicate-super": true,
|
||||
"no-empty": false,
|
||||
"no-empty-interface": true,
|
||||
"no-eval": true,
|
||||
"no-inferrable-types": [
|
||||
true,
|
||||
"ignore-params"
|
||||
],
|
||||
"no-misused-new": true,
|
||||
"no-non-null-assertion": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-string-literal": false,
|
||||
"no-string-throw": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unnecessary-initializer": true,
|
||||
"no-unused-expression": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-var-keyword": true,
|
||||
"object-literal-sort-keys": false,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-catch",
|
||||
"check-else",
|
||||
"check-whitespace"
|
||||
],
|
||||
"prefer-const": true,
|
||||
"quotemark": [
|
||||
true,
|
||||
"single"
|
||||
],
|
||||
"radix": true,
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"typeof-compare": true,
|
||||
"unified-signatures": true,
|
||||
"variable-name": false,
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
],
|
||||
"directive-selector": [
|
||||
true,
|
||||
"attribute",
|
||||
"app",
|
||||
"camelCase"
|
||||
],
|
||||
"component-selector": [
|
||||
true,
|
||||
"element",
|
||||
"app",
|
||||
"kebab-case"
|
||||
],
|
||||
"use-input-property-decorator": true,
|
||||
"use-output-property-decorator": true,
|
||||
"use-host-property-decorator": true,
|
||||
"no-input-rename": true,
|
||||
"no-output-rename": true,
|
||||
"use-life-cycle-interface": true,
|
||||
"use-pipe-transform-interface": true,
|
||||
"component-class-suffix": true,
|
||||
"directive-class-suffix": true,
|
||||
"no-access-missing-member": true,
|
||||
"templates-use-public": true,
|
||||
"invoke-injectable": true
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,8 @@ class ITunesParser:
|
||||
"""
|
||||
Parse an iTunes Library and produce JSON - for ELS
|
||||
"""
|
||||
ELS_INDEX_NAME = "itunessongs"
|
||||
|
||||
def __init__(self):
|
||||
self._tracks = {}
|
||||
self._albums = {}
|
||||
@@ -184,7 +186,8 @@ class ITunesParser:
|
||||
'Play Count': 0,
|
||||
'Rating': 0,
|
||||
'Genre': set(),
|
||||
'Artist': set()
|
||||
'Artist': set(),
|
||||
'Total Time': 0
|
||||
}
|
||||
|
||||
# Compute information
|
||||
@@ -193,9 +196,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
|
||||
@@ -227,21 +233,6 @@ class ITunesParser:
|
||||
|
||||
|
||||
class WriteElsJson:
|
||||
def to_json(self):
|
||||
"""
|
||||
Just do processSong()
|
||||
or do process_songs, then _write_artists and _write_albums.
|
||||
Note: process_songs do a process_artists and process_albums...
|
||||
This method suck.
|
||||
"""
|
||||
ret = self._process_songs()
|
||||
|
||||
self._write_artists()
|
||||
self._write_albums()
|
||||
|
||||
# return json.dumps(jsonObj, indent=indent, cls=SetEncoder)
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
def write_artists(artists, output_file):
|
||||
"""
|
||||
@@ -254,7 +245,7 @@ class WriteElsJson:
|
||||
artist['Rating'] = round(artist['Rating'])
|
||||
|
||||
json_track_index = {
|
||||
"index": {"_index": "itunessongs", "_type": "artist", "_id": persistent_id}
|
||||
"index": {"_index": ITunesParser.ELS_INDEX_NAME, "_type": "artist", "_id": persistent_id}
|
||||
}
|
||||
|
||||
file_artist.write(bytes(json.dumps(json_track_index, indent=None, cls=SetEncoder), 'UTF-8'))
|
||||
@@ -275,7 +266,7 @@ class WriteElsJson:
|
||||
album['Rating'] = round(album['Rating'])
|
||||
|
||||
json_track_index = {
|
||||
"index": {"_index": "itunessongs", "_type": "album", "_id": persistent_id}
|
||||
"index": {"_index": ITunesParser.ELS_INDEX_NAME, "_type": "album", "_id": persistent_id}
|
||||
}
|
||||
|
||||
file_albums.write(bytes(json.dumps(json_track_index, indent=None, cls=SetEncoder), 'UTF-8'))
|
||||
@@ -292,7 +283,7 @@ class WriteElsJson:
|
||||
file = io.open(output_file, 'wb')
|
||||
for persistent_id, song in songs.items():
|
||||
json_track_index = {
|
||||
"index": {"_index": "itunessongs", "_type": "song", "_id": persistent_id}
|
||||
"index": {"_index": ITunesParser.ELS_INDEX_NAME, "_type": "song", "_id": persistent_id}
|
||||
}
|
||||
|
||||
file.write(bytes(json.dumps(json_track_index, indent=None, cls=SetEncoder), 'UTF-8'))
|
||||
@@ -310,7 +301,9 @@ DEFAULT_LIBRARY_FILE = os.path.expanduser(DEFAULT_LIBRARY_FILE_NAME)
|
||||
DEFAULT_OUTPUT_FILE = os.path.dirname(os.path.realpath(__file__)) + DEFAULT_OUTPUT_FILE_NAME
|
||||
|
||||
# Get options
|
||||
parser = argparse.ArgumentParser()
|
||||
parser = argparse.ArgumentParser(description="""
|
||||
Parse an iTunes XML library file to produce JSON file for ELS bulk operation.
|
||||
""")
|
||||
parser.add_argument('-f', '--file', default=DEFAULT_LIBRARY_FILE,
|
||||
help='iTunes Library XML file path (default: ./' + DEFAULT_LIBRARY_FILE_NAME + ')')
|
||||
parser.add_argument('-o', '--output', default=DEFAULT_OUTPUT_FILE,
|
||||
|
||||
33
send_data.py
33
send_data.py
@@ -33,15 +33,34 @@ def delete_index(index_name, quiet=False):
|
||||
Delete an index in ELS
|
||||
"""
|
||||
if not quiet:
|
||||
print('Deleting index {}...'.format(index_name))
|
||||
print('Deleting index \'{}\'...'.format(index_name))
|
||||
res = requests.delete(url=ELASTICSEARCH_URL + INDEX_NAME)
|
||||
if res.status_code == 200:
|
||||
if not quiet:
|
||||
print("Deleted!")
|
||||
else:
|
||||
print("An error occured")
|
||||
# TODO Catch "index_not_found_exception"
|
||||
if res.json()['error']['type'] == 'index_not_found_exception':
|
||||
print("Index '{}' doesn't exist and can't be deleted".format(index_name))
|
||||
else:
|
||||
print(res.text)
|
||||
|
||||
def put_mapping(index_name, mapping_file, quiet=False):
|
||||
"""
|
||||
Send a mapping file for an index to ELS.
|
||||
"""
|
||||
if not quiet:
|
||||
print("Put '{}' mapping file...".format(mapping_file.name))
|
||||
res = requests.put(url=ELASTICSEARCH_URL + index_name,
|
||||
data=mapping_file,
|
||||
headers={'Content-Type': 'application/x-ndjson'})
|
||||
if res.status_code != 200:
|
||||
print("An error occured")
|
||||
print(res.text)
|
||||
else:
|
||||
if not quiet:
|
||||
print("File '{} sended to Elasticsearch!".format(mapping_file.name))
|
||||
|
||||
|
||||
#### main block ####
|
||||
|
||||
@@ -53,6 +72,7 @@ INDEX_NAME = "itunessongs"
|
||||
DEFAULT_SONG_FILE = 'es-music-data.json'
|
||||
DEFAULT_ALBUM_FILE = 'es-albums-data.json'
|
||||
DEFAULT_ARTIST_FILE = 'es-artist-data.json'
|
||||
DEFAULT_MAPPING_FILE = 'mapping.json'
|
||||
|
||||
# Get options
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -75,13 +95,15 @@ song_group.add_argument('-sf', '--song-file', type=argparse.FileType('r'),
|
||||
sending_group.add_argument('-al', '--album-file', nargs='?', type=argparse.FileType('r'), const=DEFAULT_ALBUM_FILE,
|
||||
help='Enable send album data. Optionally, precise the album file (default: \'{}\')'.format(DEFAULT_ALBUM_FILE))
|
||||
sending_group.add_argument('-ar', '--artist-file', nargs='?', type=argparse.FileType('r'), const=DEFAULT_ARTIST_FILE,
|
||||
help='Enable send artist data. Optionally, precise the artist file (default: \'{}\''.format(DEFAULT_ARTIST_FILE))
|
||||
help='Enable send artist data. Optionally, precise the artist file (default: \'{}\')'.format(DEFAULT_ARTIST_FILE))
|
||||
sending_group.add_argument('-m', '--mapping-file', type=argparse.FileType('r'), default=DEFAULT_MAPPING_FILE,
|
||||
help='If deleting index, mapping file to send (default: \'{}\')'.format(DEFAULT_MAPPING_FILE))
|
||||
# Mode
|
||||
mode_group = parser.add_argument_group('Mode')
|
||||
mode_group.add_argument('-A', '--ALL', action='store_true',
|
||||
help='Send all possible data: song, artist and album')
|
||||
mode_group.add_argument('-D', '--DELETE', action='store_true',
|
||||
help='Delete old index (precise name with -idx argument)')
|
||||
help='Delete old index (precise name with -idx argument). This will send a mapping to ELS.')
|
||||
# Settings
|
||||
g_settings_group = parser.add_argument_group('Global Settings')
|
||||
g_settings_group.add_argument('-els', '--elasticsearch-url', default=ELASTICSEARCH_URL, nargs='?',
|
||||
@@ -107,13 +129,14 @@ if __name__ == '__main__':
|
||||
|
||||
if args.DELETE:
|
||||
delete_index(INDEX_NAME, args.quiet)
|
||||
put_mapping(INDEX_NAME, args.mapping_file, args.quiet)
|
||||
|
||||
if args.song or args.ALL:
|
||||
# Retrieve default song file if not precised
|
||||
if not args.song_file:
|
||||
try:
|
||||
song_file = open(DEFAULT_SONG_FILE, 'r')
|
||||
except FileNotFoundError:
|
||||
except FileNotFoundError: # Theoretically, can occur only when default file not found
|
||||
print("Error: can't open default music file: [Errno 2] No such file or directory: '{}'.".format(DEFAULT_SONG_FILE))
|
||||
print("Use -sf argument, or -h for more help")
|
||||
sys.exit(2)
|
||||
|
||||
Reference in New Issue
Block a user