]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
History data collector did not collect min/max/avg values correctly 87/1887/3
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 28 Jun 2018 13:25:55 +0000 (16:25 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sun, 1 Jul 2018 07:57:32 +0000 (07:57 +0000)
gitlab #35

Change-Id: Iabc44ba0d8fb8a0348f27df07cd4d114975c4d0d

bundles/org.simantics.history/src/org/simantics/history/impl/CollectorImpl.java

index 4f916868ecda2c4c2c4282b7e9b609c1071e37b5..d6dd6d9b33f19baf7bca38f773d99f9530508f6e 100644 (file)
@@ -811,7 +811,7 @@ public class CollectorImpl implements Collector {
                
                boolean condition = makeNewBand || (!i.hasEndTime && i.itemState.count==2); 
 
-               if(i.stream.size() > 0 && !i.itemState.ooDeadband) {
+               if(i.stream.size() > 0 ) { //!i.itemState.ooDeadband) {
 
                        /// Extend existing band
                        // Extend endTime value
@@ -820,57 +820,59 @@ public class CollectorImpl implements Collector {
                        } else {
                                i.current.setEndTime( time.getBinding(), time.getValue() );
                        }
+                       if  (i.itemState.ooDeadband) {
+                               if (isValidValue) {
+                                       // Set last value
+                                       if (i.current.hasLastValue()) {
+                                               i.current.setLastValue( value.getBinding(), value.getValue() );
+                                       }
 
-                       if (isValidValue) {
-                               // Set last value
-                               if (i.current.hasLastValue()) {
-                                       i.current.setLastValue( value.getBinding(), value.getValue() );
-                               }
+                                       // Add sum
+                                       if (i.current.hasAvg() && i.isNumeric && !isNanValue && !restep) {
+                                               double duration = (currentTime - i.itemState.firstTime);
+                                               if(duration < 1e-9) {
+                                                       i.current.setAvg( Bindings.DOUBLE, 0.0 );
+                                               } else {
+                                                       i.current.setAvg( Bindings.DOUBLE, i.itemState.sum / duration);
+                                               }
+                                       }
 
-                               // Add sum
-                               if (i.current.hasAvg() && i.isNumeric && !isNanValue && !restep) {
-                                       double duration = (currentTime - i.itemState.firstTime);
-                                       if(duration < 1e-9) {
-                                               i.current.setAvg( Bindings.DOUBLE, 0.0 );                                               
-                                       } else {
-                                               i.current.setAvg( Bindings.DOUBLE, i.itemState.sum / duration);                                         
+                                       // Update min-max
+                                       if (i.current.hasMin() && i.isNumeric && !isNanValue) {
+                                               Binding minBinding = i.current.getMinBinding();
+                                               Object prevMinValue = i.current.getMin();
+                                               Object currentValueWithMinBinding = value.getValue( minBinding );
+                                               int diff = minBinding.compare( prevMinValue, currentValueWithMinBinding );
+                                               if (diff>0) i.current.setMin( minBinding, currentValueWithMinBinding );
+                                       }
+                                       if (i.current.hasMax() && i.isNumeric && !isNanValue) {
+                                               Binding maxBinding = i.current.getMaxBinding();
+                                               Object prevMaxValue = i.current.getMax();
+                                               Object currentValueWithMaxBinding = value.getValue( maxBinding );
+                                               int diff = maxBinding.compare( prevMaxValue, currentValueWithMaxBinding );
+                                               if (diff<0) i.current.setMax( maxBinding, currentValueWithMaxBinding );
                                        }
-                               }
 
-                               // Update min-max
-                               if (i.current.hasMin() && i.isNumeric && !isNanValue) {
-                                       Binding minBinding = i.current.getMinBinding();
-                                       Object prevMinValue = i.current.getMin();
-                                       Object currentValueWithMinBinding = value.getValue( minBinding );
-                                       int diff = minBinding.compare( prevMinValue, currentValueWithMinBinding );
-                                       if (diff>0) i.current.setMin( minBinding, currentValueWithMinBinding );
-                               }                               
-                               if (i.current.hasMax() && i.isNumeric && !isNanValue) {
-                                       Binding maxBinding = i.current.getMaxBinding();
-                                       Object prevMaxValue = i.current.getMax();
-                                       Object currentValueWithMaxBinding = value.getValue( maxBinding );
-                                       int diff = maxBinding.compare( prevMaxValue, currentValueWithMaxBinding );
-                                       if (diff<0) i.current.setMax( maxBinding, currentValueWithMaxBinding );
+                                       // Update median
+                                       if (i.current.hasMedian() && i.isNumeric && !isNanValue) {
+                                               Double median = i.itemState.median.getMedian();
+                                               i.current.setMedian( Bindings.DOUBLE, median);
+                                       }
+                               } else {
+                                       i.current.setValueNull();
                                }
 
-                               // Update median
-                               if (i.current.hasMedian() && i.isNumeric && !isNanValue) {
-                                       Double median = i.itemState.median.getMedian();
-                                       i.current.setMedian( Bindings.DOUBLE, median);
-                               }                               
-                       } else {
-                               i.current.setValueNull();
-                       }
-
-                       // Add count
-                       if (i.current.hasCount()) {
-                               i.current.setCount( i.itemState.count );
+                               // Add count
+                               if (i.current.hasCount()) {
+                                       i.current.setCount( i.itemState.count );
+                               }
                        }
 
                        // Write entry to file stream
                        //              if (i.current.getTimeDouble()<0) 
                        //                      System.err.println("Error sample "+i.current.getBinding().toString(i.current.getSample()));
                        i.stream.setNoflush( i.stream.size()-1, i.binding, i.current.getSample() );                             
+                       //System.err.println(i.itemState.id + " update " + i.current.getSample());
                }
                
                if (condition) {
@@ -923,6 +925,7 @@ public class CollectorImpl implements Collector {
                        
                        // Add the band to the file stream
                        i.stream.addNoflush( i.binding, i.current.getSample() );
+                       //System.err.println(i.itemState.id + " add " + i.current.getSample());
                        
                }