Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 76803 invoked from network); 10 Jun 2009 13:07:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Jun 2009 13:07:05 -0000 Received: (qmail 89181 invoked by uid 500); 10 Jun 2009 13:07:15 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 89114 invoked by uid 500); 10 Jun 2009 13:07:15 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 89074 invoked by uid 99); 10 Jun 2009 13:07:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2009 13:07:15 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of bchesneau@gmail.com designates 72.14.220.159 as permitted sender) Received: from [72.14.220.159] (HELO fg-out-1718.google.com) (72.14.220.159) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2009 13:07:03 +0000 Received: by fg-out-1718.google.com with SMTP id l27so1489306fgb.3 for ; Wed, 10 Jun 2009 06:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=jLK/I1q7kOAzOOO653DxDkTgkWFfqttbzxEJwjJrg90=; b=dFIswaldDF33HO4Grc4OYJpciICdmCObWNXPtCM5VgUXHXfX/k0hLn7WUFoIi08J1L xzgz5E3UMAJF/T91Rz/GQ69jAHmfdBF+I6fHk07cc5Du7bGqPF0gwsLKVeFI13a5Zxb/ vxAqgV/OP96XxH6URuT2YQo4c6Us9dHA+KPz0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ayCLhRm2cexAkE9U6kdH7Zp4++Z7Kl3cf+rbmE1+gAtCnTYOjYdNqatNGldrxVCV0X a7JSYbQDkeH1pmH05iG/G5A+4ON3UJ7cVw4OiTlaUVAGVyv6FP3KUSK7A0ljRYGeTNRy F6IToyihGN2ELCBAsYcHd/WCw8LzZyVAQwJLk= MIME-Version: 1.0 Received: by 10.86.71.8 with SMTP id t8mr1117164fga.60.1244639202366; Wed, 10 Jun 2009 06:06:42 -0700 (PDT) In-Reply-To: References: Date: Wed, 10 Jun 2009 15:06:42 +0200 Message-ID: Subject: Re: calulate doc popularity with couchdb map/reduce From: Benoit Chesneau To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org I improved a little the map/reduce code but still same error. I don't know where I am wrong at this point. If anyone have an idee please tell me. - beno=EEt map : function(doc) { // !code vendor/couchapp/date.js if (doc.type =3D=3D "vote") { var d =3D new Date().setRFC3339(doc.d).valueOf(); emit(doc.itemid, {d: d, v: doc.v}); } } reduce : function(keys, values, rereduce) { /* we use reddit algorithm to calculate scores http://blog.linkibol.com/post/How-to-Build-a-Popularity-Algorithm-You-can= -be-Proud-of.aspx http://news.ycombinator.com/item?id=3D231168 */ // all started at this date function score(A, B, x) { var t =3D A - B; if (x > 0) { y =3D 1; } else if (x =3D=3D 0) { y =3D 0; } else { y =3D -1; } z =3D (Math.abs(x) >=3D1 && Math.abs(x) || 1); log([t, x, y, z, Math.log(z) + (y*t)/45000]) return (Math.log(z) + (y*t)/45000); } var scores =3D {}; var points =3D {}; if (!rereduce) { // Thu May 28 11:16:49 2009 +0200 var B =3D 1243502209000; var oldkey =3D ""; for (var k in keys) { if (oldkey !=3D keys[k][0] && points[oldkey]) { scores[oldkey] =3D score(points[oldkey].A, B, points[oldkey].x ) } if (!points[keys[k][0]]) { oldkey =3D keys[k][0]; points[keys[k][0]] =3D { A: values[k].d, x: 0 } } points[keys[k][0]].x +=3D values[k].v; } lastkey =3D keys[keys.length-1][0]; scores[lastkey] =3D score(points[lastkey].A, B, points[lastkey].x ) log(scores); } else { scores =3D values[0]; for(var v =3D 1; v < values.length; v++) { for(var s in values[v]) { if (scores[s]) scores[s] +=3D values[v][s]; else scores[s] =3D values[v][s]; } } } var top =3D []; for (k in scores) top.push([k, scores[k]]); top.sort(function(a, b) { return a[1] - b[1] }); for(var n =3D 240; n < top.length; n++) if(top[n][0] !=3D lastkey) scores[top[n][0]] =3D undefined; return scores; }