Sha256: ddb457e155cef1975f9d7488719cf8e6eaf150ca2eb4acb8a2e2cf780ba4d6bf

Contents?: true

Size: 1.98 KB

Versions: 22

Compression:

Stored size: 1.98 KB

Contents

<% if @recs.size > 0 %>
function avg(aRecs){dSum = 0; for(nRec = 0; nRec < aRecs.length; nRec++) {dSum += aRecs[nRec].relevance;} return dSum/aRecs.length;}
function std(aRecs,dAvg){dSum = 0; for(nRec = 0; nRec < aRecs.length; nRec++) {dSum += Math.pow((aRecs[nRec].relevance-dAvg),2);} return Math.sqrt(dSum/aRecs.length);}
function calcThreshold(aRecs){var average = avg(aRecs);var standard_deviation = std(aRecs, average); return average + standard_deviation;}
function sortByClicks(r1,r2){return r2.clicks-r1.clicks;}
function randomize(aRecs){var i = aRecs.length;if (i == 0) return aRecs;while (--i){var j = Math.floor(Math.random()*(i+1));var ti = aRecs[i];var tj=aRecs[j];aRecs[i]= tj;aRecs[j]=ti;} return aRecs;}
function sortRecs(aRecs)
{
	var relevance_threshold = calcThreshold(aRecs);
	var nClickThreshold = 10;
	var aPopular = new Array();
	var aRelevant = new Array();
	var aLoosers = new Array();
	for(nRec = 0; nRec < aRecs.length; nRec++) {
		r = aRecs[nRec];
		if (r.clicks > nClickThreshold) aPopular.push(r);
		else if (r.relevance > relevance_threshold) aRelevant.push(r);
		else aLoosers.push(r);
	}
	return aPopular.sort(sortByClicks).concat(randomize(aRelevant),randomize(aLoosers));
}
var aRecommendations = [
<% @recs.each do |r| -%>
{"id":<%= r.id %>, "clicks":<%= r.clicks %>, "relevance":<%= r.relevance %>, "uri":"<%= r.uri %>", "title":"<%= r.title.gsub(/"/, '&#34;').gsub(/'/, "&#39;") %>", "source":"(<%= r.source %>)"},
<% end -%>]; 
document.write('<div class="oer_recommender_container"><div class="oer_recommender_title">Related Resources</div><div class="oer_recommender_list">');
var aSortedRecs = sortRecs(aRecommendations);
for(nRec = 0; nRec < aSortedRecs.length; nRec++) 
{
	r = aSortedRecs[nRec];
	document.write('<p class="oer_recommender_item"><a href="http://www.oerrecommender.org/r?id=' + r.id + "&u=" + r.uri + '" title="' + r.source + ' ' + r.title + '">' + r.title + '</a></p>');
}
document.write('</div></div>');	
<% end %>
<%= @recs_json %>

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
muck-raker-0.1.1 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.2 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.3 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.4 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.5 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.6 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.7 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.8 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.9 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.10 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.11 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.12 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.13 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.14 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.15 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.16 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.17 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.18 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.19 app/views/recommendations/index_js.pjs.erb
muck-raker-0.1.20 app/views/recommendations/index_js.pjs.erb