From fbe4ffbf25e0b35dcbd51f11b50e740bfe4c593d Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Mon, 20 Mar 2017 08:43:29 +0200 Subject: [PATCH] History sampling improvements refs #7028 Change-Id: Ia4653ee76859dae1842bdef82fe552ca70f61995 --- .../src/org/simantics/charts/Charts.java | 6 +++--- .../src/org/simantics/charts/TrendSupport.java | 11 ++++++++++- .../src/org/simantics/history/HistorySampler.java | 13 +++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/Charts.java b/bundles/org.simantics.charts/src/org/simantics/charts/Charts.java index 1358c4023..5e4ef406d 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/Charts.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/Charts.java @@ -48,9 +48,9 @@ public final class Charts { public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Resource subscriptionItem, ChartData data) throws DatabaseException { try { - Resource model = graph.syncRequest(new PossibleIndexRoot(subscriptionItem)); - if (model == null) { - throw new DatabaseException("There is no model for " + subscriptionItem); + Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(subscriptionItem)); + if (indexRoot == null) { + throw new DatabaseException("There is no index root for " + subscriptionItem); } ItemManager im = new ItemManager(data.history.getItems()); diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/TrendSupport.java b/bundles/org.simantics.charts/src/org/simantics/charts/TrendSupport.java index a396d10da..aeae9f5d3 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/TrendSupport.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/TrendSupport.java @@ -41,7 +41,7 @@ import org.simantics.utils.FileUtils; * * @author Tuukka Lehtonen */ -public class TrendSupport { +public class TrendSupport implements ITrendSupport { // Input private IDynamicExperiment experiment; @@ -170,4 +170,13 @@ public class TrendSupport { return finalPath.toFile(); } + @Override + public void setChartData(ReadGraph graph) throws DatabaseException { + } + + @Override + public ChartData getChartData() { + return chartData; + } + } diff --git a/bundles/org.simantics.history/src/org/simantics/history/HistorySampler.java b/bundles/org.simantics.history/src/org/simantics/history/HistorySampler.java index 73df6dc61..1c45a220f 100644 --- a/bundles/org.simantics.history/src/org/simantics/history/HistorySampler.java +++ b/bundles/org.simantics.history/src/org/simantics/history/HistorySampler.java @@ -15,9 +15,10 @@ public class HistorySampler { public synchronized static TDoubleArrayList sample( HistorySamplerItem item, double from, double end, double timeWindow, double timeStep, boolean resample ) throws HistoryException, IOException { try { - item.open(); + // If there is something pending at this point, flush before opening for read if(item.collector != null) item.collector.flush(); + item.open(); return sample(item.iter, from, end, timeWindow, timeStep, resample); } finally { item.close(); @@ -25,10 +26,18 @@ public class HistorySampler { } public static TDoubleArrayList sample( StreamIterator iter, double from, double end, double timeWindow, double timeStep, boolean resample ) throws HistoryException, IOException { + return sample(iter, from, end, timeWindow, timeStep, resample, 0.0); + } + + public static TDoubleArrayList sample( StreamIterator iter, double from, double end, double timeWindow, double timeStep, boolean resample, Double sampleFrom ) throws HistoryException, IOException { ExportInterpolation numberInterpolation = ExportInterpolation.LINEAR_INTERPOLATION; - double startTime = 0.0; + double startTime = from; + if(sampleFrom != null) { + // This option can be used do define the offset of sampling. Samples will be sampleFrom + n * timeStep + startTime = sampleFrom; + } TDoubleArrayList result = new TDoubleArrayList(); -- 2.43.2