1

Ranking now being computed properly

This commit is contained in:
Alex Yatskov 2015-03-17 16:28:16 +09:00
parent 076baa1204
commit cfd5ca4670

View File

@ -210,9 +210,6 @@ function computeRecordCompat(records, context, callback) {
reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue; reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue;
}); });
console.log(context.profile);
console.log(reviewFeatures);
console.log('***\n');
var groupScore = innerProduct(context.profile, reviewFeatures); var groupScore = innerProduct(context.profile, reviewFeatures);
callback(err, groupScore); callback(err, groupScore);
} }
@ -231,18 +228,23 @@ function computeRecordCompat(records, context, callback) {
throw err; throw err;
} }
_.each(records, function(record) {
if (record.groupScores.length > 0) {
console.log(record);
}
});
callback(records); callback(records);
} }
); );
} }
function sanitizeQuery(query) { function fixupProfile(profile) {
var fixed = {};
_.each(JSON.parse(profile), function(value, key) {
if (parseFloat(value) !== 0) {
fixed[key] = value;
}
});
return fixed;
}
function fixupFeatures(features) {
var keys = [ var keys = [
'delicious', 'delicious',
'accomodating', 'accomodating',
@ -253,19 +255,12 @@ function sanitizeQuery(query) {
'compatible' 'compatible'
]; ];
var features = {}; var fixed = {};
_.each(keys, function(key) { _.each(keys, function(key) {
features[key] = _.has(query.features, key) ? query.features[key] : 0; fixed[key] = _.has(features, key) ? features[key] : 0;
}); });
query.features = features;
var profile = {}; return fixed;
_.each(JSON.parse(query.profile), function(key, value) {
if (parseFloat(value) !== 0) {
profile[key] = value;
}
});
query.profile = profile;
} }
function getCategories(callback) { function getCategories(callback) {
@ -314,6 +309,8 @@ function removeCategory(query, callback) {
} }
function accessReview(query, callback) { function accessReview(query, callback) {
query.profile = fixupProfile(query.profile);
pool.query('SELECT url FROM reviews WHERE id = (?) LIMIT 1', [query.id], function(err, rows) { pool.query('SELECT url FROM reviews WHERE id = (?) LIMIT 1', [query.id], function(err, rows) {
if (err) { if (err) {
throw err; throw err;
@ -326,18 +323,20 @@ function accessReview(query, callback) {
if (results.success) { if (results.success) {
results.url = 'http://www.tripadvisor.com' + rows[0].url; results.url = 'http://www.tripadvisor.com' + rows[0].url;
pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) { if (_.keys(query.profile).length > 0) {
if (err) { pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) {
throw err; if (err) {
} throw err;
}
for (var categoryId in query.profile) { for (var categoryId in query.profile) {
pool.query( pool.query(
'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)', 'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)',
[categoryId, query.profile[categoryId], info.insertId] [categoryId, query.profile[categoryId], info.insertId]
); );
} }
}); });
}
} }
callback(results); callback(results);
@ -345,7 +344,8 @@ function accessReview(query, callback) {
} }
function runQuery(query, callback) { function runQuery(query, callback) {
sanitizeQuery(query); query.profile = fixupProfile(query.profile);
query.features = fixupFeatures(query.features);
var context = { var context = {
geo: query.geo, geo: query.geo,