Skip to content

Commit

Permalink
Completed preditive cache
Browse files Browse the repository at this point in the history
predictiveCache completed and integrated into the app. Monitors for media requested on the listen page. Should work, not tested in full due to preflight server auth bug
  • Loading branch information
atruskie committed Dec 23, 2014
1 parent d52bea6 commit f7478d2
Show file tree
Hide file tree
Showing 6 changed files with 716 additions and 155 deletions.
7 changes: 5 additions & 2 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ var app = angular.module('baw',
}])


.run(['$rootScope', '$location', '$route', '$http', 'Authenticator', 'AudioEvent', 'conf.paths', 'UserProfile', 'ngAudioEvents', '$url',
function ($rootScope, $location, $route, $http, Authenticator, AudioEvent, paths, UserProfile, ngAudioEvents, $url) {
.run(['$rootScope', '$location', '$route', '$http', 'Authenticator', 'AudioEvent', 'conf.paths', 'UserProfile', 'ngAudioEvents', '$url', "predictiveCache", "conf.constants",
function ($rootScope, $location, $route, $http, Authenticator, AudioEvent, paths, UserProfile, ngAudioEvents, $url, predictiveCache, constants) {

// embed configuration for easy site-wide binding
$rootScope.paths = paths;
Expand Down Expand Up @@ -343,6 +343,9 @@ var app = angular.module('baw',

$rootScope.downloadAnnotationLink = AudioEvent.csvLink();

// set up predictive cache service
predictiveCache(constants.predictiveCache.profiles["Media cache ahead"]($location, paths));

}])

.controller('AppCtrl',
Expand Down
2 changes: 1 addition & 1 deletion src/app/listen/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
return undefined;
}

return moment($scope.model.media.recordedDate).add($scope.jumpToMinute, 'm').format("YYYY-MMM-DD, HH:mm:ss");
return moment($scope.model.media.recordedDatep).add($scope.jumpToMinute, 'm').format("YYYY-MMM-DD, HH:mm:ss");
};


Expand Down
80 changes: 55 additions & 25 deletions src/baw.configuration.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ angular.module('bawApp.configuration', ['url'])
libraryItem: "/library/{recordingId}/audio_events/{audioEventId}"
},
// general links for use in <a />'s
links: {

}
links: {}
}
};

Expand Down Expand Up @@ -229,7 +227,7 @@ angular.module('bawApp.configuration', ['url'])
chrome: 30,
safari: 5.1,
opera: 23,
ios: 5.1,
ios: 5.1,
android: 4.0
},
baseMessage: "Your current internet browser ({name}, version {version}) is {reason}. <br/> Consider updating or try using <a target='_blank' href='https://www.google.com.au/intl/en_au/chrome/browser/' >Google Chrome</a>.",
Expand All @@ -246,29 +244,61 @@ angular.module('bawApp.configuration', ['url'])
},
predictiveCache: {

profiles: [
{
name: "Media cache ahead",
match: "some url",
request: ["one url", "another url"],
progression: [
function(data, previous) {
return previous + 30.0;
},
function(data, previous) {
var next = previous + 30.0;
if (next >= data.max) {
return;
}
else {
return next;
}
profiles: {
"Media cache ahead": function bind($location, paths) {
// request additional bits of media based the duration of the original request
// do not make requests that would exceed the end of the recording
function mediaProgressor(previous, data) {
var media = data.responseData.data,
duration = media.commonParameters.endOffset - media.commonParameters.startOffset,
next = previous + duration,
max = media.recording.durationSeconds;

if (next >= max) {
return;
}
else {
return next;
}
],
count: 10,
method: "HEAD"
}

function formatMediaUrl(url, counters) {
return paths.api.root + url
.replace(/start_offset=[\.\d]+/, "start_offset=" + counters[0])
.replace(/end_offset=[\.\d]+/, "end_offset=" + counters[1]);
}
return {
name: "Media cache ahead",
match: function (url, response) {
// match only if on listen page and request is for a media's json
if ($location.path().indexOf("/listen") === 0 &&
/\/audio_recordings\/[\.\d]+\/media\.json.*/.test(url)) {
var so = response.config.params.start_offset;
var eo = response.config.params.end_offset;

return so !== undefined && eo !== undefined ? [so, eo] : null;
}

return null;
},
request: [
// spectrogram
function (counters, data) {
return formatMediaUrl(data.responseData.data.available.image["png"].url, counters);
},
// mp3
function (counters, data) {
return formatMediaUrl(data.responseData.data.available.audio["mp3"].url, counters);
}
],
progression: [
mediaProgressor, mediaProgressor
],
count: 10,
method: "HEAD",
progressive: true
};
}
]
}
}
});
3 changes: 2 additions & 1 deletion src/components/services/angularjsRailsResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// MIT License
// https://github.com/tpodom/angularjs-rails-resource

angular.module('rails', [])
angular
.module('rails', [])
.constant('casingTransformers', (function () {
/**
* Old function worked via reference - deprecated
Expand Down
Loading

0 comments on commit f7478d2

Please sign in to comment.