1

Fixing up function name

This commit is contained in:
Alex Yatskov 2015-01-05 18:08:24 +09:00
parent 62e768feb7
commit 33ae0ad637
2 changed files with 25 additions and 13 deletions

View File

@ -66,7 +66,7 @@
onSearch(); onSearch();
$('#searchKeyword,#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch); $('#searchKeyword,#minScore,#hintSteps,#walkingDist,#maxResults').change(function() { onSearch(getFeaturesGrapher); });
$('#historyIndex').on('slideStop', onSelectSnapshot); $('#historyIndex').on('slideStop', onSelectSnapshot);
$('#learn').click(onLearn); $('#learn').click(onLearn);
$('#forget').click(onForget); $('#forget').click(onForget);
@ -125,11 +125,18 @@
}); });
} }
function onSearch() { function getFeaturesKeyword() {
var keyword = $('#searchKeyword').val(); var keyword = $('#searchKeyword').val();
return _.clone(_ctx.parameters.keywords[keyword]);
}
function getFeaturesGrapher() {
return _.clone(_ctx.query.features);
}
function onSearch(provider) {
_ctx.query = { _ctx.query = {
features: _.clone(_ctx.parameters.keywords[keyword]), features: (provider || getFeaturesKeyword)(),
range: { min: -1.0, max: 1.0 }, range: { min: -1.0, max: 1.0 },
walkingDist: parseFloat($('#walkingDist').val()), walkingDist: parseFloat($('#walkingDist').val()),
minScore: parseFloat($('#minScore').val()), minScore: parseFloat($('#minScore').val()),
@ -251,7 +258,7 @@
navigator.geolocation.getCurrentPosition( navigator.geolocation.getCurrentPosition(
function(geo) { onReady(geo); }, function(geo) { onReady(geo); },
function(err) { onReady(null); }, function(err) { onReady(null); },
{enableHighAccuracy: true} { enableHighAccuracy: true }
); );
} }
else { else {

View File

@ -194,7 +194,7 @@ function getKeywords(callback) {
}); });
} }
function getRecords(geo, walkingDist, callback) { function getRecords(context, callback) {
pool.query('SELECT * FROM reviews', function(err, rows) { pool.query('SELECT * FROM reviews', function(err, rows) {
if (err) { if (err) {
throw err; throw err;
@ -220,19 +220,19 @@ function getRecords(geo, walkingDist, callback) {
}; };
}); });
computeRecordGeo(records, geo, walkingDist * 1000.0); computeRecordGeo(records, context);
callback(records); callback(records);
}); });
} }
function computeRecordGeo(records, geo, accessDist) { function computeRecordGeo(records, context) {
var distUserMin = Number.MAX_VALUE; var distUserMin = Number.MAX_VALUE;
var distUserMax = Number.MIN_VALUE; var distUserMax = Number.MIN_VALUE;
_.each(records, function(record) { _.each(records, function(record) {
record.distanceToUser = 0.0; record.distanceToUser = 0.0;
if (geo) { if (context.geo) {
record.distanceToUser = geolib.getDistance(record.geo, geo); record.distanceToUser = geolib.getDistance(record.geo, context.geo);
} }
distUserMin = Math.min(distUserMin, record.distanceToUser); distUserMin = Math.min(distUserMin, record.distanceToUser);
@ -244,15 +244,15 @@ function computeRecordGeo(records, geo, accessDist) {
_.each(records, function(record) { _.each(records, function(record) {
record.features.nearby = -((record.distanceToUser - distUserMin) / distUserRange - 0.5) * 2.0; record.features.nearby = -((record.distanceToUser - distUserMin) / distUserRange - 0.5) * 2.0;
record.features.accessible = 1.0 - (record.distanceToStn / accessDist); record.features.accessible = 1.0 - (record.distanceToStn / context.walkingDist);
record.features.accessible = Math.min(record.features.accessible, 1.0); record.features.accessible = Math.min(record.features.accessible, 1.0);
record.features.accessible = Math.max(record.features.accessible, -1.0); record.features.accessible = Math.max(record.features.accessible, -1.0);
}); });
} }
function getData(geo, walkingDist, callback) { function getData(context, callback) {
getKeywords(function(keywords) { getKeywords(function(keywords) {
getRecords(geo, walkingDist, function(records) { getRecords(context, function(records) {
callback({ callback({
keywords: keywords, keywords: keywords,
records: records records: records
@ -268,7 +268,12 @@ function getParameters(callback) {
} }
function execQuery(query, callback) { function execQuery(query, callback) {
getData(query.geo, query.walkingDist, function(data) { var context = {
geo: query.geo,
walkingDist: query.walkingDist * 1000.0
};
getData(context, function(data) {
var searchResults = findRecords( var searchResults = findRecords(
data, data,
query.features, query.features,