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();
$('#searchKeyword,#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch);
$('#searchKeyword,#minScore,#hintSteps,#walkingDist,#maxResults').change(function() { onSearch(getFeaturesGrapher); });
$('#historyIndex').on('slideStop', onSelectSnapshot);
$('#learn').click(onLearn);
$('#forget').click(onForget);
@ -125,11 +125,18 @@
});
}
function onSearch() {
function getFeaturesKeyword() {
var keyword = $('#searchKeyword').val();
return _.clone(_ctx.parameters.keywords[keyword]);
}
function getFeaturesGrapher() {
return _.clone(_ctx.query.features);
}
function onSearch(provider) {
_ctx.query = {
features: _.clone(_ctx.parameters.keywords[keyword]),
features: (provider || getFeaturesKeyword)(),
range: { min: -1.0, max: 1.0 },
walkingDist: parseFloat($('#walkingDist').val()),
minScore: parseFloat($('#minScore').val()),
@ -251,7 +258,7 @@
navigator.geolocation.getCurrentPosition(
function(geo) { onReady(geo); },
function(err) { onReady(null); },
{enableHighAccuracy: true}
{ enableHighAccuracy: true }
);
}
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) {
if (err) {
throw err;
@ -220,19 +220,19 @@ function getRecords(geo, walkingDist, callback) {
};
});
computeRecordGeo(records, geo, walkingDist * 1000.0);
computeRecordGeo(records, context);
callback(records);
});
}
function computeRecordGeo(records, geo, accessDist) {
function computeRecordGeo(records, context) {
var distUserMin = Number.MAX_VALUE;
var distUserMax = Number.MIN_VALUE;
_.each(records, function(record) {
record.distanceToUser = 0.0;
if (geo) {
record.distanceToUser = geolib.getDistance(record.geo, geo);
if (context.geo) {
record.distanceToUser = geolib.getDistance(record.geo, context.geo);
}
distUserMin = Math.min(distUserMin, record.distanceToUser);
@ -244,15 +244,15 @@ function computeRecordGeo(records, geo, accessDist) {
_.each(records, function(record) {
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.max(record.features.accessible, -1.0);
});
}
function getData(geo, walkingDist, callback) {
function getData(context, callback) {
getKeywords(function(keywords) {
getRecords(geo, walkingDist, function(records) {
getRecords(context, function(records) {
callback({
keywords: keywords,
records: records
@ -268,7 +268,12 @@ function getParameters(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(
data,
query.features,