diff --git a/Code/Mantid/Framework/Algorithms/CMakeLists.txt b/Code/Mantid/Framework/Algorithms/CMakeLists.txt index 174eb258a49f..0d4999da78e3 100644 --- a/Code/Mantid/Framework/Algorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/Algorithms/CMakeLists.txt @@ -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 @@ -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 @@ -470,6 +472,7 @@ set ( TEST_FILES AddLogDerivativeTest.h AddPeakTest.h AddSampleLogTest.h + AddTimeSeriesLogTest.h AlignDetectorsTest.h AlphaCalcTest.h AnyShapeAbsorptionTest.h diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AddTimeSeriesLog.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AddTimeSeriesLog.h new file mode 100644 index 000000000000..e602fd049ded --- /dev/null +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AddTimeSeriesLog.h @@ -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 . + + File change history is stored at: + Code Documentation is available at: + */ + 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_ */ diff --git a/Code/Mantid/Framework/Algorithms/src/AddTimeSeriesLog.cpp b/Code/Mantid/Framework/Algorithms/src/AddTimeSeriesLog.cpp new file mode 100644 index 000000000000..5643c304d580 --- /dev/null +++ b/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("Workspace", "", Direction::InOut), + "In/out workspace that will store the new log information"); + + auto nonEmptyString = boost::make_shared>(); + 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>(); + 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 diff --git a/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h b/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h new file mode 100644 index 000000000000..8ff4ff6b9134 --- /dev/null +++ b/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h @@ -0,0 +1,63 @@ +#ifndef MANTID_ALGORITHMS_ADDTIMESERIESLOGTEST_H_ +#define MANTID_ALGORITHMS_ADDTIMESERIESLOGTEST_H_ + +#include +#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_ */