Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic AddTimeSeriesLog algorithm layout + minimal tests.
Refs #9227
- Loading branch information
1 parent
799f89e
commit 2443536
Showing
4 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AddTimeSeriesLog.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
63
Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ */ |