Fledge
An open source edge computing platform for industrial users
Reading Class Reference

An asset reading represented as a class. More...

#include <reading.h>

Inheritance diagram for Reading:

Public Types

enum  dateTimeFormat { FMT_DEFAULT, FMT_STANDARD, FMT_ISO8601, FMT_ISO8601MS }
 
typedef enum Reading::dateTimeFormat readingTimeFormat
 

Public Member Functions

 Reading (const std::string &asset, Datapoint *value)
 
 Reading (const std::string &asset, std::vector< Datapoint *> values)
 
 Reading (const std::string &asset, std::vector< Datapoint *> values, const std::string &ts)
 
 Reading (const std::string &asset, const std::string &datapoints)
 
 Reading (const Reading &orig)
 Reading copy constructor.
 
 ~Reading ()
 Destructor for Reading class.
 
void addDatapoint (Datapoint *value)
 Add another data point to an asset reading.
 
DatapointremoveDatapoint (const std::string &name)
 Remove a datapoint from the reading. More...
 
DatapointgetDatapoint (const std::string &name) const
 Return a specific data point by name. More...
 
std::string toJSON (bool minimal=false) const
 Return the asset reading as a JSON structure encoded in a C++ string.
 
std::string getDatapointsJSON () const
 Return the asset reading as a JSON structure encoded in a C++ string.
 
const std::string & getAssetName () const
 
void setAssetName (std::string assetName)
 
unsigned int getDatapointCount ()
 
void removeAllDatapoints ()
 Remove all data points for Reading class.
 
const std::vector< Datapoint * > getReadingData () const
 
std::vector< Datapoint * > & getReadingData ()
 
bool hasId () const
 
unsigned long getId () const
 
unsigned long getTimestamp () const
 
unsigned long getUserTimestamp () const
 
void setId (unsigned long id)
 
void setTimestamp (unsigned long ts)
 
void setTimestamp (struct timeval tm)
 
void setTimestamp (const std::string &timestamp)
 
void getTimestamp (struct timeval *tm)
 
void setUserTimestamp (unsigned long uTs)
 
void setUserTimestamp (struct timeval tm)
 
void setUserTimestamp (const std::string &timestamp)
 
void getUserTimestamp (struct timeval *tm)
 
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. More...
 
const std::string getAssetDateTime (readingTimeFormat datetimeFmt=FMT_DEFAULT, bool addMs=true) const
 Return a formatted m_timestamp DataTime in UTC. More...
 
const std::string getAssetDateUserTime (readingTimeFormat datetimeFmt=FMT_DEFAULT, bool addMs=true) const
 Return a formatted m_userTimestamp DataTime in UTC. More...
 
std::string substitute (const std::string &str)
 Substitute values from this reading into the string. More...
 

Protected Member Functions

Readingoperator= (Reading const &)
 
void stringToTimestamp (const std::string &timestamp, struct timeval *ts)
 Convert a string timestamp, with milliseconds to a struct timeval. More...
 
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. More...
 
std::vector< Datapoint * > * JSONtoDatapoints (const rapidjson::Value &json)
 Convert a JSON Value object to a set of data points. More...
 

Protected Attributes

unsigned long m_id
 
bool m_has_id
 
std::string m_asset
 
struct timeval m_timestamp
 
struct timeval m_userTimestamp
 
std::vector< Datapoint * > m_values
 

Static Protected Attributes

static std::vector< std::string > m_dateTypes
 

Detailed Description

An asset reading represented as a class.

Each asset reading may have multiple datapoints to represent the multiple values that maybe held within a complex asset.

NB The timestamp data held for both the system timestamp and the user timestamp are always held internally as UTC times

Member Function Documentation

◆ escape()

const string Reading::escape ( const std::string &  str) const
protected

Escape quotes etc to allow the string to be a property value within a JSON document.

Parameters
strThe string to escape
Returns
The escaped string

◆ getAssetDateTime()

const string Reading::getAssetDateTime ( readingTimeFormat  dateFormat = FMT_DEFAULT,
bool  addMS = true 
) const

Return a formatted m_timestamp DataTime in UTC.

Parameters
dateFormatFormat: FMT_DEFAULT or FMT_STANDARD
Returns
The formatted datetime string

◆ getAssetDateUserTime()

const string Reading::getAssetDateUserTime ( readingTimeFormat  dateFormat = FMT_DEFAULT,
bool  addMS = true 
) const

Return a formatted m_userTimestamp DataTime in UTC.

Parameters
dateFormatFormat: FMT_DEFAULT or FMT_STANDARD
Returns
The formatted datetime string

◆ getDatapoint()

Datapoint * Reading::getDatapoint ( const std::string &  name) const

Return a specific data point by name.

Parameters
nameThe name of the datapoint to return
Returns
Pointer a the named datapoint or NULL if it does not exist

◆ getFormattedDateTimeStr()

void Reading::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.

Parameters
tv_secSeconds since epoch
date_timeBuffer in which to return the formatted timestamp
dateFormatFormat: FMT_DEFAULT or FMT_STANDARD

Build date_time with format YYYY-MM-DD HH24:MM:SS.MS+00:00 this is same as Python3: datetime.datetime.now(tz=datetime.timezone.utc)

◆ JSONtoDatapoints()

vector< Datapoint * > * Reading::JSONtoDatapoints ( const rapidjson::Value &  json)
protected

Convert a JSON Value object to a set of data points.

Parameters
jsonThe json object to convert

◆ removeDatapoint()

Datapoint * Reading::removeDatapoint ( const std::string &  name)

Remove a datapoint from the reading.

Parameters
nameName of the datapoitn to remove
Returns
Pointer to the datapoint removed or NULL if it was not found

◆ stringToTimestamp()

void Reading::stringToTimestamp ( const std::string &  timestamp,
struct timeval *  ts 
)
protected

Convert a string timestamp, with milliseconds to a struct timeval.

Timezone handling The timezone in the string is extracted to get UTC values. Times within a reading are always stored as UTC

Parameters
timestampString timestamp
tsStruct timeval to populate

◆ substitute()

string Reading::substitute ( const std::string &  str)

Substitute values from this reading into the string.

Macros are of the form $datapointname$, $ASSET$ or $datapointname|default$

Parameters
strThe string to substitute into
Returns
string The substituted string

Member Data Documentation

◆ m_dateTypes

std::vector< std::string > Reading::m_dateTypes
staticprotected
Initial value:
= {
DEFAULT_DATE_TIME_FORMAT,
COMBINED_DATE_STANDARD_FORMAT,
ISO8601_DATE_TIME_FORMAT,
ISO8601_DATE_TIME_FORMAT
}

The documentation for this class was generated from the following files: