21#include <boost/algorithm/string/classification.hpp>
22#include <boost/range/algorithm/remove_if.hpp>
23#include <boost/utility.hpp>
39 bool appendTimestamp, std::vector<std::string> ignoreTheseAlgs,
40 std::vector<std::vector<std::string>> ignoreTheseAlgProperties,
bool appendExecCount)
41 : m_historyItems(view->getAlgorithmsList()), m_output(), m_versionSpecificity(
std::move(versionSpecificity)),
42 m_timestampCommands(appendTimestamp), m_algsToIgnore(
std::move(ignoreTheseAlgs)),
43 m_propertiesToIgnore(
std::move(ignoreTheseAlgProperties)), m_execCount(appendExecCount) {}
51 std::ostringstream os;
52 os <<
"from mantid.simpleapi import *\n\n";
73 auto algHistory = iter->getAlgorithmHistory();
74 if (iter->isUnrolled()) {
76 os << std::string(depth,
'#');
77 os <<
" Child algorithms of " << algHistory->name() <<
"\n";
82 os << std::string(depth,
'#');
83 os <<
" End of child algorithms of " << algHistory->name() <<
"\n";
85 if (boost::next(iter) ==
m_historyItems.end() || !boost::next(iter)->isUnrolled()) {
88 os <<
" # " << algHistory->executionDate().toISO8601String();
103 std::shared_ptr<const Mantid::API::AlgorithmHistory> &algHistory) {
106 os <<
" # " << algHistory->executionDate().toISO8601String();
111 os <<
" execCount: " << algHistory->execCount();
113 os <<
" # execCount: " << algHistory->execCount();
133 size_t numChildren = iter->numberOfChildren();
135 for (
size_t i = 0; i < numChildren && iter !=
m_historyItems.end(); ++i, ++iter) {
148 std::ostringstream comment;
149 const std::string name = algHistory.
name();
152 for (
auto &prop : props) {
153 if (prop->name() ==
"Text") {
154 comment <<
"# " << prop->value();
158 return comment.str();
168 std::ostringstream properties;
169 const std::string name = algHistory.
name();
180 if (name ==
"Load") {
186 algFresh->initialize();
188 const auto &propsFresh = algFresh->getProperties();
190 std::set<std::string> freshPropNames;
191 for (
const auto &propFresh : propsFresh) {
192 freshPropNames.insert(propFresh->name());
197 for (
auto prop_iter = props.begin(); prop_iter != props.end();) {
198 if (freshPropNames.find((*prop_iter)->name()) == freshPropNames.end() &&
200 prop_iter = props.erase(prop_iter);
206 }
catch (std::exception &) {
207 g_log.
error() <<
"Could not create a fresh version of " << name <<
" version " << algHistory.
version() <<
"\n";
210 for (
auto &propIter : props) {
212 if (prop.length() > 0) {
213 properties << prop <<
", ";
219 properties <<
"Version=" << algHistory.
version() <<
", ";
222 const auto &algName = algHistory.
name();
224 int latestVersion = 0;
226 if (algFactory.exists(algName)) {
231 if (latestVersion > algHistory.
version()) {
232 properties <<
"Version=" << algHistory.
version() <<
", ";
237 std::string propStr = properties.str();
238 if (propStr.length() > 0) {
240 propStr.erase(propStr.size() - 1);
241 propStr.erase(propStr.size() - 1);
244 std::string historyEntry = name +
"(" + propStr +
")";
245 historyEntry.erase(boost::remove_if(historyEntry, boost::is_any_of(
"\n\r")), historyEntry.end());
257 const std::string &algName) {
262 [&propHistory, algName](std::vector<std::string> &c) ->
bool {
263 return algName == c[0] && propHistory.name() == c[1];
269 std::vector<std::string> nonWorkspaceTypes{
"number",
"boolean",
"string"};
275 if (find(nonWorkspaceTypes.begin(), nonWorkspaceTypes.end(), propHistory.
type()) != nonWorkspaceTypes.end() &&
279 g_log.
debug() <<
"Ignoring property " << propHistory.
name() <<
" of type " << propHistory.
type() <<
'\n';
282 }
else if (propHistory.
type() ==
"number") {
283 prop = propHistory.
name() +
"=" + propHistory.
value();
285 }
else if (propHistory.
type() ==
"boolean") {
286 std::string
value = (propHistory.
value() ==
"1" ?
"True" :
"False");
290 std::string opener =
"='";
291 if (propHistory.
value().find(
'\\') != std::string::npos) {
295 prop = propHistory.
name() + opener + propHistory.
value() +
"'";
double value
The value of the point.
This class stores information about the Command History used by algorithms on a workspace.
const std::string & getPropertyValue(const std::string &name) const
get the string representation of a specified property
const std::string & name() const
get name of algorithm in history const
const int & version() const
get version number of algorithm in history const
const Mantid::Kernel::PropertyHistories & getProperties() const
get parameter list of algorithm in history const
void createStringForAlg(std::ostringstream &os, std::shared_ptr< const Mantid::API::AlgorithmHistory > &algHistory)
const std::string buildCommentString(const AlgorithmHistory &algHistory)
Build the script output for a single comment.
std::vector< std::vector< std::string > > m_propertiesToIgnore
void writeHistoryToStream(std::ostringstream &os, std::vector< HistoryItem >::const_iterator &iter, int depth=1)
Write out an algorithm to the script.
std::vector< std::string > m_algsToIgnore
const std::vector< HistoryItem > m_historyItems
ScriptBuilder(const std::shared_ptr< HistoryView > &view, std::string versionSpecificity="old", bool appendTimestamp=false, std::vector< std::string > ignoreTheseAlgs={}, std::vector< std::vector< std::string > > ignoreTheseAlgProperties={}, bool appendExecCount=false)
void buildChildren(std::ostringstream &os, std::vector< HistoryItem >::const_iterator &iter, int depth=1)
Iterate over each of the items children and output them to the script.
const std::string buildAlgorithmString(const AlgorithmHistory &algHistory)
Build the script output for a single algorithm.
const std::string buildPropertyString(const Mantid::Kernel::PropertyHistory &propHistory, const std::string &algName)
Build the script output for a single property.
std::string m_versionSpecificity
const std::string build()
build a python script from the history view
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
This class stores information about the parameters used by an algorithm.
unsigned int direction() const
get direction flag of algorithm parameter const
const std::string & name() const
get name of algorithm parameter const
const std::string & value() const
get value of algorithm parameter const
bool isDefault() const
get isdefault flag of algorithm parameter const
const std::string & type() const
get type of algorithm parameter const
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Kernel::Logger g_log("ExperimentInfo")
static logger object
const std::string COMMENT_ALG
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< const PropertyHistory > PropertyHistory_const_sptr
std::shared_ptr< PropertyHistory > PropertyHistory_sptr
Describes the direction (within an algorithm) of a Property.
@ Output
An output workspace.