Package ch.agent.t2.time

Examples of ch.agent.t2.time.TimeDomain


    if (def.getBaseUnit() == null)
      throw new IllegalArgumentException("basePeriod");
    if (def.getSubPeriodPattern() != null && !def.getBaseUnit().equals(def.getSubPeriodPattern().getBasePeriod()))
      throw new IllegalArgumentException("basePeriods differ");
    // step 1: find domain matching required attributes
    TimeDomain domain = getTimeDomain(def);
   
    // step 2: if not found, verify that label is available, then create new domain
    if (domain == null) {
      if (def.getLabel() == null) {
        def.setLabel(inventLabel());
      } else {
        domain = domains.get(def.getLabel());
        if (domain != null) {
          Exception cause = T2Msg.exception(K.T0007, domain.toString());
          throw T2Msg.runtimeException(K.T0001, cause);
        }
      }
      ExternalTimeFormat externalFormat = getExternalTimeFormat();
      if (externalFormat == null)
View Full Code Here


      return;
    if (builtIns.length > 0) {
      int i = 0;
      for (String def : declaredBuiltIns) {
        try {
          TimeDomain d = get(def);
          ((TimeFactory) d).markBuiltIn(i);
          builtIns[i] = d;
          i++;
        } catch (T2Exception e) {
          Exception cause = T2Msg.exception(e, K.T0008, this.getClass().getCanonicalName());
View Full Code Here

  }
 
  public void testSubRangeHasNoMissingValuesAtTheBoundaries() {
    try {
      Series<Double> s = makeSeries(makeTimeSeries());
      TimeDomain dom = s.getTimeDomain();
      TimeAddressable<Double> ts = s.getValues(new Range(dom, "2011-05-15", "2011-07-15", Adjustment.NONE));
      assertEquals(new Range(dom, "2011-06-01", "2011-07-01", Adjustment.NONE), ts.getRange());
    } catch (Exception e) {
      fail(e.toString());
    }
View Full Code Here

  }
 
  public void testGetLastValue_1() {
    try {
      Series<Double> s = makeSeries(makeTimeSeries());
      TimeDomain dom = s.getTimeDomain();
      Range range = new Range(dom.time("2011-05-15"), dom.time("2011-07-15"));
      TimeAddressable<Double> ts = s.getValues(range);
      Observation<Double> obs = ts.getLast(dom.time("2011-06-01"));
      assertEquals("2011-06-01", obs.getTime().toString());
    } catch (Exception e) {
      fail(e.toString());
    }
  }
View Full Code Here

  }
 
  public void testGetLastValue_3() {
    try {
      Series<Double> s = makeSeries(makeTimeSeries());
      TimeDomain dom = s.getTimeDomain();
      Range range = new Range(dom.time("2011-05-15"), dom.time("2011-07-15"));
      TimeAddressable<Double> ts = s.getValues(range);
      Observation<Double> obs = ts.getLast(dom.time("2011-05-31"));
      assertNull(obs);
    } catch (Exception e) {
      fail(e.toString());
    }
  }
View Full Code Here

    s.applyUpdates();
    return s;
  }
 
  private TimeAddressable<Double> makeTimeSeries() throws Exception {
    TimeDomain domain = SERIES_DOMAIN;
    TimeAddressable<Double> ts = TimeSeriesFactory.make(domain, Double.class);
    ts.put(domain.time("2011-05-01"), 201105.01);
    ts.put(domain.time("2011-06-01"), 201106.01);
    ts.put(domain.time("2011-07-01"), 201107.01);
    return ts;
  }
View Full Code Here

    ts.put(domain.time("2011-06-01"), 201106.01);
    ts.put(domain.time("2011-07-01"), 201107.01);
    return ts;
  }
  private TimeAddressable<Double> makeTimeSeries2() throws Exception {
    TimeDomain domain = SERIES_DOMAIN;
    TimeAddressable<Double> ts = TimeSeriesFactory.make(domain, Double.class);
    ts.put(domain.time("2011-05-01"), 201105.01);
    ts.put(domain.time("2011-05-02"), 201105.02);
    ts.put(domain.time("2011-05-03"), 201105.03);
    ts.put(domain.time("2011-05-30"), 201105.30);
    ts.put(domain.time("2011-05-31"), 201105.31);
    ts.put(domain.time("2011-06-01"), 201106.01);
    ts.put(domain.time("2011-06-02"), 201106.02);
    ts.put(domain.time("2011-06-30"), 201106.30);
    ts.put(domain.time("2011-07-01"), 201107.01);
    ts.put(domain.time("2011-07-02"), 201107.02);
    ts.put(domain.time("2011-07-03"), 201107.03);
    return ts;
  }
View Full Code Here

    return s;
  }
 
  private Series<Double> makeSeriesWithGap(String date1, String date2) throws Exception {
    UpdatableSeries<Double> s = db.getUpdatableSeries(SERIES, true);
    TimeDomain domain = s.getTimeDomain();
    s.setValue(domain.time(date1), 1d);
    s.setValue(domain.time(date2), 2d);
    s.applyUpdates();
    return s;
  }
View Full Code Here

    db.commit();
  }

  public void testCreateSeries() {
    try {
      TimeDomain dom = Day.DOMAIN;
      UpdatableSeries<Double> s = db.getUpdatableSeries(SERIES, true).typeCheck(Double.class);
      TimeAddressable<Double> ts = TimeSeriesFactory.make(dom, Double.class);
      ts.put(dom.time("2011-05-01")201105.01);
      ts.put(dom.time("2011-05-02")201105.02);
      ts.put(dom.time("2011-06-01")201106.01);
      ts.put(dom.time("2011-06-30")201106.30);
      ts.put(dom.time("2011-07-01")201107.01);
      s.setValues(ts);
      s.applyUpdates();
      assertEquals("[2011-05-01, 2011-07-01]", s.getRange().toString());
    } catch (Exception e) {
      fail(e.toString());
View Full Code Here

  private static final String SELECT_RANGE =
    "select min(date), max(date) from " + DB.VALUE_DOUBLE + " where series = ?";
  @Override
  public Range getRange(Series<Double> series) throws T2DBException {
    Range range = null;
    TimeDomain timeDomain = series.getTimeDomain();
    try {
      select_range = open(SELECT_RANGE, series, select_range);
      select_range.setInt(1, getId(series));
      ResultSet rs = select_range.executeQuery();
      if (rs.next()) {
        range = new Range(timeDomain.timeFromOffset(rs.getInt(1)), timeDomain.timeFromOffset(rs.getInt(2)));
        if (rs.wasNull())
          range = null;
      }
    } catch (Exception e) {
      throw T2DBMsg.exception(e, E.E50122, series.getName(true));
View Full Code Here

TOP

Related Classes of ch.agent.t2.time.TimeDomain

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.