@Override
protected void doRun() {
if (!(getToolContext().getHistoricalTimeSeriesSource() instanceof RedisSimulationSeriesSource)) {
throw new OpenGammaRuntimeException("HistoricalTimeSeriesSource from conrtext is not a RedisSimulationSeriesSource, got " + getToolContext().getHistoricalTimeSeriesSource() + ": note this tool must be run with a toolcontext config file not via -c http://localhost");
}
final RedisSimulationSeriesSource source = (RedisSimulationSeriesSource) getToolContext().getHistoricalTimeSeriesSource();
String fileName = getCommandLine().getOptionValue(FILE_NAME_OPT);
SheetFormat sheetFormat = SheetFormat.of(fileName);
// most of these fields are dropped in redis - used here to allow us to use existing machinery
String dataSource = getCommandLine().getOptionValue(TIME_SERIES_DATASOURCE_OPT);
String dataProvider = getCommandLine().getOptionValue(TIME_SERIES_DATAPROVIDER_OPT);
String dataField = getCommandLine().getOptionValue(TIME_SERIES_DATAFIELD_OPT);
String observationTime = getCommandLine().getOptionValue(TIME_SERIES_OBSERVATIONTIME_OPT);
String idScheme = getCommandLine().getOptionValue(TIME_SERIES_IDSCHEME_OPT);
String dateFormat = getCommandLine().getOptionValue(TIME_SERIES_DATEFORMAT_OPT);
boolean write = getCommandLine().hasOption(WRITE_OPT);
try {
InputStream portfolioFileStream = new BufferedInputStream(new FileInputStream(fileName));
TimeSeriesReader timeSeriesReader = new SingleSheetMultiTimeSeriesReader(sheetFormat,
portfolioFileStream,
dataSource,
dataProvider,
dataField,
observationTime,
idScheme,
dateFormat);
timeSeriesReader.writeTo(new TimeSeriesWriter() {
@Override
public LocalDateDoubleTimeSeries writeDataPoints(ExternalId htsId,
String dataSource,
String dataProvider,
String dataField,
String observationTime,
LocalDateDoubleTimeSeries series) {
final LocalDateDoubleEntryIterator iterator = series.iterator();
while (iterator.hasNext()) {
final Map.Entry<LocalDate, Double> entry = iterator.next();
final UniqueId id = UniqueId.of(htsId.getScheme().getName(), htsId.getValue());
source.updateTimeSeriesPoint(id, source.getCurrentSimulationExecutionDate(), entry.getKey(), entry.getValue());
}
return series;
}
@Override