Package ch.agent.t2.time

Examples of ch.agent.t2.time.Day


  }
 
  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

        return 0;
    } else {
      int compareResols = getTimeDomain().getResolution().compareTo(otherTime.getTimeDomain().getResolution());
      if (compareResols == 0) {
        // convert  both to unrestricted domain
        TimeDomainDefinition def = new TimeDomainDefinition(null, getTimeDomain().getResolution(), 0L);
        TimeDomain unrestrictedDomain = TimeDomainManager.getFactory().get(def, true);
        TimeIndex converted = convertOrThrowRTE(unrestrictedDomain, this);
        TimeIndex otherConverted = convertOrThrowRTE(unrestrictedDomain, otherTime);
        return converted.compareTo(otherConverted);
      } else if (compareResols < 0) {
        // convert  both to highest resolution
        TimeDomainDefinition def = new TimeDomainDefinition(null, otherTime.getTimeDomain().getResolution(), 0L);
        TimeDomain unrestrictedDomain = TimeDomainManager.getFactory().get(def, true);
        TimeIndex converted = convertOrThrowRTE(unrestrictedDomain, this);
        return converted.compareTo(otherTime);
      } else {
        // convert  both to highest resolution
        TimeDomainDefinition def = new TimeDomainDefinition(null, getTimeDomain().getResolution(), 0L);
        TimeDomain unrestrictedDomain = TimeDomainManager.getFactory().get(def, true);
        TimeIndex otherConverted = convertOrThrowRTE(unrestrictedDomain, otherTime);
        return compareTo(otherConverted);
      }
    }
View Full Code Here

        select_first_double2.setInt(2, sid);
        rs = select_first_double2.executeQuery();
      }
      if (rs.next()) {
        TimeDomain dom = time == null ? series.getTimeDomain() : time.getTimeDomain();
        TimeIndex t = dom.timeFromOffset(rs.getInt(1));
        obs = new Observation<Double>(t, rs.getDouble(2));
      }
    } catch (Exception e) {
        throw T2DBJMsg.exception(e, J.J50123, series.getName(true), time.toString());
    } finally {
View Full Code Here

        select_last_double2.setInt(2, sid);
        rs = select_last_double2.executeQuery();
      }
      if (rs.next()) {
        TimeDomain dom = time == null ? series.getTimeDomain() : time.getTimeDomain();
        TimeIndex t = dom.timeFromOffset(rs.getInt(1));
        obs = new Observation<Double>(t, rs.getDouble(2));
      }
    } catch (Exception e) {
        throw T2DBJMsg.exception(e, J.J50124, series.getName(true), time.toString());
    } finally {
View Full Code Here

   * @param domain a non-null time domain
   * @return the current time
   */
  public static TimeIndex now(TimeDomain domain) {
    try {
      TimeIndex t = new SystemTime();
      return t.convert(domain, Adjustment.DOWN);
    } catch (T2Exception e) {
      // should not occur because of the adjustment
      throw new RuntimeException(e);
    }
  }
View Full Code Here

TOP

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

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.