Package com.opengamma.master.historicaltimeseries

Examples of com.opengamma.master.historicaltimeseries.ManageableHistoricalTimeSeries$Meta


  //-------------------------------------------------------------------------
  @Test
  public void test_get_dateRangeFromStart() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    ManageableHistoricalTimeSeries test = _htsMaster.getTimeSeries(oid,
        VersionCorrection.of(_version2Instant.plusSeconds(1), _version3Instant.plusSeconds(1)),
        HistoricalTimeSeriesGetFilter.ofRange(null, LocalDate.of(2011, 1, 2)));
    assertEquals(oid, test.getUniqueId().getObjectId());
    LocalDateDoubleTimeSeries timeSeries = test.getTimeSeries();
    assertEquals(2, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 1), timeSeries.getTimeAtIndex(0));
    assertEquals(3.1d, timeSeries.getValueAtIndex(0), 0.0001d);
    assertEquals(LocalDate.of(2011, 1, 2), timeSeries.getTimeAtIndex(1));
    assertEquals(3.21d, timeSeries.getValueAtIndex(1), 0.0001d);
View Full Code Here


  }

  @Test
  public void test_get_dateRangeToEnd() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    ManageableHistoricalTimeSeries test = _htsMaster.getTimeSeries(oid,
        VersionCorrection.of(_version2Instant.plusSeconds(1), _version3Instant.plusSeconds(1)),
        HistoricalTimeSeriesGetFilter.ofRange(LocalDate.of(2011, 1, 2), null));
    assertEquals(oid, test.getUniqueId().getObjectId());
    LocalDateDoubleTimeSeries timeSeries = test.getTimeSeries();
    assertEquals(2, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 2), timeSeries.getTimeAtIndex(0));
    assertEquals(3.21d, timeSeries.getValueAtIndex(0), 0.0001d);
    assertEquals(LocalDate.of(2011, 1, 3), timeSeries.getTimeAtIndex(1));
    assertEquals(3.3d, timeSeries.getValueAtIndex(1), 0.0001d);
View Full Code Here

  }

  @Test
  public void test_get_dateRange() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    ManageableHistoricalTimeSeries test = _htsMaster.getTimeSeries(oid,
        VersionCorrection.of(_version2Instant.plusSeconds(1), _version3Instant.plusSeconds(1)),
        HistoricalTimeSeriesGetFilter.ofRange(LocalDate.of(2011, 1, 2), LocalDate.of(2011, 1, 2)));
    assertEquals(oid, test.getUniqueId().getObjectId());
    LocalDateDoubleTimeSeries timeSeries = test.getTimeSeries();
    assertEquals(1, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 2), timeSeries.getTimeAtIndex(0));
    assertEquals(3.21d, timeSeries.getValueAtIndex(0), 0.0001d);
  }
View Full Code Here

  @Test
  public void test_get_nPointsFromEarliest() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    HistoricalTimeSeriesGetFilter filter = new HistoricalTimeSeriesGetFilter();
    filter.setMaxPoints(2);
    ManageableHistoricalTimeSeries test = _htsMaster.getTimeSeries(oid,
        VersionCorrection.of(_version2Instant.plusSeconds(1), _version3Instant.plusSeconds(1)), filter);
    assertEquals(oid, test.getUniqueId().getObjectId());
    LocalDateDoubleTimeSeries timeSeries = test.getTimeSeries();
    assertEquals(2, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 1), timeSeries.getTimeAtIndex(0));
    assertEquals(3.1d, timeSeries.getValueAtIndex(0), 0.0001d);
    assertEquals(LocalDate.of(2011, 1, 2), timeSeries.getTimeAtIndex(1));
    assertEquals(3.21d, timeSeries.getValueAtIndex(1), 0.0001d);
View Full Code Here

  @Test
  public void test_get_nPointsFromLatest() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    HistoricalTimeSeriesGetFilter filter = HistoricalTimeSeriesGetFilter.ofLatestPoint();
    ManageableHistoricalTimeSeries test = _htsMaster.getTimeSeries(oid,
        VersionCorrection.of(_version2Instant.plusSeconds(1), _version3Instant.plusSeconds(1)), filter);
    assertEquals(oid, test.getUniqueId().getObjectId());
    LocalDateDoubleTimeSeries timeSeries = test.getTimeSeries();
    assertEquals(1, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 3), timeSeries.getTimeAtIndex(0));
    assertEquals(3.3d, timeSeries.getValueAtIndex(0), 0.0001d);
  }
View Full Code Here

  @Test
  public void test_get_nPointsFromLatestWithinDateRange() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    HistoricalTimeSeriesGetFilter filter = HistoricalTimeSeriesGetFilter.ofRange(null, LocalDate.of(2011, 1, 2), -1);
    ManageableHistoricalTimeSeries test = _htsMaster.getTimeSeries(oid,
        VersionCorrection.of(_version2Instant.plusSeconds(1), _version3Instant.plusSeconds(1)), filter);
    assertEquals(oid, test.getUniqueId().getObjectId());
    LocalDateDoubleTimeSeries timeSeries = test.getTimeSeries();
    assertEquals(1, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 2), timeSeries.getTimeAtIndex(0));
    assertEquals(3.21d, timeSeries.getValueAtIndex(0), 0.0001d);
  }
View Full Code Here

  @Test
  public void test_remove_101_removeOne() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    UniqueId uniqueId = _htsMaster.removeTimeSeriesDataPoints(oid, LocalDate.of(2011, 1, 2), LocalDate.of(2011, 1, 2));
   
    ManageableHistoricalTimeSeries testCorrected = _htsMaster.getTimeSeries(uniqueId);
    assertEquals(uniqueId, testCorrected.getUniqueId());
    LocalDateDoubleTimeSeries timeSeries = testCorrected.getTimeSeries();
    assertEquals(2, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 1), timeSeries.getTimeAtIndex(0));
    assertEquals(3.1d, timeSeries.getValueAtIndex(0), 0.001d);
    assertEquals(LocalDate.of(2011, 1, 3), timeSeries.getTimeAtIndex(1));
    assertEquals(3.33d, timeSeries.getValueAtIndex(1), 0.001d);
View Full Code Here

  @Test
  public void test_remove_101_removeRange() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    UniqueId uniqueId = _htsMaster.removeTimeSeriesDataPoints(oid, LocalDate.of(2010, 7, 3), LocalDate.of(2011, 1, 2));
   
    ManageableHistoricalTimeSeries testCorrected = _htsMaster.getTimeSeries(uniqueId);
    assertEquals(uniqueId, testCorrected.getUniqueId());
    LocalDateDoubleTimeSeries timeSeries = testCorrected.getTimeSeries();
    assertEquals(1, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 3), timeSeries.getTimeAtIndex(0));
    assertEquals(3.33d, timeSeries.getValueAtIndex(0), 0.001d);
  }
View Full Code Here

  @Test
  public void test_remove_101_removeRangeWithNullEnd() {
    ObjectId oid = ObjectId.of("DbHts", "DP101");
    UniqueId uniqueId = _htsMaster.removeTimeSeriesDataPoints(oid, LocalDate.of(2011, 1, 2), null);
   
    ManageableHistoricalTimeSeries testCorrected = _htsMaster.getTimeSeries(uniqueId);
    assertEquals(uniqueId, testCorrected.getUniqueId());
    LocalDateDoubleTimeSeries timeSeries = testCorrected.getTimeSeries();
    assertEquals(1, timeSeries.size());
    assertEquals(LocalDate.of(2011, 1, 1), timeSeries.getTimeAtIndex(0));
    assertEquals(3.1d, timeSeries.getValueAtIndex(0), 0.001d);
  }
View Full Code Here

    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
   
    // Get version metadata from the data-points and set up a Manageable HTS accordingly
    // While the HTS doc itself might have been deleted, the data-points can still be retrieved here
    final String sqlVersion = getElSqlBundle().getSql("SelectDataPointsVersion", args);
    ManageableHistoricalTimeSeries result = namedJdbc.query(sqlVersion, args, new ManageableHTSExtractor(oid));
    if (result == null) {
      // No data-points were found, check if the time-series doc exists or existed at some point
      final String sqlExists = getElSqlBundle().getSql("SelectExistential", args);
      result = namedJdbc.query(sqlExists, args, new ManageableHTSExtractor(oid));
      if (result != null) {
        // The time series doc exists or existed at some point, it's just that there are no data-points
        result.setTimeSeries(ImmutableLocalDateDoubleTimeSeries.EMPTY_SERIES);
        return result;
      } else {
        // The time series with the supplied id never existed
        throw new DataNotFoundException("Unable to find time-series: " + objectId);             
      }
    }

    // Set up query arguments to limit the number of points to return
    if (filter.getMaxPoints() == null) {
      // return all points (limit all)
      args.addValue("order", "ASC");
    } else if (filter.getMaxPoints() > 0) {
      // return first few points
      args.addValue("paging_fetch", filter.getMaxPoints());
      args.addValue("order", "ASC");
    } else if (filter.getMaxPoints() < 0) {
      // return last few points
      args.addValue("paging_fetch", -filter.getMaxPoints());
      args.addValue("order", "DESC");
    } else {
      // Zero datapoints requested
      result.setTimeSeries(ImmutableLocalDateDoubleTimeSeries.EMPTY_SERIES);
      return result;
    }

    // Get the actual data points and attach to the Manageable HTS
    if (filter.getLatestDate() == null || filter.getEarliestDate() == null || !filter.getLatestDate().isBefore(filter.getEarliestDate())) {
      final String sqlPoints = getElSqlBundle().getSql("SelectDataPoints", args);
      final LocalDateDoubleTimeSeries series = namedJdbc.query(sqlPoints, args, new DataPointsExtractor());
      result.setTimeSeries(series);
    } else {
      //TODO: this is a hack, most of the places that call with this condition want some kind of metadata, which it would be cheaper for us to expose specifically
      result.setTimeSeries(ImmutableLocalDateDoubleTimeSeries.EMPTY_SERIES);
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of com.opengamma.master.historicaltimeseries.ManageableHistoricalTimeSeries$Meta

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.