Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 39017 invoked from network); 31 Jan 2011 01:04:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Jan 2011 01:04:04 -0000 Received: (qmail 16924 invoked by uid 500); 31 Jan 2011 01:04:02 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 16886 invoked by uid 500); 31 Jan 2011 01:04:01 -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 16878 invoked by uid 99); 31 Jan 2011 01:04:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jan 2011 01:04:01 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of ziggythehamster@gmail.com designates 209.85.218.52 as permitted sender) Received: from [209.85.218.52] (HELO mail-yi0-f52.google.com) (209.85.218.52) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jan 2011 01:03:55 +0000 Received: by yic1 with SMTP id 1so2140592yic.11 for ; Sun, 30 Jan 2011 17:03:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:x-mailer:mime-version:subject:date :references; bh=y7jEIH/SYOn5H0B+PJTA3GOjrvsb1A/BADxEP2SGCtA=; b=Xa2Z8UIZbBo3VPLyRvyVYfKkbTQDDoYewcOo2LPx/DtNRFhruOn6MuCFLKpK+AduCa afokQmdN2A3SS++5RtdtwTcWvi3t3rkhVN6f0aYCsw28/FDiluG4hFpyuJBuF1dtJCH4 l4S0SBGvlwLFBVdmOGiG2UF2xMJU4gVcNNOQ0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type :content-transfer-encoding:x-mailer:mime-version:subject:date :references; b=httRYxs/DJ0z91szOc4wIc6DHOdWUhmKSKpnDKctTWwTY8tW1rlAc33f+kHPRj8ZWH 823YL/JMXqxhaJNJwvs+wFfklh99xau0vSln7MLBADcANrB3FLwfpjwsoypc9F6c8G5e ZMSlt0AT5tqdy3kOY24tBtf8kkYlhdd+fEjkU= Received: by 10.150.142.16 with SMTP id p16mr7012812ybd.418.1296435814058; Sun, 30 Jan 2011 17:03:34 -0800 (PST) Received: from [192.168.1.37] (ip68-0-126-1.tu.ok.cox.net [68.0.126.1]) by mx.google.com with ESMTPS id v4sm13132537ybe.17.2011.01.30.17.03.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 30 Jan 2011 17:03:33 -0800 (PST) Message-Id: From: Keith Gable To: "user@couchdb.apache.org" In-Reply-To: <271065AB-F329-4B50-9D3A-48214E4EBACF@netdev.co.uk> Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Mailer: iPhone Mail (7D11) Mime-Version: 1.0 (iPhone Mail 7D11) Subject: Re: Reporting aggregated data using reduce function Date: Sun, 30 Jan 2011 19:02:16 -0600 References: <271065AB-F329-4B50-9D3A-48214E4EBACF@netdev.co.uk> It sounds like you need a new view for each piece of data. by_answered, by_busy, by_time_to_answer, etc. Then you'd query each view to get the reduction, and the reduce would be as simple as _sum. On Jan 30, 2011, at 5:55 PM, John wrote: > Hi > > I'm looking to extend our usage of couchdb by replacing our mysql > reporting db. > Whilst using couchdb successfully for a number of varied use cases > I've never had to do much with reduce so I'm unsure on how to use it > to reduce an array of values. > > Basically I want to be able to search a database using a composite > key and retrieving some aggregated information about number of > calls, call status, avg time to answer and avg duration > > > The following view shows how I'd like it to work: > > Key = > Value = <1, answered, busy, noreply, time to answer, duration> > > e.g. > > ["NTS", "NetDev", "MySub1"], [1,1,0,0,100,200] > ["NTS", "NetDev", "MySub1"], [1,1,0,0,150,400] > ["NTS", "NetDev", "MySub1"], [1,1,0,0,170,500] > ["NTS", "NetDev", "MySub1"], [1,0,1,0,0,0] > ["NTS", "NetDev", "MySub1"], [1,0,1,0,0,0] > ["NTS", "NetDev", "MySub1"], [1,0,0,2,0,0] > ["NTS", "NetDev", "MySub1"], [1,0,0,2,0,0] > > My Reduced output should look like this: > > [7,3,2,2,420,1100] > i.e. 7 calls in total, 3 answered, 2 busy, 2 no reply, the total > time for time to answer is 420 and the total time for call duration > is 1100. > > I can then compute the two averages after getting the data back from > couch i.e. 420/no. of answered calls(3) and 1100/no. of answered > calls(3) > > I thought that sum(values) would do this for me but it just upsets > couch: > > Reduce output must shrink more rapidly: Current output: > '[" > 001,11,11,11,11,11,11,11,11,11,11,101,11,11,11,11,11,11,11,11,11,11,11,101,11,11,11,11,11,11,11,11' > ... (first 100 of 277 bytes) > > What should my reduce function look like? > > Thanks > > John