9#include <Poco/DateTime.h>
10#include <Poco/DateTimeFormat.h>
11#include <Poco/DateTimeParser.h>
16std::tuple<bool, size_t, std::string> isARGUSDateTime(
const std::string &date) {
24 std::string strippedDate = date.substr(0, 10);
25 const size_t nSpace = strippedDate.find(
' ');
26 return std::make_tuple(nSpace != std::string::npos, nSpace, strippedDate);
52 auto res = isARGUSDateTime(date);
54 if (std::get<0>(res)) {
56 if (displayWarnings) {
60 auto nSpace = std::get<1>(res);
65 auto strippedDate = std::get<2>(res);
66 strippedDate[nSpace] =
'0';
68 const size_t nSecondSpace = strippedDate.find(
' ');
69 if (nSecondSpace != std::string::npos)
70 time[nSecondSpace] =
'0';
71 if (displayWarnings) {
85Types::Core::DateAndTime
averageSorted(
const std::vector<Types::Core::DateAndTime> ×) {
87 throw std::invalid_argument(
"Cannot find average of empty vector");
91 const int64_t first = times.begin()->totalNanoseconds();
93 std::accumulate(times.begin(), times.end(), int64_t{0}, [first](int64_t a,
const Types::Core::DateAndTime time) {
94 return a + (time.totalNanoseconds() - first);
97 double avg =
static_cast<double>(total) /
static_cast<double>(times.size());
99 return times.front() +
static_cast<int64_t
>(avg);
102Types::Core::DateAndTime
averageSorted(
const std::vector<Types::Core::DateAndTime> ×,
103 const std::vector<double> &weights) {
105 throw std::invalid_argument(
"Cannot find average of empty vector");
106 if (times.size() != weights.size())
107 throw std::invalid_argument(
"time and weight vectors must be the same length");
108 if (times.size() == 1)
109 return times.front();
111 double totalWeight = std::accumulate(weights.begin(), weights.end(), 0.);
115 const int64_t first = times.begin()->totalNanoseconds();
119 double totalValue = std::inner_product(times.begin(), times.end(), weights.begin(),
double{0.}, std::plus<>(),
120 [first](
const Types::Core::DateAndTime time,
const double weight) {
121 return static_cast<double>(time.totalNanoseconds() - first) * weight;
125 return times.front() +
static_cast<int64_t
>(totalValue / totalWeight);
The Logger class is in charge of the publishing messages from the framework through various channels.
void warning(const std::string &msg)
Logs at warning level.
MANTID_KERNEL_DLL Types::Core::DateAndTime createFromSanitizedISO8601(const std::string &date)
Creates a DateAndTime object from a date string even if the string does not exactly conform to ISO860...
MANTID_KERNEL_DLL std::string verifyAndSanitizeISO8601(const std::string &date, bool displayWarnings=true)
Verifies whether or not a string conforms to ISO8601.
Logger g_log("DateAndTime")
MANTID_KERNEL_DLL Types::Core::DateAndTime averageSorted(const std::vector< Types::Core::DateAndTime > ×)
averageSorted Assuming that the vector is sorted, find the average time