@Test public void testMake() { TsDataCollector dc = new TsDataCollector(); EnumSet<TsFrequency> defined = complementOf(of(Undefined)); dc.clear(); dc.addObservation(JAN2010, 10); defined.forEach(o -> assertThat(dc.make(o, None)).isEqualTo(data(o, 2010, 0, 10))); dc.clear(); dc.addObservation(JAN2010, 10); dc.addObservation(APR2010, 40); assertThat(dc.make(Monthly, None)).isEqualTo(data(Monthly, 2010, 0, 10, Double.NaN, Double.NaN, 40)); dc.clear(); dc.addObservation(JAN2010, 10); dc.addObservation(APR2010, 40); assertThat(dc.make(Quarterly, None)).isEqualTo(data(Quarterly, 2010, 0, 10, 40)); dc.clear(); dc.addObservation(JAN2010, 10); dc.addObservation(FEB2010, 20); assertThat(dc.make(Undefined, None)).isEqualTo(data(Monthly, 2010, 0, 10, 20)); dc.clear(); dc.addObservation(JAN2010, 10); dc.addObservation(FEB2010, 20); dc.addObservation(MAY2010, 50); assertThat(dc.make(Undefined, None)).isEqualTo(data(Monthly, 2010, 0, 10, 20, Double.NaN, Double.NaN, 50)); dc.clear(); dc.addObservation(JAN2010, 10); dc.addObservation(APR2010, 40); assertThat(dc.make(Undefined, None)).isEqualTo(data(Quarterly, 2010, 0, 10, 40)); dc.clear(); dc.addObservation(JAN2010, 12); dc.addObservation(JAN2010, 13); dc.addObservation(JAN2010, 10); dc.addObservation(JAN2010, 11); defined.forEach(o -> { assertThat(dc.make(o, First)).isEqualTo(data(o, 2010, 0, 12)); assertThat(dc.make(o, Last)).isEqualTo(data(o, 2010, 0, 11)); assertThat(dc.make(o, Min)).isEqualTo(data(o, 2010, 0, 10)); assertThat(dc.make(o, Max)).isEqualTo(data(o, 2010, 0, 13)); assertThat(dc.make(o, Average)).isEqualTo(data(o, 2010, 0, 46d / 4)); assertThat(dc.make(o, Sum)).isEqualTo(data(o, 2010, 0, 46)); }); dc.clear(); dc.addObservation(asDate(LocalDate.of(2010, 2, 1)), 20); dc.addObservation(asDate(LocalDate.of(2010, 1, 3)), 10); dc.addObservation(asDate(LocalDate.of(2010, 1, 4)), 11); dc.addObservation(asDate(LocalDate.of(2010, 1, 1)), 12); dc.addObservation(asDate(LocalDate.of(2010, 1, 2)), 13); assertThat(dc.make(Monthly, First)).isEqualTo(data(Monthly, 2010, 0, 12, 20)); assertThat(dc.make(Monthly, Last)).isEqualTo(data(Monthly, 2010, 0, 11, 20)); assertThat(dc.make(Monthly, Min)).isEqualTo(data(Monthly, 2010, 0, 10, 20)); assertThat(dc.make(Monthly, Max)).isEqualTo(data(Monthly, 2010, 0, 13, 20)); assertThat(dc.make(Monthly, Average)).isEqualTo(data(Monthly, 2010, 0, 46d / 4, 20)); assertThat(dc.make(Monthly, Sum)).isEqualTo(data(Monthly, 2010, 0, 46, 20)); }
public TsData make(TsFrequency frequency, TsAggregationType convMode) { if (frequency == TsFrequency.Undefined) { if (convMode != TsAggregationType.None) { throw new TsException(TsException.INVALID_AGGREGATIONMODE); } return makeFromUnknownFrequency(m_obs); } if (convMode != TsAggregationType.None) { return makeWithAggregation(m_obs, frequency, convMode); } return makeWithoutAggregation(m_obs, frequency); }
TsDataCollector { public TsData make(TsFrequency frequency, TsAggregationType convMode) { if (frequency == TsFrequency.Undefined) { if (convMode != TsAggregationType.None) { throw new TsException(TsException.INVALID_AGGREGATIONMODE); } return makeFromUnknownFrequency(m_obs); } if (convMode != TsAggregationType.None) { return makeWithAggregation(m_obs, frequency, convMode); } return makeWithoutAggregation(m_obs, frequency); } }
TsDataCollector { public TsData make(TsFrequency frequency, TsAggregationType convMode) { if (frequency == TsFrequency.Undefined) { if (convMode != TsAggregationType.None) { throw new TsException(TsException.INVALID_AGGREGATIONMODE); } return makeFromUnknownFrequency(m_obs); } if (convMode != TsAggregationType.None) { return makeWithAggregation(m_obs, frequency, convMode); } return makeWithoutAggregation(m_obs, frequency); } TsDataCollector(); }
TsDataCollector { public TsData make(TsFrequency frequency, TsAggregationType convMode) { if (frequency == TsFrequency.Undefined) { if (convMode != TsAggregationType.None) { throw new TsException(TsException.INVALID_AGGREGATIONMODE); } return makeFromUnknownFrequency(m_obs); } if (convMode != TsAggregationType.None) { return makeWithAggregation(m_obs, frequency, convMode); } return makeWithoutAggregation(m_obs, frequency); } TsDataCollector(); void addMissingValue(Date date); void addObservation(Date date, double value); void clear(); @NewObject double[] data(); int getCount(); double getMissingValue(); void setMissingValue(double value); TsData make(TsFrequency frequency, TsAggregationType convMode); @Internal static TsData makeWithAggregation(ObsList obs, TsFrequency freq, TsAggregationType convMode); @Internal static TsData makeFromUnknownFrequency(ObsList obs); @Internal static TsData makeWithoutAggregation(ObsList obs, TsFrequency freq); }
TsDataCollector { public TsData make(TsFrequency frequency, TsAggregationType convMode) { if (frequency == TsFrequency.Undefined) { if (convMode != TsAggregationType.None) { throw new TsException(TsException.INVALID_AGGREGATIONMODE); } return makeFromUnknownFrequency(m_obs); } if (convMode != TsAggregationType.None) { return makeWithAggregation(m_obs, frequency, convMode); } return makeWithoutAggregation(m_obs, frequency); } TsDataCollector(); void addMissingValue(Date date); void addObservation(Date date, double value); void clear(); @NewObject double[] data(); int getCount(); double getMissingValue(); void setMissingValue(double value); TsData make(TsFrequency frequency, TsAggregationType convMode); @Internal static TsData makeWithAggregation(ObsList obs, TsFrequency freq, TsAggregationType convMode); @Internal static TsData makeFromUnknownFrequency(ObsList obs); @Internal static TsData makeWithoutAggregation(ObsList obs, TsFrequency freq);  }