Search in sources :

Example 1 with TimeSeriesProcessor

use of eu.fthevenet.binjr.data.timeseries.TimeSeriesProcessor 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;
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) TimeSeriesInfo(eu.fthevenet.binjr.data.workspace.TimeSeriesInfo) HashMap(java.util.HashMap) TimeSeriesProcessor(eu.fthevenet.binjr.data.timeseries.TimeSeriesProcessor) AtomicLong(java.util.concurrent.atomic.AtomicLong) Profiler(eu.fthevenet.util.logging.Profiler) ZonedDateTime(java.time.ZonedDateTime) BufferedReader(java.io.BufferedReader) XYChart(javafx.scene.chart.XYChart) CSVFormat(org.apache.commons.csv.CSVFormat) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 2 with TimeSeriesProcessor

use of eu.fthevenet.binjr.data.timeseries.TimeSeriesProcessor 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;
}
Also used : TimeSeriesInfo(eu.fthevenet.binjr.data.workspace.TimeSeriesInfo) HashMap(java.util.HashMap) TimeSeriesProcessor(eu.fthevenet.binjr.data.timeseries.TimeSeriesProcessor) DoubleTimeSeriesProcessor(eu.fthevenet.binjr.data.timeseries.DoubleTimeSeriesProcessor) XYChart(javafx.scene.chart.XYChart) DoubleTimeSeriesProcessor(eu.fthevenet.binjr.data.timeseries.DoubleTimeSeriesProcessor)

Aggregations

TimeSeriesProcessor (eu.fthevenet.binjr.data.timeseries.TimeSeriesProcessor)2 TimeSeriesInfo (eu.fthevenet.binjr.data.workspace.TimeSeriesInfo)2 HashMap (java.util.HashMap)2 XYChart (javafx.scene.chart.XYChart)2 DoubleTimeSeriesProcessor (eu.fthevenet.binjr.data.timeseries.DoubleTimeSeriesProcessor)1 Profiler (eu.fthevenet.util.logging.Profiler)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ZonedDateTime (java.time.ZonedDateTime)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 CSVFormat (org.apache.commons.csv.CSVFormat)1 CSVRecord (org.apache.commons.csv.CSVRecord)1