Skip to content

Commit

Permalink
Merge pull request mozilla#47 from mzhilyaev/issue_35
Browse files Browse the repository at this point in the history
Closes mozilla#35: Compute user interests on demand
  • Loading branch information
Mardak committed Jun 15, 2012
2 parents a0e31f5 + df56ecc commit 7255550
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
10 changes: 5 additions & 5 deletions addon/examples/newtab_test.html
Expand Up @@ -44,12 +44,14 @@
}
}

// now go back to marketPlaceCats and nromalize by sqrt of ODP and mrktplace vectors for each market place category
// now go back to marketPlaceCats and normalize by totalScore
for( var cat in marketPlaceCats ) {
marketPlaceCats[ cat ] *= 100.0 / totalScore ;
}
// dor debugging
outputData( "odp_interests" , odpInterests );

// display the mappings on the page
outputData("interests", marketPlaceCats);
outputData("odp_interests", odpInterests);
});
} // end of mapOdp2MarketPlace

Expand All @@ -61,8 +63,6 @@
odp2MarketPlaceMapping = JSON.parse( request.responseText );
mapOdp2MarketPlace( );

// display the mappings on the page
outputData( "interests" , marketPlaceCats );

// also dump the JSON object to odp2market
var txt = "";
Expand Down
34 changes: 22 additions & 12 deletions addon/lib/Demographer.js
Expand Up @@ -4,6 +4,7 @@

"use strict";
const {data} = require("self");
const timers = require("timers");
const historyUtils = require("HistoryUtils");

function Demographer(sitesCatFile) {
Expand All @@ -12,22 +13,21 @@ function Demographer(sitesCatFile) {
this.totalVisits = 0;
this.catDepth = 2;

this.allSites = {};
this.mySites = {};
this.cats = {};
this.readCats();
this.readHistory();
this.allSites = null;
this.cats = null;
}

Demographer.prototype = {
clearCats: function() {
rebuild: function(cb) {
this.totalVisits = 0;
this.cats = {};
},

rebuild: function(cb) {
this.clearCats();
this.mySites = {};
// check if we loaded sites<->ODP mapping
if (this.allSites == null) {
this.allSites = {};
this.readSiteToCategoryMapping( );
}
this.readHistory(cb);
},

Expand Down Expand Up @@ -147,7 +147,7 @@ Demographer.prototype = {
this.cats[top] += count;
},

readCats: function() {
readSiteToCategoryMapping: function() {
// read the file first
let sites = data.load(this.catFile);
// split by new lines
Expand Down Expand Up @@ -179,8 +179,18 @@ Demographer.prototype = {
}.bind(this));
},

getInterests: function() {
return this.cats;
submitInterests: function(callback) {
let callbackLoader = function() {
callback(this.cats);
}.bind(this);

if (this.cats == null) {
this.rebuild(callbackLoader);
}
else {
// be explicitly asynchronous - call callback via timeout
timers.setTimeout(callbackLoader);
}
},

normalize: function() {
Expand Down
2 changes: 1 addition & 1 deletion addon/lib/appViewer.js
Expand Up @@ -49,7 +49,7 @@ function AppViewer(configObject) {
Services.obs.removeObserver(apiInjector, 'document-element-inserted', false);

iframe.contentWindow.wrappedJSObject.getCategories = function(callback) {
callback(this._demographer.getInterests());
this._demographer.submitInterests(callback);
}.bind(this);

iframe.contentWindow.wrappedJSObject.getDemographics = function(callback) {
Expand Down

0 comments on commit 7255550

Please sign in to comment.