Package ch.agent.t2.time

Examples of ch.agent.t2.time.TimeIndex


  public AccessMethodsForNumber() {
  }

  @Override
  public Range getRange(Series<Double> series) throws T2DBException {
    Range range = null;
    try {
      check(Permission.READ, series);
      Surrogate s = series.getSurrogate();
      BasicDBObject obj = (BasicDBObject) getObject(s, false);
      if (obj != null) {
        long first = obj.getLong(MongoDatabase.FLD_SER_FIRST);
        long last = obj.getLong(MongoDatabase.FLD_SER_LAST);
        range = new Range(series.getTimeDomain(), first, last);
      }
    } catch (Exception e) {
      throw T2DBMsg.exception(e, E.E50122, series.getName(true));
    }
    if (range == null)
      range = new Range(series.getTimeDomain());
    return range;
  }
View Full Code Here


    return count;
  }
 
  private <T>void update(Series<T> series, TimeAddressable<Double> values) throws T2DBException {
    com.mongodb.DBObject operation = null;
    Range range = values.getRange();
    Map<String, Double> data = new HashMap<String, Double>();
    for (Observation<Double> obs : values) {
      data.put(Long.toString(obs.getIndex()), obs.getValue());
    }
    operation = operation(Operator.SET,
        MongoDatabase.FLD_SER_FIRST, range.getFirstIndex(),
        MongoDatabase.FLD_SER_LAST, range.getLastIndex(),
        MongoDatabase.FLD_SER_VALUES, data);
   
    Surrogate s = series.getSurrogate();
    getMongoDB(s).getSeries().update(asQuery(s.getId()), operation);
  }
View Full Code Here

      if (DUMP)
        System.out.println(t.getTimeDomain() + " " + s.getRange());
      assertEquals(9, s.getRange().getSize());
      if (DUMP)
        System.out.println(s.getValues(null));
      boolean done = s.setRange(new Range(t.getTimeDomain(), "2011-03-12", "2011-03-17", Adjustment.NONE));
      if (DUMP)
        System.out.println(s.getValues(null));
      assertFalse(done);
      done = s.setRange(new Range(t.getTimeDomain(), "2011-03-12", "2011-03-16", Adjustment.NONE));
      s.applyUpdates();
      if (DUMP)
        System.out.println(s.getValues(null));
      assertEquals(3, s.getRange().getSize());
      done = s.setRange(null);
View Full Code Here

  }

  public void testEmptyRange() {
    try {
      UpdatableSeries<Double> s = db.getUpdatableSeries(SERIES, true);
      assertEquals(new Range(s.getTimeDomain()), s.getRange());
    } catch (Exception e) {
      fail(e.toString());
    }
  }
View Full Code Here

    }
    if (basePeriodPattern != null)
      time = basePeriodPattern.expandIndex(time);
   
    TimeParts tp = new TimeParts();
    Resolution unit = this.baseUnit;
    switch (unit) {
    case YEAR:
      tp.setYear(time);
      break;
    case MONTH:
      tp.setYear(time / 12);
      tp.setMonth((int) (time - tp.getYear() * 12) + 1);
      break;
    case DAY:
      TimeTools.computeYMD(time, tp);
      break;
    case HOUR:
      long days = time / 24;
      tp.setHour((int) (time - days * 24));
      TimeTools.computeYMD(days, tp);
      break;
    case MIN:
      days = time/ (24 * 60);
      long minutes = time - days * 24 * 60;
      tp.setHour((int)(minutes / 60));
      tp.setMin((int) (minutes - tp.getHour() * 60));
      TimeTools.computeYMD(days, tp);
      break;
    case SEC:
      days = time / (24 * 60 * 60);
      long seconds = time - days * 24L * 60L * 60L;
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    case MSEC:
      days = time / (24L * 60L * 60L * 1000L);
      long millis = time - days * 24L * 60L * 60L * 1000L;
      seconds = millis / 1000L;
      tp.setUsec((int) (millis - seconds * 1000L) * 1000);
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    case USEC:
      days = time / (24L * 60L * 60L * 1000000L);
      long micros = time - days * 24L * 60L * 60L * 1000000L;
      seconds = micros / 1000000L;
      tp.setUsec((int) (micros - seconds * 1000000L));
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    default:
      throw new RuntimeException("bug: " + unit.name());
    }
   
    if (subPeriodPattern != null) {
      // there is something to do even when subPeriod = 0
      subPeriodPattern.fillInSubPeriod(subPeriod, tp);
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

    long index = m.asLong() * 24L * 3600000L;
    return index = index - epoch;
  }
 
  private static long dayOrLessToMillisecSinceEpoch (TimeIndex t) throws T2Exception {
    long index = new SystemTime(t.toString()).asLong();
    return index - epoch;
  }
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 T2DBJMsg.exception(e, J.J50122, series.getName(true));
View Full Code Here

        select_first_double2.setInt(1, sid);
        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(1, sid);
        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

TOP

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

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.