Created
May 31, 2012 21:23
-
-
Save aedoran/2846406 to your computer and use it in GitHub Desktop.
linear hotness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
article = { | |
meta : { | |
white_click_count : 38, | |
unknown_click_count : 399, | |
white_saved_count : 299 | |
} | |
}; | |
//weights from 0 to 1 of how important the attribute is | |
//sum of weights should add to 1 | |
attribute_importance = { | |
meta : { | |
white_click_count : .5, | |
unknown_click_count : .25, | |
white_saved_count : .25 | |
} | |
} | |
//max values for each value | |
max_attribute_values = { | |
meta : { | |
white_click_count : 100, | |
unknown_click_count : 1000, | |
white_saved_count : 500 | |
} | |
} | |
//recursively go through article to multiply the importance * article property / max property value | |
//if max values are really the max, and importances all add up to one then function returns a hotness of 0 to 1 | |
var getScore = function(article,attribute_importance,max_attribute_values) { | |
var score = 0; | |
for (var a in article) { | |
if (typeof(article[a]) == "object") { | |
score = score+ getScore(article[a],attribute_importance[a],max_attribute_values[a]); | |
} else { | |
score = score + article[a] * attribute_importance[a] / max_attribute_values[a]; | |
} | |
} | |
return score; | |
} | |
console.log(getScore(article,attribute_importance,max_attribute_values)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment