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

A wrapper class for a Reading to convert to and from Python objects. More...

#include <pythonreading.h>

Inheritance diagram for PythonReading:
Collaboration diagram for PythonReading:

Public Member Functions

 PythonReading (PyObject *pyReading)
 Construct a PythonReading from a DICT object returned by Python code. More...
 
PyObject * toPython (bool changeKeys=false, bool bytesString=false)
 Convert a PythonReading, which is just a Reading, into a PyObject structure that can be passed to embedded Python code. More...
 
- Public Member Functions inherited from Reading
 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...
 

Static Public Member Functions

static std::string errorMessage ()
 Retrieve the error message last raised in Python. More...
 
static bool isArray (PyObject *)
 Return true of the Python object is an array. More...
 

Static Public Attributes

static bool doneNumPyImport = false
 

Additional Inherited Members

- Public Types inherited from Reading
enum  dateTimeFormat { FMT_DEFAULT, FMT_STANDARD, FMT_ISO8601, FMT_ISO8601MS }
 
typedef enum Reading::dateTimeFormat readingTimeFormat
 
- Protected Member Functions inherited from Reading
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 inherited from Reading
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 inherited from Reading
static std::vector< std::string > m_dateTypes
 

Detailed Description

A wrapper class for a Reading to convert to and from Python objects.

Constructor & Destructor Documentation

◆ PythonReading()

PythonReading::PythonReading ( PyObject *  pyReading)

Construct a PythonReading from a DICT object returned by Python code.

The PythonReading acts as a wrapper on the Reading class to convert to and from Readings in C and Python.

Parameters
pyReadingThe Python DICT

Set id, uuid, ts and user_ts of the original data

Member Function Documentation

◆ errorMessage()

string PythonReading::errorMessage ( )
static

Retrieve the error message last raised in Python.

Returns
string The Python error message

◆ isArray()

bool PythonReading::isArray ( PyObject *  obj)
static

Return true of the Python object is an array.

This is mostly for testing and overcomes an issue with including the numpy header files multiple times.

Parameters
objThe Pythin object to test
Returns
true if the Python object is a numpy array

◆ toPython()

PyObject * PythonReading::toPython ( bool  changeKeys = false,
bool  useBytesString = false 
)

Convert a PythonReading, which is just a Reading, into a PyObject structure that can be passed to embedded Python code.

Parameters
changeKeysSet DICT keys as reading/asset_code if true or readings/asset if false
useBytesStringWhether to use DICT keys as BytesString and string values as BytesString
Returns
PyObject* The Python representation of the readings as a DICT

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