Skip to content

Commit

Permalink
add hotness algorithm and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
maccman committed Jan 27, 2012
1 parent 403f9a9 commit f5579ed
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions assets/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,36 @@

function addRecentlyUpdatedRepo(repo) {
var $item = $("<li>");
$item.append('<span class="name"><a href="' + repoUrl(repo) + '">' + repo.name + '</a></span>');
$item.append('<span class="time"><a href="' + repo.html_url + '/commits">' + strftime("%h %e, %Y", repo.pushed_at) + '</a></span>');

var $name = $("<a>").attr("href", repoUrl(repo)).text(repo.name);
$item.append($("<span>").addClass("name").append($name));

var $time = $("<a>").attr("href", repo.html_url + "/commits").text(strftime("%h %e, %Y", repo.pushed_at));
$item.append($("<span>").addClass("time").append($time));

$item.append('<span class="bullet">&sdot;</span>');
$item.append('<span class="watchers"><a href="' + repo.html_url + '/watchers">' + repo.watchers + ' watchers</a></span>');

var $watchers = $("<a>").attr("href", repo.html_url + "/watchers").text(repo.watchers);
$item.append($("<span>").addClass("watchers").append($watchers));

$item.append('<span class="bullet">&sdot;</span>');
$item.append('<span class="forks"><a href="' + repo.html_url + '/network">' + repo.forks + ' forks</a></span>');

var $forks = $("<a>").attr("href", repo.html_url + "/network").text(repo.forks + " forks");
$item.append($("<span>").append($forks));

$item.appendTo("#recently-updated-repos");
}

function addRepo(repo) {
var $item = $("<li>").addClass("repo grid-1 " + repo.language.toLowerCase());
var $item = $("<li>").addClass("repo grid-1 " + (repo.language || '').toLowerCase());
var $link = $("<a>").attr("href", repoUrl(repo)).appendTo($item);
$link.append($("<h2>").text(repo.name));
$link.append($("<h3>").text(repo.language));
$link.append($("<p>").text(repoDescription(repo)));
$item.appendTo("#repos");
}

$.getJSON("https://api.github.com/users/twitter/repos?callback=?", function (result) {
$.getJSON("https://api.github.com/orgs/twitter/repos?callback=?", function (result) {
var repos = result.data;

$(function () {
Expand All @@ -58,12 +69,23 @@
// Convert pushed_at to Date.
$.each(repos, function (i, repo) {
repo.pushed_at = new Date(repo.pushed_at);

var weekHalfLife = 1.146 * Math.pow(10, -9);

var pushDelta = (new Date) - Date.parse(repo.pushed_at);
var createdDelta = (new Date) - Date.parse(repo.created_at);

var weightForPush = 1;
var weightForWatchers = 1.314 * Math.pow(10, 7);

repo.hotness = weightForPush * Math.pow(Math.E, -1 * weekHalfLife * pushDelta);
repo.hotness += weightForWatchers * repo.watchers / createdDelta;
});

// Sort by highest # of watchers.
repos.sort(function (a, b) {
if (a.watchers < b.watchers) return 1;
if (b.watchers < a.watchers) return -1;
if (a.hotness < b.hotness) return 1;
if (b.hotness < a.hotness) return -1;
return 0;
});

Expand Down

0 comments on commit f5579ed

Please sign in to comment.