Created
August 14, 2008 21:04
-
-
Save jessehattabaugh/5494 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function cron_analyze_entries(){ | |
const limit = 500 | |
var terms = [] | |
var interests = [] | |
var count = 0 | |
storage.entries.filter({analyzed:false}).sort().forEach(function(e){ | |
text = (e.title+' '+e.content).replace(/<[a-zA-Z\/][^>]*>/g, ' ').toLowerCase().clean() | |
words = text.match(/\b\w{3,}\b/g) | |
if((count += words.length) > limit) return false | |
if(words){ | |
words.forEach(function(t){ | |
e.user.count++ | |
if(t == 'map') t = 'maps' // 'map' is a reserved word | |
if(terms[t]) term = terms[t] | |
else term = storage.terms.filter({string:t}).first() | |
if(!term) { | |
term = storage.terms.add({ | |
string:t, | |
count:1, | |
interests:0 | |
}) | |
storage.site.terms++ | |
} else term.count++ | |
storage.site.count++ | |
terms[t] = term // cache for later | |
if(!interests[e.user.id]) | |
interest = storage.interests.filter({ | |
user:e.user, | |
term:term | |
}).first() | |
else if(interests[e.user.id][t]) | |
interest = interests[e.user.id][t] | |
if(!interest) { | |
interest = storage.interests.add({ | |
user:e.user, | |
term:term, | |
count:1 | |
}) | |
e.user.interests++ | |
term.interests++ | |
} else interest.count++ | |
if(!interests[e.user.id]) interests[e.user.id] = [] | |
interests[e.user.id][t] = interest // cache for later | |
term.volume = (100 / storage.site.count) * term.count | |
interest.volume = (100 / e.user.count) * interest.count | |
interest.difference = interest.volume - term.volume | |
term.average = term.count / term.interests | |
}) | |
} | |
e.analyzed = true | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment