1

Fixing compatibility calculation code.

This commit is contained in:
Alex Yatskov 2015-03-21 16:25:30 +09:00
parent 1402d60100
commit d6bb53e870

View File

@ -193,7 +193,6 @@ function computeRecordGeo(records, context) {
} }
function computeRecordPopularity(records, context, callback) { function computeRecordPopularity(records, context, callback) {
var scoreMin = 0;
var scoreMax = 0; var scoreMax = 0;
async.each( async.each(
@ -216,7 +215,6 @@ function computeRecordPopularity(records, context, callback) {
}); });
var groupScore = innerProduct(context.profile, reviewFeatures); var groupScore = innerProduct(context.profile, reviewFeatures);
scoreMin = Math.min(scoreMin, groupScore);
scoreMax = Math.max(scoreMax, groupScore); scoreMax = Math.max(scoreMax, groupScore);
callback(err, groupScore); callback(err, groupScore);
@ -224,10 +222,19 @@ function computeRecordPopularity(records, context, callback) {
); );
}, },
function(err, groupScores) { function(err, groupScores) {
var scoreSum = _.reduce(groupScores, function(a, b) { return a + b; }); var scoreAvg = 0;
var scoreAvg = scoreSum / groupScores.length; if (groupScores.length > 0) {
var scoreSum = _.reduce(groupScores, function(a, b) { return a + b; });
scoreAvg = scoreSum / groupScores.length;
}
if (scoreMax !== 0) {
record.features.compatibility = scoreAvg / scoreMax;
}
else {
record.features.compatibility = 0;
}
record.features.compatibility = (scoreAvg - scoreMin) / (scoreMax - scoreMin);
callback(err); callback(err);
} }
); );