You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Cory Zue <cz...@dimagi.com> on 2010/07/27 16:19:12 UTC

Reporting in CouchDB

I need to write some reports on top of the data in my couch db
application.  My use case is a central database monitoring the data
coming in from a bunch of satellite sites, and they want to generate
aggregate reports on the data by site and by date range.

My current plan is to use a view with a complex key that includes the
site id and date the data came in, with the value being a dictionary
of contributions the data makes to each aggregate indicator in the
report.  Then my reduce function can just sum up the individual keys.

However, this will only generate reports with the granularity of a
single day out-of-the-box, which means I will need to do further
processing on the client side in order to aggregate the counts over
the entire range specified.

My question is -- is there any way to do this in one view via couchdb?
 My understanding is that the best aggregation I can do is get it down
to one value per key, so even though I am only using the keys to
specify start and end ranges and always want to return a full
aggregate with a single set of counts I still have to do the final
aggregation on the client side.

Sorry if this is unclear.  I'd be happy to clarify over mail or IRC if
necessary.

thanks,
Cory

Re: Reporting in CouchDB

Posted by Cory Zue <cz...@dimagi.com>.
On Tue, Jul 27, 2010 at 10:22 AM, Luke Driscoll <lu...@gmail.com> wrote:
> If I understand what you're saying, I think you could make your key:
> [siteid, year, month, day]
>
> Then when you call reduce you could set the group_level to 1, 2, 3 or 4, to
> granulate by siteid, year, month and day respectively

Brilliant, thanks!  Didn't know about group_level...

Re: Reporting in CouchDB

Posted by Luke Driscoll <lu...@gmail.com>.
If I understand what you're saying, I think you could make your key:
[siteid, year, month, day]

Then when you call reduce you could set the group_level to 1, 2, 3 or 4, to
granulate by siteid, year, month and day respectively

Luke

On Tue, Jul 27, 2010 at 10:19, Cory Zue <cz...@dimagi.com> wrote:

> I need to write some reports on top of the data in my couch db
> application.  My use case is a central database monitoring the data
> coming in from a bunch of satellite sites, and they want to generate
> aggregate reports on the data by site and by date range.
>
> My current plan is to use a view with a complex key that includes the
> site id and date the data came in, with the value being a dictionary
> of contributions the data makes to each aggregate indicator in the
> report.  Then my reduce function can just sum up the individual keys.
>
> However, this will only generate reports with the granularity of a
> single day out-of-the-box, which means I will need to do further
> processing on the client side in order to aggregate the counts over
> the entire range specified.
>
> My question is -- is there any way to do this in one view via couchdb?
>  My understanding is that the best aggregation I can do is get it down
> to one value per key, so even though I am only using the keys to
> specify start and end ranges and always want to return a full
> aggregate with a single set of counts I still have to do the final
> aggregation on the client side.
>
> Sorry if this is unclear.  I'd be happy to clarify over mail or IRC if
> necessary.
>
> thanks,
> Cory
>