12 #include <datapoint.h> 17 #include <rapidjson/document.h> 19 #define DEFAULT_DATE_TIME_FORMAT "%Y-%m-%d %H:%M:%S" 20 #define COMBINED_DATE_STANDARD_FORMAT "%Y-%m-%dT%H:%M:%S" 21 #define ISO8601_DATE_TIME_FORMAT "%Y-%m-%d %H:%M:%S +0000" 22 #define DATE_TIME_BUFFER_LEN 52 36 Reading(
const std::string& asset, std::vector<Datapoint *> values);
37 Reading(
const std::string& asset, std::vector<Datapoint *> values,
const std::string& ts);
38 Reading(
const std::string& asset,
const std::string& datapoints);
45 std::string
toJSON(
bool minimal =
false)
const;
48 const std::string& getAssetName()
const {
return m_asset; };
50 void setAssetName(std::string assetName) { m_asset = assetName; };
51 unsigned int getDatapointCount() {
return m_values.size(); };
54 const std::vector<Datapoint *> getReadingData()
const {
return m_values; };
56 std::vector<Datapoint *>& getReadingData() {
return m_values; };
57 bool hasId()
const {
return m_has_id; };
58 unsigned long getId()
const {
return m_id; };
59 unsigned long getTimestamp()
const {
return (
unsigned long)m_timestamp.tv_sec; };
60 unsigned long getUserTimestamp()
const {
return (
unsigned long)m_userTimestamp.tv_sec; };
61 void setId(
unsigned long id) { m_id = id; };
62 void setTimestamp(
unsigned long ts) { m_timestamp.tv_sec = (time_t)ts; };
63 void setTimestamp(
struct timeval tm) { m_timestamp = tm; };
64 void setTimestamp(
const std::string& timestamp);
65 void getTimestamp(
struct timeval *tm) { *tm = m_timestamp; };
66 void setUserTimestamp(
unsigned long uTs) { m_userTimestamp.tv_sec = (time_t)uTs; };
67 void setUserTimestamp(
struct timeval tm) { m_userTimestamp = tm; };
68 void setUserTimestamp(
const std::string& timestamp);
69 void getUserTimestamp(
struct timeval *tm) { *tm = m_userTimestamp; };
71 typedef enum dateTimeFormat { FMT_DEFAULT, FMT_STANDARD, FMT_ISO8601, FMT_ISO8601MS } readingTimeFormat;
75 const std::string
getAssetDateTime(readingTimeFormat datetimeFmt = FMT_DEFAULT,
bool addMs =
true)
const;
77 const std::string
getAssetDateUserTime(readingTimeFormat datetimeFmt = FMT_DEFAULT,
bool addMs =
true)
const;
78 std::string
substitute(
const std::string& str);
84 const std::string
escape(
const std::string& str)
const;
89 struct timeval m_timestamp;
90 struct timeval m_userTimestamp;
91 std::vector<Datapoint *> m_values;
93 static std::vector<std::string> m_dateTypes;
98 Macro(
const std::string& dpname, std::string::size_type s,
99 const std::string& defValue) :
100 start(s), name(dpname), def(defValue)
104 Macro(
const std::string& dpname, std::string::size_type s) :
105 start(s), name(dpname)
110 std::string::size_type start;
116 void collectMacroInfo(
const std::string& str, std::vector<Macro>& macros);
const std::string escape(const std::string &str) const
Escape quotes etc to allow the string to be a property value within a JSON document.
Definition: reading.cpp:542
Datapoint * getDatapoint(const std::string &name) const
Return a specific data point by name.
Definition: reading.cpp:216
Name and value pair used to represent a data value within an asset reading.
Definition: datapoint.h:310
void removeAllDatapoints()
Remove all data points for Reading class.
Definition: reading.cpp:171
An asset reading represented as a class.
Definition: reading.h:33
~Reading()
Destructor for Reading class.
Definition: reading.cpp:160
std::string substitute(const std::string &str)
Substitute values from this reading into the string.
Definition: reading.cpp:670
const std::string getAssetDateUserTime(readingTimeFormat datetimeFmt=FMT_DEFAULT, bool addMs=true) const
Return a formatted m_userTimestamp DataTime in UTC.
Definition: reading.cpp:384
void addDatapoint(Datapoint *value)
Add another data point to an asset reading.
Definition: reading.cpp:183
std::string getDatapointsJSON() const
Return the asset reading as a JSON structure encoded in a C++ string.
Definition: reading.cpp:273
std::string toJSON(bool minimal=false) const
Return the asset reading as a JSON structure encoded in a C++ string.
Definition: reading.cpp:235
Datapoint * removeDatapoint(const std::string &name)
Remove a datapoint from the reading.
Definition: reading.cpp:194
void stringToTimestamp(const std::string ×tamp, struct timeval *ts)
Convert a string timestamp, with milliseconds to a struct timeval.
Definition: reading.cpp:457
std::vector< Datapoint * > * JSONtoDatapoints(const rapidjson::Value &json)
Convert a JSON Value object to a set of data points.
Definition: reading.cpp:584
void getFormattedDateTimeStr(const time_t *tv_sec, char *date_time, readingTimeFormat dateFormat) const
Convert time since epoch to a formatted m_timestamp DataTime in UTC and use a cache to speed it up...
Definition: reading.cpp:297
const std::string getAssetDateTime(readingTimeFormat datetimeFmt=FMT_DEFAULT, bool addMs=true) const
Return a formatted m_timestamp DataTime in UTC.
Definition: reading.cpp:340