aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/index.html1
-rw-r--r--app/js/services.js39
-rw-r--r--tests/pathAlgoPerf.html135
3 files changed, 171 insertions, 4 deletions
diff --git a/app/index.html b/app/index.html
index 0404bb0..77bcb2d 100644
--- a/app/index.html
+++ b/app/index.html
@@ -16,7 +16,6 @@
<script src="js/services.js" ></script>
<script src="js/directives.js" ></script>
<script src="js/controllers.js" ></script>
- <script src="js/yt_musicsearch.js" ></script>
</head>
<body id="body_spe" ng-app="playGraph" ng-controller="pointCtrl">
diff --git a/app/js/services.js b/app/js/services.js
index d18e923..8dbd1b2 100644
--- a/app/js/services.js
+++ b/app/js/services.js
@@ -9,7 +9,7 @@ app.service('pathService', function() {
var dy = point1.y - point2.y;
return Math.sqrt(dx * dx + dy * dy);
},
- computePlaylist: function(songList, line, duration) {
+ computePlaylistOld: function(songList, line, duration) {
//compute distances from the constrain path
console.log('length', line.length);
@@ -29,7 +29,39 @@ app.service('pathService', function() {
});
});
return selection;
- }
+ },
+ computePlaylist:function(songList, line, duration) {
+ //compute distances from the constrain path
+
+ var threshold = 60;
+ for(var i=songList.length-1; i>0; i--){
+ songList[i].selected = false;
+ };
+ var songCopy = songList.slice(0);
+ songCopy.sort(function(a,b){return a.x-b.x;});
+
+ var selection = [];
+ for(var i=line.length-1; i>0; i--) {
+ var point = line[i];
+ var min = line[i].x-threshold;
+ var max = line[i].x+threshold;
+ var j=songCopy.length-1;
+ while(songCopy[j].x > max && j > 0){
+ j--;
+ }
+ while(songCopy[j].x > min && j > 0){
+ var song = songCopy[j];
+ var d = self.dist(song, point);
+ if (d < threshold) {
+ songCopy.splice(j,1);
+ selection.push(song);
+ song.selected = true;
+ }
+ j--;
+ };
+ };
+ return selection;
+ }
};
return self;
});
@@ -39,12 +71,13 @@ app.service('musicPlayer', function() {
startSongWithDuration: function(id, duration)
{
$('#ytplayer').attr('src', 'https://www.youtube.com/embed/' + id + '?autoplay=1&modestbranding=1');
- self.musicTimer = setInterval(changeSong, duration * 1000);
+ self.musicTimer = setInterval(self.changeSong, duration * 1000);
},
changeSong: function()
{
clearInterval(self.musicTimer);
}
};
+
return self;
});
diff --git a/tests/pathAlgoPerf.html b/tests/pathAlgoPerf.html
new file mode 100644
index 0000000..5c91d90
--- /dev/null
+++ b/tests/pathAlgoPerf.html
@@ -0,0 +1,135 @@
+<!DOCTYPE html>
+<!--
+To change this license header, choose License Headers in Project Properties.
+To change this template file, choose Tools | Templates
+and open the template in the editor.
+-->
+<html>
+ <head>
+ <title>TODO supply a title</title>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <script src="../app/lib/angular.js"></script>
+ </head>
+ <body>
+ <div>TODO write content</div>
+ <script type="text/javascript">
+ var dist = function(point1, point2) {
+ var dx = point1.x - point2.x;
+ var dy = point1.y - point2.y;
+ return Math.sqrt(dx * dx + dy * dy);
+ };
+ var computePlaylist = function(songList, line, duration) {
+ //compute distances from the constrain path
+
+ var threshold = 60;
+ angular.forEach(songList, function(song) {
+ song.selected = false;
+ });
+
+ var selection = [];
+ angular.forEach(line, function(point) {
+ angular.forEach(songList, function(song) {
+ var d = dist(song, point);
+ if (d < threshold && song.selected !== true) {
+ selection.push(song);
+ song.selected = true;
+ }
+ });
+ });
+ console.log(selection.length);
+ return selection;
+ };
+
+ var computePlaylist2 = function(songList, line, duration) {
+ //compute distances from the constrain path
+
+ var threshold = 60;
+ for(var i=songList.length-1; i>0; i--){
+ songList.selected = false;
+ };
+ var songCopy = songList.slice(0);
+ songCopy.sort(function(a,b){return a.x-b.x;});
+
+ var selection = [];
+ for(var i=line.length-1; i>0; i--) {
+ var point = line[i];
+ var min = line[i].x-threshold;
+ var max = line[i].x+threshold;
+ var j=songCopy.length-1;
+ while(songCopy[j].x > max && j > 0){
+ j--;
+ }
+ while(songCopy[j].x > min && j > 0){
+ var song = songCopy[j];
+ var d = dist(song, point);
+ if (d < threshold) {
+ songCopy.splice(j,1);
+ selection.push(song);
+ song.selected = true;
+ }
+ j--;
+ };
+ };
+ console.log(selection.length);
+ return selection;
+ };
+ var computePlaylist3 = function(songList, line, duration) {
+ //compute distances from the constrain path
+
+ var threshold = 60;
+ for(var i=songList.length-1; i>0; i--){
+ songList.selected = false;
+ };
+ var songCopy = songList.slice(0);
+
+ var selection = [];
+ for(var i=line.length-1; i>0; i--) {
+ var point = line[i];
+ for(var j=songCopy.length-1; j>0; j--){
+ var song = songCopy[j];
+ var d = dist(song, point);
+ if (d < threshold) {
+ songCopy.splice(j,1);
+ selection.push(song);
+ song.selected = true;
+ }
+ };
+ };
+ console.log(selection.length);
+ return selection;
+ };
+
+
+ var generateRandCoords = function(amount) {
+ var temp = [];
+ var randomPoint = function() {
+ return {
+ x: Math.round(Math.random() * 1000),
+ y: Math.round(Math.random() * 1000)
+ };
+ };
+ for (var i = 0; i < amount; i++) {
+ temp.push(randomPoint());
+ }
+ ;
+ return temp;
+ };
+
+ var line = generateRandCoords(100);
+ var songs = generateRandCoords(100);
+
+ var timestamp = new Date().getTime();
+ computePlaylist(songs, line, 60);
+ console.log('execution time', new Date().getTime() - timestamp);
+
+ var timestamp = new Date().getTime();
+ computePlaylist2(songs, line, 60);
+ console.log('execution time2', new Date().getTime() - timestamp);
+
+ var timestamp = new Date().getTime();
+ computePlaylist3(songs, line, 60);
+ console.log('execution time3', new Date().getTime() - timestamp);
+ </script>
+ </body>
+</html>