Bug 135090 - Add a [Vector-First] automatic scalar
Summary: Add a [Vector-First] automatic scalar
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Solaris
: NOR wishlist
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-04 15:31 UTC by Nicolas Brisset
Modified: 2006-11-27 10:21 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Proposed patch (2.21 KB, patch)
2006-10-04 16:07 UTC, Nicolas Brisset
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Brisset 2006-10-04 15:31:58 UTC
Version:           1.3.0 (using KDE 3.4.0, compiled sources)
Compiler:          gcc version 3.4.3
OS:                SunOS (sun4u) release 5.8

As there is a [Vector-Last] scalar created for each loaded vector, a [Vector-First] scalar containing the first value would be handy.

On a side note, what does the -MinPos scalar represent ? Is is supposed to be the index corresponding to the minimum value ? And why is there no MaxPos ?
Comment 1 Nicolas Brisset 2006-10-04 16:07:52 UTC
Created attachment 18009 [details]
Proposed patch

Since the request is very similar to bug #88120, I developed something very
similar. It seems to work fine, I'll leave it to you to apply after review,
though.

Note: I'm not sure I understand the purpose of the first
_scalars["first"]->setValue(first); 
line after the loop that checks whether there are NaNs in the vector.. Maybe
the line I added there is not appropriate...
Comment 2 Nicolas Brisset 2006-10-04 16:13:41 UTC
By the way, MinPos is the smallest positive value. There may be other useful values we could add ? I'm thinking particularly about:
- index of the min (to e.g. create a label containing the time at which the minimum occurs, provided that time is the X vector and has the same length)
- index of the max
Comment 3 George Staikos 2006-10-04 16:18:15 UTC
On Wednesday 04 October 2006 10:07, Nicolas Brisset wrote:

> Since the request is very similar to bug #88120, I developed something very
> similar. It seems to work fine, I'll leave it to you to apply after review,
> though.


  Looks fine, feel free to commit to trunk if you like.

> Note: I'm not sure I understand the purpose of the first
> _scalars["first"]->setValue(first);
> line after the loop that checks whether there are NaNs in the vector..
> Maybe the line I added there is not appropriate...


  It's a short-circuit to exit the update early.  Notice that it returns if it 
goes there.
Comment 4 Nicolas Brisset 2006-10-04 16:25:15 UTC
OK, I'll commit to trunk. I suppose you'll backport it to the 1.3 branch ?
Regarding the MinIndex and MaxIndex scalars, are there opinions as to whether we should also add them ?
Comment 5 Nicolas Brisset 2006-10-04 16:42:45 UTC
SVN commit 592357 by brisset:

Add a -First scalar when loading vectors, with the first value of the vector.
I think it would be useful to also add -MinIndex and -MaxIndex scalars, so I'll leave the bug open.
I have just one question: what happens to these scalars when vectors are interpolated ?

CCBUG: 135090



 M  +8 -2      kstvector.cpp  


--- trunk/extragear/graphics/kst/src/libkst/kstvector.cpp #592356:592357
@@ -250,6 +250,8 @@
     sp->_KShared_ref();
     _scalars.insert("last", sp = new KstScalar(tagName() + "-Last", this));
     sp->_KShared_ref();
+    _scalars.insert("first", sp = new KstScalar(tagName() + "-First", this));
+    sp->_KShared_ref();
     _scalars.insert("mean", sp = new KstScalar(tagName() + "-Mean", this));
     sp->_KShared_ref();
     _scalars.insert("sigma", sp = new KstScalar(tagName() + "-Sigma", this));
@@ -272,6 +274,7 @@
     _scalars["max"]->setTagName(tagName() + "-Max");
     _scalars["min"]->setTagName(tagName() + "-Min");
     _scalars["last"]->setTagName(tagName() + "-Last");
+    _scalars["first"]->setTagName(tagName() + "-First");
     _scalars["mean"]->setTagName(tagName() + "-Mean");
     _scalars["sigma"]->setTagName(tagName() + "-Sigma");
     _scalars["rms"]->setTagName(tagName() + "-Rms");
@@ -375,11 +378,11 @@
 
 KstObject::UpdateType KstVector::internalUpdate(KstObject::UpdateType providerRC) {
   int i, i0;
-  double sum, sum2, last, v;
+  double sum, sum2, last, first, v;
   double last_v;
   double dv2 = 0.0, dv, no_spike_max_dv;
   
-  _max = _min = sum = sum2 = _minPos = last = KST::NOPOINT;
+  _max = _min = sum = sum2 = _minPos = last = first = KST::NOPOINT;
   _nsum = 0;
   
   if (_size > 0) {
@@ -398,6 +401,7 @@
         _scalars["min"]->setValue(_min);
         _scalars["minpos"]->setValue(_minPos);
         _scalars["last"]->setValue(last);
+        _scalars["first"]->setValue(first);
       }
       _ns_max = _ns_min = 0;
 
@@ -460,6 +464,7 @@
     _ns_max = _ns_min = last_v = _v[i0];
 
     last = _v[_size-1];
+    first = _v[0];
 
     for (i = i0; i < _size; i++) {
       v = _v[i]; // get rid of redirections
@@ -490,6 +495,7 @@
       _scalars["min"]->setValue(_min);
       _scalars["minpos"]->setValue(_minPos);
       _scalars["last"]->setValue(last);
+      _scalars["first"]->setValue(first);
     }
 
     updateScalars();
Comment 6 George Staikos 2006-10-04 17:13:13 UTC
No new features in 1.3.1.  It will have to wait for 1.4.
Comment 7 Nicolas Brisset 2006-10-04 18:01:15 UTC
Looking at the code again, I notice there is a updateScalars method that seems to update some scalar values, e.g. when a vector is blanked or zeroed. It is not clear to me why other scalars are not updated like for instance -Last, and certainly others ?
Comment 8 Nicolas Brisset 2006-10-04 18:12:26 UTC
Thinking about the use cases for MinIndex and MaxIndex, I realize this is linked with indexed access into vectors (as discussed on the list in July 2005)? Have we eventually gone as far as adding that to the parser ?
The idea would be to be able to generate a label like "Min temperature: [Temperature-Min] obtained at @Time[Temperature-MinIndex]"
If indexed access into vectors hs been forgotten, I think we should create a new bugzilla entry for it...
Comment 9 George Staikos 2006-10-04 18:37:29 UTC
  If you think it is a bug, please test and report it here and we can fix it 
(and backport those fixes).
Comment 10 Netterfield 2006-11-25 03:59:46 UTC
The fix for this was committed by Nicholas in October.
Comment 11 Nicolas Brisset 2006-11-27 10:21:30 UTC
Right, but the first reason I left this open is that I had doubts that all scalars get updated correctly. Looking at the code, it was not obvious as some are handled in internalUpdate() and others in updateScalars(). But I have just had a (quick) look again and it seems to be OK. As far as I remember (non-exhaustive) testing also showed normal results. 
The second reason was that we could easily add other scalars (see comment #8) that will be very useful as soon as we have indexed access into vectors from labels. I was also wondering if we could benefit performance wise in the drawing code from these scalars ? In any case, the best would probably be to open a separate report for those new scalars. That's what I'll do...