Permalink
Browse files

added shit

  • Loading branch information...
1 parent cbc7660 commit 9ac429356d1e8d53bfc2926ce989014e82ec3c05 @lmatteis committed May 20, 2012
Showing with 38 additions and 19 deletions.
  1. +6 −11 app.js
  2. BIN attachments/grayarrow.gif
  3. +26 −0 common/ranking.js
  4. +6 −8 templates/all.html
View
17 app.js
@@ -16,18 +16,12 @@ ddoc = {
ddoc.views = {};
ddoc.views.items = {
map: function(doc) {
- // https://github.com/schmidek/News-aggregator/blob/master/views/rank/reduce.js
- function findScore(points, jsonDate) {
- var s = points;
- var order = Math.log(Math.max(Math.abs(s),1)) / Math.log(10);
- var sign = s > 0 ? 1 : (s<0 ? -1 : 0);
- var seconds = (new Date(jsonDate).getTime() /1000) - 1134028003;
- return Math.round((order + sign * seconds / 45000) * 10000000) / 10000000;
- }
if(doc.type === 'item') {
- if(!doc.points) doc.points = 0;
- // http://amix.dk/blog/post/19574
- var score = findScore(doc.points, doc.created_at);
+ var ranking = require('ranking');
+
+ var points = ranking.getPoints(doc.voted);
+ var score = ranking.findScore(points, doc.created_at);
+
emit(score, doc);
}
}
@@ -59,6 +53,7 @@ ddoc.lists.all = function(head, req) {
while(row = getRow()) {
var value = row.value;
+ var voted = value.voted;
if(!value.points) value.points = 0;
data.rows.push(value);
}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,26 @@
+var ranking = {
+ // https://github.com/schmidek/News-aggregator/blob/master/views/rank/reduce.js
+ findScore: function(points, jsonDate) {
+ var s = points + 1;
+ var order = Math.log(Math.max(Math.abs(s),1)) / Math.log(10);
+ var sign = s > 0 ? 1 : (s<0 ? -1 : 0);
+ var seconds = (new Date(jsonDate).getTime() /1000) - 1134028003;
+ return Math.round((order + sign * seconds / 45000) * 10000000) / 10000000;
+ },
+ getUnique: function(arr){
+ var u = {}, a = [];
+ for(var i = 0, l = arr.length; i < l; ++i){
+ if(arr[i] in u)
+ continue;
+ a.push(arr[i]);
+ u[arr[i]] = 1;
+ }
+ return a;
+ },
+ getPoints: function(voted) {
+ if(!voted) voted = [];
+ var arr = ranking.getUnique(voted);
+ var points = arr.length;
+ }
+};
+exports = ranking;
View
@@ -8,12 +8,10 @@
<td>
<center>
- <a id="up_15421" href=
- "vote?for=15421&amp;dir=up&amp;whence=%6e%65%77%73"
+ <a href="vote?for=15421&amp;dir=up&amp;whence=%6e%65%77%73"
name="up_15421"><img src=
- "http://ycombinator.com/images/grayarrow.gif"
- border="0" vspace="3" hspace="2"></a><span id=
- "down_15421"></span>
+ "/grayarrow.gif"
+ border="0" vspace="3" hspace="2"></a><span></span>
</center>
</td>
@@ -26,10 +24,10 @@
<tr>
<td colspan="2"></td>
- <td class="subtext"><span id="score_15421">{{points}}
+ <td class="subtext"><span>{{points}}
points</span> by <a href=
- "user?id=akkartik">akkartik</a> 20 hours ago |
- <a href="item?id=15421">discuss</a></td>
+ "/user?id={{author}}">{{author}}</a> <span class="created_at">{{created_at}}</span> |
+ <a href="/item?id={{_id}}">discuss</a></td>
</tr>
<tr style="height:5px">

0 comments on commit 9ac4293

Please sign in to comment.