You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Tom Sante <to...@gmail.com> on 2010/05/20 13:38:55 UTC

Reduce function results

Hi,

I have a reduce function like this:
// reduce function
function (keys, values, rereduce) {
     var res={};

     if(!rereduce){ /* reduce */
	for(var val in values){
	    for(var v_n in values[val]){
		var v = new Number(values[val][v_n]);
		if(res.hasOwnProperty(v_n)){
		    res[v_n].mi = Math.min(v,res[v_n].mi);
		    res[v_n].ma = Math.max(v,res[v_n].ma);
		    res[v_n].c++;
		    res[v_n].t += v;
		}else{
		    res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
		}
	    }
	}
     }else{ /* rereduce */
	for(var val in values){
	    for(var v_n in values[val]){
		if(res.hasOwnProperty(v_n)){
		    res[v_n].mi = Math.min(values[val][v_n].mi,res[v_n].mi);
		    res[v_n].ma = Math.max(values[val][v_n].ma,res[v_n].ma);
		    res[v_n].c += values[val][v_n].c;
		    res[v_n].t += values[val][v_n].t;
		}else{
		 
res[v_n]={'mi':values[val][v_n].mi,'ma':values[val][v_n].ma,'c':values[val][v_n].c,'t':values[val][v_n].t};
		}
	    }
	}
     }

     return res;
}

and it get key, values pair from a map functions that produces these:
"01:00:000074" -> {raw: "-0.213"}
"01:00:000084" -> {raw: "0.129"}

But when I query the view i get this back:
"01:00:000074" -> {raw: {mi: {}, ma: {}, c: 1, t: {}}}
"01:00:000084" -> {raw: {mi: {}, ma: {}, c: 1, t: {}}}

So for some reason if there is only 1 element to be reduced, on the line of
res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
v becomes v={} and not the actual number. Any ideas why?

I tested the reduce function with the command line 'js' and send it the 
above test keys manually as function argument and then it does result in 
the correct return:
"01:00:000074" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
"01:00:000084" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}



Re: Reduce function results

Posted by Tom Sante <to...@gmail.com>.
On 21/05/10 19:53, J Chris Anderson wrote:
> On May 21, 2010, at 10:37 AM, Tom Sante wrote:
>
>> >  Because the data was stored like that, but indeed for future database this will be stored as a JSON number. Still doesn't explain why the different behaviour of Number() in couch compared to 'js'.
>> >
> The only factor I can think of is the inclusion of json2.js in the main.js source code... You might have a look through share/server for clues.
>

You're right I think this part of json2.js might be it:

// Otherwise, iterate through all of the keys in the object.

                 for (k in value) {
                     if (Object.hasOwnProperty.call(value, k)) {
                         v = str(k, value);
                         if (v) {
                             partial.push(quote(k) + (gap ? ': ' : ':') 
+ v);
                         }
                     }
                 }
             }

For a Number is seen as an typeof = object it will iterate through it 
but that doesn't return anything for a Number() object so it ends up as 
being {} in JSON.
The v from var v = new Number(values[val][v_n]) only directly gets 
converted to JSON if there was only one doc send to my reduce function. 
If there was more than one doc send to the reduce function it works 
because the v is send to the Math.min() function which will always 
return a typeof number, and that does get converted to JSON correctly.

Calling v.valueOf() returns the Number object as a typeof number and 
solves the problem.

Re: Reduce function results

Posted by J Chris Anderson <jc...@gmail.com>.
On May 21, 2010, at 10:37 AM, Tom Sante wrote:

> Because the data was stored like that, but indeed for future database this will be stored as a JSON number. Still doesn't explain why the different behaviour of Number() in couch compared to 'js'.
> 

The only factor I can think of is the inclusion of json2.js in the main.js source code... You might have a look through share/server for clues.

> Side question:
> What would result in the smallest document byte size? storing it as a string like "0.345" (only need precision of 0.001) or as a JSON number?

You'd have to experiment to know for sure. I'm gonna guess that numbers will store smaller than strings (they will definitely sort faster).

Chris

> For a few docs this will not matter but in my case a dataset size of 10 million docs (seperated in different DB's), this could have a significant impact.
> 
> On 21/05/10 18:41, J Chris Anderson wrote:
>> It's this line that looked odd to me:
>> 
>>>>>> var v = new Number(values[val][v_n]);
>>>> 
>> 
>> 
>> 
>> I don't usually see the new Number() construct. Why not just store as a JSON number and then use values[val][v_n] directly?
>> 
>> Chris
>> 
>> On May 21, 2010, at 1:21 AM, Tom Sante wrote:
>> 
>>> Ok the log() helped to narrow things down:
>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>> in this context v isn't returned as a Number but as a {}
>>> In number context, like in a Math.min(v,othernumber); it works fine.
>>> Same thing happens with log:
>>> log(v) returns {}
>>> log(''+v) returns -0.453
>>> 
>>> Any reason why this would be the case since this is not the behaviour of a Number in normal js (JavaScript-C 1.7.0 2007-10-03) ?
>>> 
>>> I worked around it by forcing v to become a string here
>>> res[v_n]={'mi':''+v,'ma':''+v,'c':1,'t':''+v};
>>> But when i later do a sum like res[v_n].t += v;
>>> it just concats the v to it instead of adding its values
>>> So there i have to convert it back to a Number() before adding.
>>> 
>>> On 21/05/10 10:01, Tom Sante wrote:
>>>> Yeah I'll try that, see if it gives me any clues.
>>>> Is there a way to run your code manually for debugging via the command
>>>> line with the JS engine the way couch calls it to build the view? (like
>>>> an interactive mode of couchjs)
>>>> 
>>>> On 21/05/10 04:59, Zachary Zolton wrote:
>>>>> Reduce functions can be tricky. My best advice: try log()'ing all your
>>>>> input and intermediary results; the answer usually jumps out to ya.
>>>>> 
>>>>> On Thursday, May 20, 2010, Tom Sante<to...@gmail.com>  wrote:
>>>>>> On 20/05/10 23:52, David Goodlad wrote:
>>>>>> 
>>>>>> On Thu, May 20, 2010 at 9:38 PM, Tom Sante<to...@gmail.com>  wrote:
>>>>>> 
>>>>>> Hi,
>>>>>> 
>>>>>> I have a reduce function like this:
>>>>>> [snip]
>>>>>> So for some reason if there is only 1 element to be reduced, on the
>>>>>> line of
>>>>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>>>>> v becomes v={} and not the actual number. Any ideas why?
>>>>>> 
>>>>>> I tested the reduce function with the command line 'js' and send it the
>>>>>> above test keys manually as function argument and then it does result
>>>>>> in the
>>>>>> correct return:
>>>>>> "01:00:000074" ->  {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>>>>> "01:00:000084" ->  {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>>>>> 
>>>>>> 
>>>>>> Sounds like you need to specify group_level; Try playing around in
>>>>>> Futon, you'll see a group_level dropdown.
>>>>>> 
>>>>>> Dave
>>>>>> 
>>>>>> 
>>>>>> Why would I need a group_level parameter?
>>>>>> My key is a simple string "01:00:000074".
>>>>>> Its my values don't get correctly generated by couchjs, since it does
>>>>>> out but proper values in normal commandline js.
>>>>>> 
>>>>>> var v = new Number(values[val][v_n]);
>>>>>> if(res.hasOwnProperty(v_n)){
>>>>>> res[v_n].mi = Math.min(v,res[v_n].mi);
>>>>>> res[v_n].ma = Math.max(v,res[v_n].ma);
>>>>>> res[v_n].c++;
>>>>>> res[v_n].t += v;
>>>>>> }else{
>>>>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>>>>> }
>>>>>> 
>>>>>> It seems that in the above part in the 'else' case the v isn't a
>>>>>> number but an empty object {}
>>>>>> 
>>>> 
>>> 
>> 
>> 
> 


Re: Reduce function results

Posted by Tom Sante <to...@gmail.com>.
Because the data was stored like that, but indeed for future database 
this will be stored as a JSON number. Still doesn't explain why the 
different behaviour of Number() in couch compared to 'js'.

Side question:
What would result in the smallest document byte size? storing it as a 
string like "0.345" (only need precision of 0.001) or as a JSON number?
For a few docs this will not matter but in my case a dataset size of 10 
million docs (seperated in different DB's), this could have a 
significant impact.

On 21/05/10 18:41, J Chris Anderson wrote:
> It's this line that looked odd to me:
>
>>>>> var v = new Number(values[val][v_n]);
>>>
>
>
>
> I don't usually see the new Number() construct. Why not just store as a JSON number and then use values[val][v_n] directly?
>
> Chris
>
> On May 21, 2010, at 1:21 AM, Tom Sante wrote:
>
>> Ok the log() helped to narrow things down:
>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>> in this context v isn't returned as a Number but as a {}
>> In number context, like in a Math.min(v,othernumber); it works fine.
>> Same thing happens with log:
>> log(v) returns {}
>> log(''+v) returns -0.453
>>
>> Any reason why this would be the case since this is not the behaviour of a Number in normal js (JavaScript-C 1.7.0 2007-10-03) ?
>>
>> I worked around it by forcing v to become a string here
>> res[v_n]={'mi':''+v,'ma':''+v,'c':1,'t':''+v};
>> But when i later do a sum like res[v_n].t += v;
>> it just concats the v to it instead of adding its values
>> So there i have to convert it back to a Number() before adding.
>>
>> On 21/05/10 10:01, Tom Sante wrote:
>>> Yeah I'll try that, see if it gives me any clues.
>>> Is there a way to run your code manually for debugging via the command
>>> line with the JS engine the way couch calls it to build the view? (like
>>> an interactive mode of couchjs)
>>>
>>> On 21/05/10 04:59, Zachary Zolton wrote:
>>>> Reduce functions can be tricky. My best advice: try log()'ing all your
>>>> input and intermediary results; the answer usually jumps out to ya.
>>>>
>>>> On Thursday, May 20, 2010, Tom Sante<to...@gmail.com>  wrote:
>>>>> On 20/05/10 23:52, David Goodlad wrote:
>>>>>
>>>>> On Thu, May 20, 2010 at 9:38 PM, Tom Sante<to...@gmail.com>  wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I have a reduce function like this:
>>>>> [snip]
>>>>> So for some reason if there is only 1 element to be reduced, on the
>>>>> line of
>>>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>>>> v becomes v={} and not the actual number. Any ideas why?
>>>>>
>>>>> I tested the reduce function with the command line 'js' and send it the
>>>>> above test keys manually as function argument and then it does result
>>>>> in the
>>>>> correct return:
>>>>> "01:00:000074" ->  {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>>>> "01:00:000084" ->  {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>>>>
>>>>>
>>>>> Sounds like you need to specify group_level; Try playing around in
>>>>> Futon, you'll see a group_level dropdown.
>>>>>
>>>>> Dave
>>>>>
>>>>>
>>>>> Why would I need a group_level parameter?
>>>>> My key is a simple string "01:00:000074".
>>>>> Its my values don't get correctly generated by couchjs, since it does
>>>>> out but proper values in normal commandline js.
>>>>>
>>>>> var v = new Number(values[val][v_n]);
>>>>> if(res.hasOwnProperty(v_n)){
>>>>> res[v_n].mi = Math.min(v,res[v_n].mi);
>>>>> res[v_n].ma = Math.max(v,res[v_n].ma);
>>>>> res[v_n].c++;
>>>>> res[v_n].t += v;
>>>>> }else{
>>>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>>>> }
>>>>>
>>>>> It seems that in the above part in the 'else' case the v isn't a
>>>>> number but an empty object {}
>>>>>
>>>
>>
>
>


Re: Reduce function results

Posted by J Chris Anderson <jc...@gmail.com>.
It's this line that looked odd to me:

>>>> var v = new Number(values[val][v_n]);
>> 



I don't usually see the new Number() construct. Why not just store as a JSON number and then use values[val][v_n] directly?

Chris

On May 21, 2010, at 1:21 AM, Tom Sante wrote:

> Ok the log() helped to narrow things down:
> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
> in this context v isn't returned as a Number but as a {}
> In number context, like in a Math.min(v,othernumber); it works fine.
> Same thing happens with log:
> log(v) returns {}
> log(''+v) returns -0.453
> 
> Any reason why this would be the case since this is not the behaviour of a Number in normal js (JavaScript-C 1.7.0 2007-10-03) ?
> 
> I worked around it by forcing v to become a string here
> res[v_n]={'mi':''+v,'ma':''+v,'c':1,'t':''+v};
> But when i later do a sum like res[v_n].t += v;
> it just concats the v to it instead of adding its values
> So there i have to convert it back to a Number() before adding.
> 
> On 21/05/10 10:01, Tom Sante wrote:
>> Yeah I'll try that, see if it gives me any clues.
>> Is there a way to run your code manually for debugging via the command
>> line with the JS engine the way couch calls it to build the view? (like
>> an interactive mode of couchjs)
>> 
>> On 21/05/10 04:59, Zachary Zolton wrote:
>>> Reduce functions can be tricky. My best advice: try log()'ing all your
>>> input and intermediary results; the answer usually jumps out to ya.
>>> 
>>> On Thursday, May 20, 2010, Tom Sante<to...@gmail.com> wrote:
>>>> On 20/05/10 23:52, David Goodlad wrote:
>>>> 
>>>> On Thu, May 20, 2010 at 9:38 PM, Tom Sante<to...@gmail.com> wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> I have a reduce function like this:
>>>> [snip]
>>>> So for some reason if there is only 1 element to be reduced, on the
>>>> line of
>>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>>> v becomes v={} and not the actual number. Any ideas why?
>>>> 
>>>> I tested the reduce function with the command line 'js' and send it the
>>>> above test keys manually as function argument and then it does result
>>>> in the
>>>> correct return:
>>>> "01:00:000074" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>>> "01:00:000084" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>>> 
>>>> 
>>>> Sounds like you need to specify group_level; Try playing around in
>>>> Futon, you'll see a group_level dropdown.
>>>> 
>>>> Dave
>>>> 
>>>> 
>>>> Why would I need a group_level parameter?
>>>> My key is a simple string "01:00:000074".
>>>> Its my values don't get correctly generated by couchjs, since it does
>>>> out but proper values in normal commandline js.
>>>> 
>>>> var v = new Number(values[val][v_n]);
>>>> if(res.hasOwnProperty(v_n)){
>>>> res[v_n].mi = Math.min(v,res[v_n].mi);
>>>> res[v_n].ma = Math.max(v,res[v_n].ma);
>>>> res[v_n].c++;
>>>> res[v_n].t += v;
>>>> }else{
>>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>>> }
>>>> 
>>>> It seems that in the above part in the 'else' case the v isn't a
>>>> number but an empty object {}
>>>> 
>> 
> 


Re: Reduce function results

Posted by Tom Sante <to...@gmail.com>.
Ok the log() helped to narrow things down:
res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
in this context v isn't returned as a Number but as a {}
In number context, like in a Math.min(v,othernumber); it works fine.
Same thing happens with log:
log(v) returns {}
log(''+v) returns -0.453

Any reason why this would be the case since this is not the behaviour of 
a Number in normal js (JavaScript-C 1.7.0 2007-10-03) ?

I worked around it by forcing v to become a string here
res[v_n]={'mi':''+v,'ma':''+v,'c':1,'t':''+v};
But when i later do a sum like res[v_n].t += v;
it just concats the v to it instead of adding its values
So there i have to convert it back to a Number() before adding.

On 21/05/10 10:01, Tom Sante wrote:
> Yeah I'll try that, see if it gives me any clues.
> Is there a way to run your code manually for debugging via the command
> line with the JS engine the way couch calls it to build the view? (like
> an interactive mode of couchjs)
>
> On 21/05/10 04:59, Zachary Zolton wrote:
>> Reduce functions can be tricky. My best advice: try log()'ing all your
>> input and intermediary results; the answer usually jumps out to ya.
>>
>> On Thursday, May 20, 2010, Tom Sante<to...@gmail.com> wrote:
>>> On 20/05/10 23:52, David Goodlad wrote:
>>>
>>> On Thu, May 20, 2010 at 9:38 PM, Tom Sante<to...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I have a reduce function like this:
>>> [snip]
>>> So for some reason if there is only 1 element to be reduced, on the
>>> line of
>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>> v becomes v={} and not the actual number. Any ideas why?
>>>
>>> I tested the reduce function with the command line 'js' and send it the
>>> above test keys manually as function argument and then it does result
>>> in the
>>> correct return:
>>> "01:00:000074" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>> "01:00:000084" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>>
>>>
>>> Sounds like you need to specify group_level; Try playing around in
>>> Futon, you'll see a group_level dropdown.
>>>
>>> Dave
>>>
>>>
>>> Why would I need a group_level parameter?
>>> My key is a simple string "01:00:000074".
>>> Its my values don't get correctly generated by couchjs, since it does
>>> out but proper values in normal commandline js.
>>>
>>> var v = new Number(values[val][v_n]);
>>> if(res.hasOwnProperty(v_n)){
>>> res[v_n].mi = Math.min(v,res[v_n].mi);
>>> res[v_n].ma = Math.max(v,res[v_n].ma);
>>> res[v_n].c++;
>>> res[v_n].t += v;
>>> }else{
>>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>> }
>>>
>>> It seems that in the above part in the 'else' case the v isn't a
>>> number but an empty object {}
>>>
>


Re: Reduce function results

Posted by Tom Sante <to...@gmail.com>.
Yeah I'll try that, see if it gives me any clues.
Is there a way to run your code manually for debugging via the command 
line with the JS engine the way couch calls it to build the view? (like 
an interactive mode of couchjs)

On 21/05/10 04:59, Zachary Zolton wrote:
> Reduce functions can be tricky. My best advice: try log()'ing all your
> input and intermediary results; the answer usually jumps out to ya.
>
> On Thursday, May 20, 2010, Tom Sante<to...@gmail.com>  wrote:
>> On 20/05/10 23:52, David Goodlad wrote:
>>
>> On Thu, May 20, 2010 at 9:38 PM, Tom Sante<to...@gmail.com>    wrote:
>>
>> Hi,
>>
>> I have a reduce function like this:
>> [snip]
>> So for some reason if there is only 1 element to be reduced, on the line of
>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>> v becomes v={} and not the actual number. Any ideas why?
>>
>> I tested the reduce function with the command line 'js' and send it the
>> above test keys manually as function argument and then it does result in the
>> correct return:
>> "01:00:000074" ->    {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>> "01:00:000084" ->    {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>>
>>
>> Sounds like you need to specify group_level; Try playing around in
>> Futon, you'll see a group_level dropdown.
>>
>> Dave
>>
>>
>> Why would I need a group_level parameter?
>> My key is a simple string "01:00:000074".
>> Its my values don't get correctly generated by couchjs, since it does out but proper values in normal commandline js.
>>
>>          var v = new Number(values[val][v_n]);
>>          if(res.hasOwnProperty(v_n)){
>>              res[v_n].mi = Math.min(v,res[v_n].mi);
>>              res[v_n].ma = Math.max(v,res[v_n].ma);
>>              res[v_n].c++;
>>              res[v_n].t += v;
>>          }else{
>>              res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>>          }
>>
>> It seems that in the above part in the 'else' case the v isn't a number but an empty object {}
>>


Re: Reduce function results

Posted by Zachary Zolton <za...@gmail.com>.
Reduce functions can be tricky. My best advice: try log()'ing all your
input and intermediary results; the answer usually jumps out to ya.

On Thursday, May 20, 2010, Tom Sante <to...@gmail.com> wrote:
> On 20/05/10 23:52, David Goodlad wrote:
>
> On Thu, May 20, 2010 at 9:38 PM, Tom Sante<to...@gmail.com>  wrote:
>
> Hi,
>
> I have a reduce function like this:
> [snip]
> So for some reason if there is only 1 element to be reduced, on the line of
> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
> v becomes v={} and not the actual number. Any ideas why?
>
> I tested the reduce function with the command line 'js' and send it the
> above test keys manually as function argument and then it does result in the
> correct return:
> "01:00:000074" ->  {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
> "01:00:000084" ->  {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>
>
> Sounds like you need to specify group_level; Try playing around in
> Futon, you'll see a group_level dropdown.
>
> Dave
>
>
> Why would I need a group_level parameter?
> My key is a simple string "01:00:000074".
> Its my values don't get correctly generated by couchjs, since it does out but proper values in normal commandline js.
>
>         var v = new Number(values[val][v_n]);
>         if(res.hasOwnProperty(v_n)){
>             res[v_n].mi = Math.min(v,res[v_n].mi);
>             res[v_n].ma = Math.max(v,res[v_n].ma);
>             res[v_n].c++;
>             res[v_n].t += v;
>         }else{
>             res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>         }
>
> It seems that in the above part in the 'else' case the v isn't a number but an empty object {}
>

Re: Reduce function results

Posted by Tom Sante <to...@gmail.com>.
On 20/05/10 23:52, David Goodlad wrote:
> On Thu, May 20, 2010 at 9:38 PM, Tom Sante<to...@gmail.com>  wrote:
>> Hi,
>>
>> I have a reduce function like this:
>> [snip]
>> So for some reason if there is only 1 element to be reduced, on the line of
>> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
>> v becomes v={} and not the actual number. Any ideas why?
>>
>> I tested the reduce function with the command line 'js' and send it the
>> above test keys manually as function argument and then it does result in the
>> correct return:
>> "01:00:000074" ->  {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>> "01:00:000084" ->  {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
>
> Sounds like you need to specify group_level; Try playing around in
> Futon, you'll see a group_level dropdown.
>
> Dave

Why would I need a group_level parameter?
My key is a simple string "01:00:000074".
Its my values don't get correctly generated by couchjs, since it does 
out but proper values in normal commandline js.

         var v = new Number(values[val][v_n]);
         if(res.hasOwnProperty(v_n)){
             res[v_n].mi = Math.min(v,res[v_n].mi);
             res[v_n].ma = Math.max(v,res[v_n].ma);
             res[v_n].c++;
             res[v_n].t += v;
         }else{
             res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
         }

It seems that in the above part in the 'else' case the v isn't a number 
but an empty object {}

Re: Reduce function results

Posted by David Goodlad <da...@goodlad.ca>.
On Thu, May 20, 2010 at 9:38 PM, Tom Sante <to...@gmail.com> wrote:
> Hi,
>
> I have a reduce function like this:
> [snip]
> So for some reason if there is only 1 element to be reduced, on the line of
> res[v_n]={'mi':v,'ma':v,'c':1,'t':v};
> v becomes v={} and not the actual number. Any ideas why?
>
> I tested the reduce function with the command line 'js' and send it the
> above test keys manually as function argument and then it does result in the
> correct return:
> "01:00:000074" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}
> "01:00:000084" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}}

Sounds like you need to specify group_level; Try playing around in
Futon, you'll see a group_level dropdown.

Dave