NaN Rolling Sum

24 views
Skip to first unread message

Jason Hines

unread,
Feb 16, 2012, 10:23:20 AM2/16/12
to cube...@googlegroups.com
I'm new to Cube and have just setup a local demo to play around with.

After emitting some random data (random.js), I proceeded to create a graph that shows the median random value:

median(random(random))

This results in a NaN, which I assume is the result of a computation error.

Should I be able to compute the median from the sample random data emitter?

Thanks!

Mike Bostock

unread,
Feb 16, 2012, 12:16:31 PM2/16/12
to cube...@googlegroups.com
> This results in a NaN, which I assume is the result of a computation error.

Works for me? I can't reproduce the error. However, be aware that the
random data emitter picks a random date around which to create data.
So, if you're unlucky, it's easy to create a graph that has no data
defined within the associated time window even after running the
emitter. The median is undefined (NaN) if there are no events within
the given time interval.

For example, if I say:

http://localhost:1081/1.0/metric?expression=median(random(random))&start=2012-02-16T00:00:00Z&stop=2012-02-16T00:15:00Z&step=300000

I get:

[
{"time":"2012-02-16T00:00:00.000Z","value":-0.5439993245527148},
{"time":"2012-02-16T00:05:00.000Z","value":-0.5125112039968371},
{"time":"2012-02-16T00:10:00.000Z","value":-0.4808696174295619}
]

But if I picked some range where the data is undefined, I get:

[
{"time":"2012-02-17T00:00:00.000Z"},
{"time":"2012-02-17T00:05:00.000Z"},
{"time":"2012-02-17T00:10:00.000Z"}
]

Mike

Jason Hines

unread,
Feb 16, 2012, 4:08:50 PM2/16/12
to cube...@googlegroups.com
Thanks for the explanation and example.  It's helping me understand the inner workings tremendously.

So, in my tinkering, I edited the random.js to specify the date as Date(Date.now()), so that I could get a sense of real-time data being fed into Cube.

When I view my data from say, 4pm (when I started testing)...


I find mixed results (which seems normal, since I'm running the emitter on and off)

[
{time: "2012-02-16T20:00:00.000Z"},
{time: "2012-02-16T20:05:00.000Z"},
{time: "2012-02-16T20:10:00.000Z"},
{time: "2012-02-16T20:15:00.000Z",value: 0.29840014898218215},
{time: "2012-02-16T20:20:00.000Z",value: -0.49999387632124126},
{time: "2012-02-16T20:25:00.000Z",value: -0.5006494133267552},
{time: "2012-02-16T20:30:00.000Z"},
{time: "2012-02-16T20:35:00.000Z"},
{time: "2012-02-16T20:40:00.000Z"},
]

I'm still seeing NaN on the Rolling Sum, no matter what time range I specify.  I'm not sure what parameters are being sent to /metric/get, so it's very likely (almost positive) that I'm just not doing something right.

Thanks again for any insight you might be able to share.

Mike Bostock

unread,
Feb 16, 2012, 4:51:47 PM2/16/12
to cube...@googlegroups.com
Your output looks correct; the undefined metrics are because there are
no random events in those time intervals. Try switching the expression
to sum(random) to count the number of events.

Mike

Jason Hines

unread,
Feb 16, 2012, 4:57:05 PM2/16/12
to cube...@googlegroups.com
Changing the expression to sum(random) works, as indications that there are no events in that time interval (value: 0)

However, I'm still unable to get a median random number to display in the RollingSum chart.  (NaN error)

Mike Bostock

unread,
Feb 16, 2012, 6:11:20 PM2/16/12
to cube...@googlegroups.com
> However, I'm still unable to get a median random number to display in the
> RollingSum chart.  (NaN error)

Right, that's because the value is undefined, because the bins are empty.

Mike

Reply all
Reply to author
Forward
0 new messages