From 53c2b2531c7cb0933a0a6e239ef2e195f99cd4c9 Mon Sep 17 00:00:00 2001 From: terrypacker Date: Tue, 23 Jul 2019 09:47:37 -1000 Subject: [PATCH] Ensure order of iteration is consistent to ensure csv data is in order --- ...efaultRollupStatisticsQuantizerStream.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Mango API/src/com/infiniteautomation/mango/rest/v2/model/pointValue/quantize/MultiDataPointDefaultRollupStatisticsQuantizerStream.java b/Mango API/src/com/infiniteautomation/mango/rest/v2/model/pointValue/quantize/MultiDataPointDefaultRollupStatisticsQuantizerStream.java index 87c431f2c..6267a62bc 100644 --- a/Mango API/src/com/infiniteautomation/mango/rest/v2/model/pointValue/quantize/MultiDataPointDefaultRollupStatisticsQuantizerStream.java +++ b/Mango API/src/com/infiniteautomation/mango/rest/v2/model/pointValue/quantize/MultiDataPointDefaultRollupStatisticsQuantizerStream.java @@ -7,9 +7,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import com.goebl.simplify.SimplifyUtility; import com.infiniteautomation.mango.rest.v2.model.pointValue.DataPointVOPointValueTimeBookend; @@ -69,9 +70,11 @@ public void streamData(PointValueTimeWriter writer) throws IOException { if(singleArray) { //Combine into single array List values = new ArrayList<>(); - for(Entry> entry : processed.entrySet()) { - values.addAll(entry.getValue()); + Iterator it = processed.keySet().iterator(); + while(it.hasNext()) { + values.addAll(processed.get(it.next())); } + //Sort by time Collections.sort(values); //Limit entire list @@ -100,10 +103,13 @@ public void streamData(PointValueTimeWriter writer) throws IOException { writer.writeDataPointValues(currentValues, currentValues.get(0).getTime()); } }else { - for(Entry> entry : processed.entrySet()) { + Iterator it = processed.keySet().iterator(); + while(it.hasNext()) { + DataPointVO key = it.next(); + List values = processed.get(key); if(!info.isSingleArray()) - this.writer.writeStartArray(entry.getKey().getXid()); - for(DataPointValueTime value : entry.getValue()) { + this.writer.writeStartArray(key.getXid()); + for(DataPointValueTime value : values) { writer.writeDataPointValue(value); count++; } @@ -119,7 +125,7 @@ public void streamData(PointValueTimeWriter writer) throws IOException { * @return */ private Map> process(Integer limit) { - Map> processed = new HashMap<>(); + Map> processed = new LinkedHashMap<>(); for(DataPointVO vo : voMap.values()) { List generators = valueMap.get(vo.getId()); List values = new ArrayList<>();