| Summary: | Add a [Vector-First] automatic scalar | ||
|---|---|---|---|
| Product: | [Applications] kst | Reporter: | Nicolas Brisset <nicolas.brisset> |
| Component: | general | Assignee: | kst |
| Status: | RESOLVED FIXED | ||
| Severity: | wishlist | ||
| Priority: | NOR | ||
| Version First Reported In: | 1.x | ||
| Target Milestone: | --- | ||
| Platform: | unspecified | ||
| OS: | Solaris | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | Proposed patch | ||
|
Description
Nicolas Brisset
2006-10-04 15:31:58 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... 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 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. 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 ? 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();
No new features in 1.3.1. It will have to wait for 1.4. 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 ? 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... If you think it is a bug, please test and report it here and we can fix it (and backport those fixes). The fix for this was committed by Nicholas in October. 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... |