diff --git a/client/index.html b/client/index.html index 30818d8..492e2a7 100644 --- a/client/index.html +++ b/client/index.html @@ -25,7 +25,8 @@ diff --git a/client/scripts/search.js b/client/scripts/search.js index 9e3cad7..a204ffb 100644 --- a/client/scripts/search.js +++ b/client/scripts/search.js @@ -42,6 +42,12 @@ $('#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch); $('#profileDlg').on('hidden.bs.modal', onSearch); + $('#resetStorage').click(function() { + if (confirm('Are you sure you want to reset your profile?')) { + localStorage.clear(); + $('iframe').attr('src', $('iframe').attr('src')); + } + }); window.accessReview = function(id) { $.getJSON('/access', {id: id, profile: getProfile()}, function(results) { diff --git a/server/search.js b/server/search.js index 5d59195..242db23 100644 --- a/server/search.js +++ b/server/search.js @@ -191,48 +191,52 @@ function computeRecordGeo(records, context) { } function computeRecordCompat(records, context, callback) { - console.log(context.profile); - async.map( + async.each( records, function(record, callback) { - pool.query('SELECT * FROM history WHERE reviewId = (?)', [record.id], function(err, rows) { - if (err) { - throw err; - } + pool.query( + 'SELECT * FROM history WHERE reviewId = (?)', + [record.id], + function(err, rows) { + async.map( + rows, + function(row, callback) { + pool.query( + 'SELECT * FROM historyGroups WHERE historyId = (?)', + [row.id], + function(err, historyGroupRows) { + var reviewFeatures = {}; + _.each(historyGroupRows, function(historyGroupRow) { + reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue; + }); - async.map( - rows, - function(row, callback) { - pool.query( - 'SELECT * FROM historyGroups WHERE historyId = (?)', - [row.id], - function(err, historyGroupRows) { - if (err) { - throw err; + console.log(context.profile); + console.log(reviewFeatures); + console.log('***\n'); + var groupScore = innerProduct(context.profile, reviewFeatures); + callback(err, groupScore); } - - var reviewFeatures = {}; - _.each(historyGroupRows, function(historyGroupRow) { - reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue; - }); - - var groupScore = innerProduct(context.profile, reviewFeatures); - callback(err, groupScore); - } - ); - }, - function(err, results) { - if (err) { - throw err; + ); + }, + function(err, groupScores) { + record.groupScores = groupScores; + callback(err); } - - callback(results); - } - ); - }); + ); + } + ); }, - function(err, results) { - // console.log(results); + function(err) { + if (err) { + throw err; + } + + _.each(records, function(record) { + if (record.groupScores.length > 0) { + console.log(record); + } + }); + callback(records); } ); @@ -245,8 +249,8 @@ function sanitizeQuery(query) { 'affordable', 'atmospheric', 'nearby', - 'accessible' - // 'compatible' + 'accessible', + 'compatible' ]; var features = {}; @@ -256,11 +260,10 @@ function sanitizeQuery(query) { query.features = features; - // for (var category in query.profile) { - // if (parseFloat(query.profile[category]) === 0) { - // delete query.profile[category]; - // } - // } + query.profile = _.reject( + query.profile, + function(num) { return num === 0; } + ); } function getCategories(callback) {