Timeseries.makeNorm

#1

This throws an NPE. Why?

var data = [];
var churn;
while (start < end) {
churn = _calculateMonthlyChurn(obj, start.clone()); // a number or null
data.push(churn);
start.addMonths(1)
}

var timeseriesSpec = NormTimeseriesDoubleSpec.make({
  start: start,
  end: end,
  interval: interval,
  data: data
});
return Timeseries.makeNorm(timeseriesSpec);
0 Likes

#2

This seems like a bug in the engine and should be reported as a JIRA ticket.

0 Likes

#3

Somewhat realated to this post, I am trying to figure out is the best (easiest) way to create a Timeseries object from a JavaScript Array?

I have a simple JS array stored in rr variable below, and I would expect that the function could figure out the rest:

    Timeseries.fromObjs(
      ObjArry.fromArry(rr), 
      {
        start: "2011-01-01",
        end: "2011-02-01",
        interval: "HOUR"
      }
    )

… but it doesnt, and says that it requires a third argument asTimeseriesSpec which in turn requires values for startPath and valuePath. Is there an easier way to achieving this, or do I actually need to define a start value for each element in my rr array? I would have imagined that the Timeseries constructor could figure out the start values on its own using start, end and interval???

0 Likes

#4

Calvin,

The original answer is the correct one.

0 Likes

#5

So there is a bug, was a ticket ever created @rohit.sureka? Im actually using the fromObjs API so perhaps its a different scenario.

0 Likes

#6

Calvin,

The startPath, endPath is needed “once” and not for every object. The reason is, ObjArry is an arry of generic obj. Let’s say your type happens to have 5 datetime fields named timestamp1,timestamp2… what field do you want the engine to use in order to construct your time series?

I am hearing that in scenarios where there is only field field of each kind e.g. datetime, double, the engine could infer the fields, but in other scenario the user will have to provide these as inputs. Let me know if that clarifies things for you

0 Likes

#7

Rohit,

I found a solution that is simple:

Timeseries.makeNorm(NormTimeseriesDoubleSpec.make({
    data: rr,
    start: start,
    end: end,
    interval: interval
  }))

rr here is a JS array of doubles. Even when I populated startPath and valuePath it would generate a 100% missing timeseries…

0 Likes

#8

Yes, Timeseries.makeNorm should be used in cases where you already have the timeseries elements. ObjArry is specifically for generating Timeseries from say e.g. fetch results

0 Likes