Skip to content

Commit

Permalink
Basic AddTimeSeriesLog algorithm layout + minimal tests.
Browse files Browse the repository at this point in the history
Refs #9227
  • Loading branch information
martyngigg committed Mar 31, 2014
1 parent 799f89e commit 2443536
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@ set ( SRC_FILES
src/AddLogDerivative.cpp
src/AddPeak.cpp
src/AddSampleLog.cpp
src/AddTimeSeriesLog.cpp
src/AlignDetectors.cpp
src/AlphaCalc.cpp
src/AnyShapeAbsorption.cpp
Expand Down Expand Up @@ -232,6 +233,7 @@ set ( INC_FILES
inc/MantidAlgorithms/AddLogDerivative.h
inc/MantidAlgorithms/AddPeak.h
inc/MantidAlgorithms/AddSampleLog.h
inc/MantidAlgorithms/AddTimeSeriesLog.h
inc/MantidAlgorithms/AlignDetectors.h
inc/MantidAlgorithms/AlphaCalc.h
inc/MantidAlgorithms/AnyShapeAbsorption.h
Expand Down Expand Up @@ -470,6 +472,7 @@ set ( TEST_FILES
AddLogDerivativeTest.h
AddPeakTest.h
AddSampleLogTest.h
AddTimeSeriesLogTest.h
AlignDetectorsTest.h
AlphaCalcTest.h
AnyShapeAbsorptionTest.h
Expand Down
@@ -0,0 +1,48 @@
#ifndef MANTID_ALGORITHMS_ADDTIMESERIESLOG_H_
#define MANTID_ALGORITHMS_ADDTIMESERIESLOG_H_

#include "MantidAPI/Algorithm.h"

namespace Mantid
{
namespace Algorithms
{

/**
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport AddTimeSeriesLog : public API::Algorithm
{
public:
virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;

private:
virtual void initDocs();
void init();
void exec();
};

} // namespace Algorithms
} // namespace Mantid

#endif /* MANTID_ALGORITHMS_ADDTIMESERIESLOG_H_ */
81 changes: 81 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/AddTimeSeriesLog.cpp
@@ -0,0 +1,81 @@
/*WIKI*
Inserts/updates a time-series log entry on a chosen workspace. The given timestamp & value are appended to the
named log entry. If the named entry does not exist then a new log is created. A time stamp must be given in
ISO8601 format, e.g. 2010-09-14T04:20:12."
*WIKI*/
/*WIKI_USAGE*
'''Python'''
import datetime as dt
# Add an entry for the current time
log_name = "temperature"
log_value = 21.5
AddTimeSeriesLog(inOutWS, Name=log_name, Time=dt.datetime.utcnow().isoformat(), Value=log_value)
*WIKI_USAGE*/

#include "MantidAlgorithms/AddTimeSeriesLog.h"
#include "MantidKernel/MandatoryValidator.h"

namespace Mantid
{
namespace Algorithms
{

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(AddTimeSeriesLog)

//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string AddTimeSeriesLog::name() const { return "AddTimeSeriesLog"; }

/// Algorithm's version for identification. @see Algorithm::version
int AddTimeSeriesLog::version() const { return 1; }

/// Algorithm's category for identification. @see Algorithm::category
const std::string AddTimeSeriesLog::category() const { return "DataHandling\\Logs"; }

//----------------------------------------------------------------------------------------------
/// Sets documentation strings for this algorithm
void AddTimeSeriesLog::initDocs()
{
this->setWikiSummary("");
this->setOptionalMessage("");
}

//----------------------------------------------------------------------------------------------
/**
* Initialize the algorithm's properties.
*/
void AddTimeSeriesLog::init()
{
using namespace API;
using namespace Kernel;
declareProperty(new WorkspaceProperty<MatrixWorkspace>("Workspace", "", Direction::InOut),
"In/out workspace that will store the new log information");

auto nonEmptyString = boost::make_shared<MandatoryValidator<std::string>>();
declareProperty("Name", "", nonEmptyString,
"A string name for either a new time series log to be created "
"or an existing name to update", Direction::Input);
declareProperty("Time", "", nonEmptyString,
"An ISO formatted date/time string specifying the timestamp for "
"the given log value, e.g 2010-09-14T04:20:12",
Direction::Input);
auto nonEmtpyDbl = boost::make_shared<MandatoryValidator<double>>();
declareProperty("Value", EMPTY_DBL(), nonEmtpyDbl, "The value for the log at the given time",
Direction::Input);
}

//----------------------------------------------------------------------------------------------
/**
* Execute the algorithm.
*/
void AddTimeSeriesLog::exec()
{
}



} // namespace Algorithms
} // namespace Mantid
63 changes: 63 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h
@@ -0,0 +1,63 @@
#ifndef MANTID_ALGORITHMS_ADDTIMESERIESLOGTEST_H_
#define MANTID_ALGORITHMS_ADDTIMESERIESLOGTEST_H_

#include <cxxtest/TestSuite.h>
#include "MantidAlgorithms/AddTimeSeriesLog.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"

class AddTimeSeriesLogTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static AddTimeSeriesLogTest *createSuite() { return new AddTimeSeriesLogTest(); }
static void destroySuite( AddTimeSeriesLogTest *suite ) { delete suite; }

//-------------------------- Failure cases ------------------------------------
void test_empty_log_name_not_allowed()
{
Mantid::Algorithms::AddTimeSeriesLog alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());

TS_ASSERT_THROWS(alg.setPropertyValue("Name", ""), std::invalid_argument);
}

void test_empty_time_not_allowed()
{
Mantid::Algorithms::AddTimeSeriesLog alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());

TS_ASSERT_THROWS(alg.setPropertyValue("Time", ""), std::invalid_argument);
}

void test_empty_value_not_allowed()
{
Mantid::Algorithms::AddTimeSeriesLog alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());

TS_ASSERT_THROWS(alg.setPropertyValue("Value", ""), std::invalid_argument);
}

private:

void executeAlgorithm(Mantid::API::MatrixWorkspace_sptr testWS, const std::string & logName, const std::string & logTime,
const double logValue)
{
//execute algorithm
Mantid::Algorithms::AddTimeSeriesLog alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT( alg.isInitialized() )

alg.setProperty("Workspace", testWS);
alg.setPropertyValue("Name", logName);
alg.setPropertyValue("Time", logTime);
alg.setProperty("Value", logValue);
alg.setRethrows(true);
alg.execute();
}


};


#endif /* MANTID_ALGORITHMS_ADDTIMESERIESLOGTEST_H_ */

0 comments on commit 2443536

Please sign in to comment.