Skip to content

Commit

Permalink
Remove duplicate log times before calling meanTime()
Browse files Browse the repository at this point in the history
Not sure this is the best thing to do, ideally meanTime()
should be able to cope itself.

refs #6760
  • Loading branch information
stuartcampbell committed Mar 22, 2013
1 parent 84b8030 commit 8024211
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace Mantid

if ( m_extractSingleValueAs.compare("mean" ) == 0 )
{
logData->eliminateDuplicates();
extractedValue = timeMean(logData);
}
else if(bUsingStandardStatistics)
Expand Down
21 changes: 11 additions & 10 deletions Code/Mantid/Framework/Kernel/src/LogParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ namespace Mantid
}

/**
Create a log vale for the current period.
@param period: The period number to create the log entry for.
* Create a log vale for the current period.
* @param period: The period number to create the log entry for.
*/
Kernel::Property* LogParser::createCurrentPeriodLog(const int& period) const
{
Expand All @@ -346,28 +346,28 @@ namespace Mantid
}


/** Returns the time-weigthed mean value if the property is TimeSeriesProperty<double>.
/**
* Returns the time-weighted mean value if the property is TimeSeriesProperty<double>.
*
* TODO: Make this more efficient.
*
@param p :: Property with the data. Will throw if not TimeSeriesProperty<double>.
@return The mean value over time.
@throw runtime_error if the property is not TimeSeriesProperty<double>
* @param p :: Property with the data. Will throw if not TimeSeriesProperty<double>.
* @return The mean value over time.
* @throw runtime_error if the property is not TimeSeriesProperty<double>
*/
double timeMean(const Kernel::Property* p)
{
const Kernel::TimeSeriesProperty<double>* dp = dynamic_cast<const Kernel::TimeSeriesProperty<double>*>(p);
Kernel::TimeSeriesProperty<double>* dp = dynamic_cast<Kernel::TimeSeriesProperty<double>*>(p);
if (!dp)
{
throw std::runtime_error("Property of a wrong type.");
throw std::runtime_error("Property of a wrong type. Cannot be cast to a TimeSeriesProperty<double>.");
}

//Special case for only one value - the algorithm
// Special case for only one value - the algorithm
if (dp->size() == 1)
{
return dp->nthValue(1);
}

double res = 0.;
Kernel::time_duration total(0,0,0,0);

Expand All @@ -381,6 +381,7 @@ namespace Mantid
}

double total_seconds = Kernel::DateAndTime::secondsFromDuration(total);

if (total_seconds > 0) res /= total_seconds;

return res;
Expand Down

0 comments on commit 8024211

Please sign in to comment.