Skip to content

Commit

Permalink
Re #6152. Fix if-else construct that was identical on either branch.
Browse files Browse the repository at this point in the history
There's also a slight change in behaviour. If a 'good' region contains
more than one log value, and log values are considered to represent the
left of a bin, then the end time will be the point it went 'bad'
(previously it was the time of the last good value + a tolerance).
  • Loading branch information
RussellTaylor committed Nov 21, 2012
1 parent b29c608 commit dd2b10f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace Mantid
/// Split out a time series property by time intervals.
void splitByTime(TimeSplitterType& splitter, std::vector< Property * > outputs) const;
/// Fill a TimeSplitterType that will filter the events by matching
void makeFilterByValue(TimeSplitterType& split, TYPE min, TYPE max, double TimeTolerance, bool centre=true);
void makeFilterByValue(TimeSplitterType& split, TYPE min, TYPE max, double TimeTolerance, bool centre=true) const;

/// Return the time series as a correct C++ map<DateAndTime, TYPE>. All values
std::map<DateAndTime, TYPE> valueAsCorrectMap() const;
Expand Down
32 changes: 16 additions & 16 deletions Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,32 +448,33 @@ namespace Mantid
* @param centre :: Whether the log value time is considered centred or at the beginning.
*/
template<typename TYPE>
void TimeSeriesProperty<TYPE>::makeFilterByValue(TimeSplitterType& split, TYPE min, TYPE max, double TimeTolerance, bool centre)
void TimeSeriesProperty<TYPE>::makeFilterByValue(TimeSplitterType& split, TYPE min, TYPE max, double TimeTolerance, bool centre) const
{
// Make sure the splitter starts out empty
split.clear();

//Do nothing if the log is empty.
if (m_values.size() == 0)
return;
if ( m_values.empty() ) return;

// 1. Sort
sort();

// 2. Do the rest
bool lastGood = false;
bool isGood;
bool lastGood(false);
time_duration tol = DateAndTime::durationFromSeconds( TimeTolerance );
int numgood = 0;
DateAndTime lastTime, t;
DateAndTime t;
DateAndTime start, stop;

for (size_t i = 0; i < m_values.size(); i ++)
for (size_t i = 0; i < m_values.size(); ++i)
{
lastTime = t;
const DateAndTime lastTime = t;
//The new entry
t =m_values[i].time();
TYPE val = m_values[i].value();

//A good value?
isGood = ((val >= min) && (val < max));
const bool isGood = ((val >= min) && (val < max));
if (isGood)
numgood++;

Expand All @@ -492,18 +493,18 @@ namespace Mantid
else
{
//End of the good section
if (numgood == 1)
if (numgood == 1 || centre )
{
//There was only one point with the value. Use the last time, + the tolerance, as the end time
// If there was only one point with the value, or values represent bin centres,
// use the last good time, + the tolerance, as the end time
stop = lastTime + tol;
split.push_back( SplittingInterval(start, stop, 0) );
}
else
{
//At least 2 good values. Save the end time
stop = lastTime + tol;
split.push_back( SplittingInterval(start, stop, 0) );
// At least 2 good values for left boundary aligned logs. Save the end time.
stop = t;
}
split.push_back( SplittingInterval(start, stop, 0) );
//Reset the number of good ones, for next time
numgood = 0;
}
Expand All @@ -516,7 +517,6 @@ namespace Mantid
//The log ended on "good" so we need to close it using the last time we found
stop = t + tol;
split.push_back( SplittingInterval(start, stop, 0) );
numgood = 0;
}

return;
Expand Down
19 changes: 19 additions & 0 deletions Code/Mantid/Framework/Kernel/test/TimeSeriesPropertyTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite

TS_ASSERT_EQUALS( log->realSize(), 6);

// Test centred log value boundaries
TimeSplitterType splitter;
log->makeFilterByValue(splitter, 1.8, 2.2, 1.0);

Expand All @@ -363,6 +364,24 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite
t = DateAndTime("2007-11-30T16:17:41");
TS_ASSERT_DELTA( s.stop(), t, 1e-3);


// Now test with left-aligned log value boundaries
log->makeFilterByValue(splitter, 1.8, 2.2, 1.0, false);

TS_ASSERT_EQUALS( splitter.size(), 2);

s = splitter[0];
t = DateAndTime("2007-11-30T16:17:10");
TS_ASSERT_DELTA( s.start(), t, 1e-3);
t = DateAndTime("2007-11-30T16:17:11");
TS_ASSERT_DELTA( s.stop(), t, 1e-3);

s = splitter[1];
t = DateAndTime("2007-11-30T16:17:30");
TS_ASSERT_DELTA( s.start(), t, 1e-3);
t = DateAndTime("2007-11-30T16:17:50");
TS_ASSERT_DELTA( s.stop(), t, 1e-3);

delete log;
}

Expand Down

0 comments on commit dd2b10f

Please sign in to comment.