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 <[email protected]> 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 = <Application, Account, Subscription>
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

Reply via email to