You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Francisco Viramontes <pa...@freshout.us> on 2009/10/08 05:15:38 UTC

different results for same group levels

I have a views problem that I dunno if can be solved by couch

here is my map function:

function(doc) {
         if ((doc['couchrest-type'] == 'DataValue') &&  
doc['device_variable_id']) {
           date =  new Date(doc.date_time);
           emit([doc.device_variable_id, date.getFullYear(),  
date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(),  
parseInt(date.getUTCMinutes() / 20) ], doc.value);
         }
       }

Please just min the last key portion emited ->  
parseInt(date.getUTCMinutes() / 20)

I use this to sum in groups of values of data for every 20 minutes

I DONT want to make another view if say for example I want to emit for  
5 minutes

Views already take too much space!!!

Is there a view I can make that handle conditional key emiting or  
something that I can pass a parameter to?

PAco

Re: different results for same group levels

Posted by Benoit Chesneau <bc...@gmail.com>.
On Thu, Oct 8, 2009 at 5:15 AM, Francisco Viramontes <pa...@freshout.us> wrote:
> I have a views problem that I dunno if can be solved by couch
>
> here is my map function:
>
> function(doc) {
>        if ((doc['couchrest-type'] == 'DataValue') &&
> doc['device_variable_id']) {
>          date =  new Date(doc.date_time);
>          emit([doc.device_variable_id, date.getFullYear(),
> date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(),
> parseInt(date.getUTCMinutes() / 20) ], doc.value);
>        }
>      }
>
> Please just min the last key portion emited -> parseInt(date.getUTCMinutes()
> / 20)
>
> I use this to sum in groups of values of data for every 20 minutes
>
> I DONT want to make another view if say for example I want to emit for 5
> minutes
>
> Views already take too much space!!!
>
> Is there a view I can make that handle conditional key emiting or something
> that I can pass a parameter to?
>
> PAco
>

you can't use date in your views. emit the key you need and try to
play with startkey/endkey to find it.

- benoît

Re: different results for same group levels

Posted by Brian Candler <B....@pobox.com>.
On Thu, Oct 08, 2009 at 10:40:51AM -0500, Francisco Viramontes wrote:
> I dont know what a list gunction is, can I have an example?

http://wiki.apache.org/couchdb/Formatting_with_Show_and_List

The web page says "these functions convert documents and views,
respectively, into non-JSON formats", but nothing stops you emitting JSON
from them if you wish.

See also the test suite, e.g. basicJSON in share/www/script/test/list_views.js

Re: different results for same group levels

Posted by Zachary Zolton <za...@gmail.com>.
http://wiki.apache.org/couchdb/Formatting_with_Show_and_List

On Thu, Oct 8, 2009 at 10:40 AM, Francisco Viramontes <pa...@freshout.us> wrote:
> I dont know what a list gunction is, can I have an example?
>
> PAco
> On Oct 8, 2009, at 10:21 AM, Brian Candler wrote:
>
>> On Wed, Oct 07, 2009 at 10:15:38PM -0500, Francisco Viramontes wrote:
>>>
>>> Is there a view I can make that handle conditional key emiting or
>>> something that I can pass a parameter to?
>>
>> No, views cannot take parameters. This is because they are built up-front,
>> and updated incrementally thereafter. That is, the view exists
>> independently
>> of the queries which are subsequently made against it.
>>
>> One option is to have a view which outputs keys in whatever the smallest
>> range is you want to support, say 1 minute buckets. Then you can combine
>> them into N-minute buckets client-side, or inside a _list function.
>
>

Re: different results for same group levels

Posted by Francisco Viramontes <pa...@freshout.us>.
I dont know what a list gunction is, can I have an example?

PAco
On Oct 8, 2009, at 10:21 AM, Brian Candler wrote:

> On Wed, Oct 07, 2009 at 10:15:38PM -0500, Francisco Viramontes wrote:
>> Is there a view I can make that handle conditional key emiting or
>> something that I can pass a parameter to?
>
> No, views cannot take parameters. This is because they are built up- 
> front,
> and updated incrementally thereafter. That is, the view exists  
> independently
> of the queries which are subsequently made against it.
>
> One option is to have a view which outputs keys in whatever the  
> smallest
> range is you want to support, say 1 minute buckets. Then you can  
> combine
> them into N-minute buckets client-side, or inside a _list function.


Re: different results for same group levels

Posted by Brian Candler <B....@pobox.com>.
On Wed, Oct 07, 2009 at 10:15:38PM -0500, Francisco Viramontes wrote:
> Is there a view I can make that handle conditional key emiting or  
> something that I can pass a parameter to?

No, views cannot take parameters. This is because they are built up-front,
and updated incrementally thereafter. That is, the view exists independently
of the queries which are subsequently made against it.

One option is to have a view which outputs keys in whatever the smallest
range is you want to support, say 1 minute buckets. Then you can combine
them into N-minute buckets client-side, or inside a _list function.