use of eu.fthevenet.binjr.data.workspace.TimeSeriesInfo in project selenium_java by sergueik.
the class CsvDecoder method decode.
@Override
public Map<TimeSeriesInfo<T>, TimeSeriesProcessor<T>> decode(InputStream in, List<TimeSeriesInfo<T>> seriesInfo) throws IOException, DecodingDataFromAdapterException {
try (Profiler ignored = Profiler.start("Building time series from csv data", logger::trace)) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, encoding))) {
CSVFormat csvFormat = CSVFormat.DEFAULT.withAllowMissingColumnNames(false).withFirstRecordAsHeader().withSkipHeaderRecord().withDelimiter(delimiter);
Iterable<CSVRecord> records = csvFormat.parse(reader);
Map<TimeSeriesInfo<T>, TimeSeriesProcessor<T>> series = new HashMap<>();
final AtomicLong nbpoints = new AtomicLong(0);
for (CSVRecord csvRecord : records) {
nbpoints.incrementAndGet();
ZonedDateTime timeStamp = dateParser.apply(csvRecord.get(0));
for (TimeSeriesInfo<T> info : seriesInfo) {
T val = numberParser.apply(csvRecord.get(info.getBinding().getLabel()));
XYChart.Data<ZonedDateTime, T> point = new XYChart.Data<>(timeStamp, val);
TimeSeriesProcessor<T> l = series.computeIfAbsent(info, k -> timeSeriesFactory.create());
l.addSample(point);
}
}
logger.trace(() -> String.format("Built %d series with %d samples each (%d total samples)", seriesInfo.size(), nbpoints.get(), seriesInfo.size() * nbpoints.get()));
return series;
}
}
}
use of eu.fthevenet.binjr.data.workspace.TimeSeriesInfo in project selenium_java by sergueik.
the class CsvFileAdapter method fetchDecodedData.
@Override
public Map<TimeSeriesInfo<Double>, TimeSeriesProcessor<Double>> fetchDecodedData(String path, Instant begin, Instant end, List<TimeSeriesInfo<Double>> seriesInfo, boolean bypassCache) throws DataAdapterException {
if (this.isClosed()) {
throw new IllegalStateException("An attempt was made to fetch data from a closed adapter");
}
Map<TimeSeriesInfo<Double>, TimeSeriesProcessor<Double>> series = new HashMap<>();
Map<String, TimeSeriesInfo<Double>> rDict = new HashMap<>();
for (TimeSeriesInfo<Double> info : seriesInfo) {
rDict.put(info.getBinding().getLabel(), info);
series.put(info, new DoubleTimeSeriesProcessor());
}
for (DataSample<Double> sample : getDataStore().subMap(begin.getEpochSecond(), end.getEpochSecond()).values()) {
for (String n : sample.getCells().keySet()) {
TimeSeriesInfo<Double> i = rDict.get(n);
if (i != null) {
series.get(i).addSample(new XYChart.Data<>(sample.getTimeStamp(), sample.getCells().get(n)));
}
}
}
return series;
}
Aggregations