Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 600CAD732 for ; Thu, 20 Sep 2012 00:07:21 +0000 (UTC) Received: (qmail 62517 invoked by uid 500); 20 Sep 2012 00:07:19 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 62464 invoked by uid 500); 20 Sep 2012 00:07:19 -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 62456 invoked by uid 99); 20 Sep 2012 00:07:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Sep 2012 00:07:19 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FSL_RCVD_USER,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of carl.bourne@me.com designates 17.158.236.242 as permitted sender) Received: from [17.158.236.242] (HELO nk11p04mm-asmtp007.mac.com) (17.158.236.242) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Sep 2012 00:07:10 +0000 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from [192.168.1.64] (host86-165-160-238.range86-165.btcentralplus.com [86.165.160.238]) by nk11p04mm-asmtp007.mac.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Jan 3 2012)) with ESMTPSA id <0MAM00AISGB0C4B0@nk11p04mm-asmtp007.mac.com> for user@couchdb.apache.org; Thu, 20 Sep 2012 00:06:49 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855,1.0.431,0.0.0000 definitions=2012-09-19_07:2012-09-19,2012-09-19,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1209190316 From: Carl Bourne Subject: Summary view for Pie Charting Message-id: <08180A01-8DC0-491C-8976-B75BBB5F95F4@me.com> Date: Thu, 20 Sep 2012 01:06:29 +0100 To: "user@couchdb.apache.org" X-Mailer: Apple Mail (2.1486) Hi, I'm trying to build a summary view for a pie chart based on a document count within date ranges as shown below. The map function is basically working, except I need to get the "emit(XX-Days, 1);" part to write a variable label in the place of the XX-Days. e.g. 30-Days,60-Days,90-Days. However, I can't seem to work out a way to do this. Any suggestions would be much appreciated. Map Function: function(doc){ var now = new Date((new Date()).getTime()); var thirty_days_from_now = new Date((new Date()).getTime() + 30*24*60*60*1000); var sixty_days_from_now = new Date((new Date()).getTime() + 60*24*60*60*1000); var ninty_days_from_now = new Date((new Date()).getTime() + 90*24*60*60*1000); var expire = Date.parse(doc.date.expire) var exps = [thirty_days_from_now, sixty_days_from_now, ninty_days_from_now]; for (r in exps){ if (expire >= now && expire <= (exps[r])){ emit(XX-Days, 1); } } return; } Reduce Function: _count Regards, Carl