TimeSeries
in package
Uses
DatabaseTrait
Fetches and manipulates time series data
Table of Contents
- BAD_QUALITY = 2147483648
- This is the base 10 number that signifies bad data
- GOOD_QUALITY = 0
- This is the base 10 number that signifies good data
- $db : PgSQL
- Database instance
- $db_config : TiqConfig
- Config instance
- $debug : bool
- Is debug mode or not
- $error_message : mixed
- Base error message, this belongs in com_think's configuration class
- configErrorMessage() : string
- If the TiqConfig error message constant is set, use it otherwise return the 'last resort' error message.
- evaluateExpression() : ValueStream
- getConfig() : TiqConfig
- getDb() : PgSQL
- Get database instance
- getTimeSeries() : array<string|int, mixed>|ValueStream
- Flexible method to get time series data.
- getTimeSeriesWithMedia() : ValueStream
- getValueAtTime() : mixed
- This function returns a value at a time for a given node_id respecting interpolation
- getWideTableData() : mixed
- Method that takes array of id's, start time, end time, method and interval (if applicable) and return a json time series object in wide table format.
- insertTimeSeries() : array<string|int, mixed>
- Inserts Time Series data into an attribute given equal length arrays of data, timestamps, and optional quality
- isDebug() : bool
- Is debug mode or not
- pgSqlTimeFormat() : string
- Takes a mixed object and returns a Postgres safe timestamp
- toSqlArray() : string
- Convert PHP-array to SQL-array
- createTimeSeriesEntryArray() : string
Constants
BAD_QUALITY
This is the base 10 number that signifies bad data
public
mixed
BAD_QUALITY
= 2147483648
GOOD_QUALITY
This is the base 10 number that signifies good data
public
mixed
GOOD_QUALITY
= 0
Properties
$db
Database instance
public
static PgSQL
$db
= null
$db_config
Config instance
public
static TiqConfig
$db_config
= null
$debug
Is debug mode or not
public
static bool
$debug
= false
$error_message
Base error message, this belongs in com_think's configuration class
public
static mixed
$error_message
= 'An issue occurred, please contact ThinkIQ for Support and enable debugging'
Methods
configErrorMessage()
If the TiqConfig error message constant is set, use it otherwise return the 'last resort' error message.
public
static configErrorMessage() : string
Return values
string —evaluateExpression()
public
static evaluateExpression(string $expression) : ValueStream
Parameters
- $expression : string
-
All variables must be ValueStream Objects
Tags
Return values
ValueStream —getConfig()
public
static getConfig() : TiqConfig
Return values
TiqConfig —getDb()
Get database instance
public
static getDb() : PgSQL
Return values
PgSQL —getTimeSeries()
Flexible method to get time series data.
public
static getTimeSeries(int $node_id, DateTimeInterface|string $start, DateTimeInterface|string $end) : array<string|int, mixed>|ValueStream
Takes a node id, or an FQN amd returns time series data in the duration. The dates must be in ISO format.
Parameters
- $node_id : int
- $start : DateTimeInterface|string
-
if a string is passed in it must be a SQL compliant date
- $end : DateTimeInterface|string
-
if a string is passed in it must be a SQL compliant date
Tags
Return values
array<string|int, mixed>|ValueStream —see the ValueStream object
getTimeSeriesWithMedia()
public
static getTimeSeriesWithMedia(int $node_id, DateTimeInterface|string $start, DateTimeInterface|string $end) : ValueStream
Parameters
- $node_id : int
- $start : DateTimeInterface|string
- $end : DateTimeInterface|string
Tags
Return values
ValueStream —getValueAtTime()
This function returns a value at a time for a given node_id respecting interpolation
public
static getValueAtTime(string|int $node_id, DateTimeInterface|string $timestamp) : mixed
Parameters
- $node_id : string|int
-
fqn, or tag_id or attribute_id
- $timestamp : DateTimeInterface|string
-
php Datetime or an SQL safe string
Tags
Return values
mixed —getWideTableData()
Method that takes array of id's, start time, end time, method and interval (if applicable) and return a json time series object in wide table format.
public
static getWideTableData(array<string|int, mixed> $ids, int $start, int $end, string $method[, mixed $interval = null ]) : mixed
Parameters
- $ids : array<string|int, mixed>
-
array of id's
- $start : int
-
in epoch
- $end : int
-
in epoch
- $method : string
-
can be on of the following: FULL, SPARSE, FIRST, INTERVAL
- $interval : mixed = null
-
must be pass if method is INTERVAL (e.g. '1 second', '3 m', '4 hours')
Return values
mixed —insertTimeSeries()
Inserts Time Series data into an attribute given equal length arrays of data, timestamps, and optional quality
public
static insertTimeSeries(string $node_id, array<string|int, mixed> $values, array<string|int, mixed> $timestamps[, array<string|int, mixed> $quality = [] ]) : array<string|int, mixed>
Parameters
- $node_id : string
-
fqn, or tag_id or attribute_id
- $values : array<string|int, mixed>
- $timestamps : array<string|int, mixed>
- $quality : array<string|int, mixed> = []
Tags
Return values
array<string|int, mixed> —array keys are rows_inserted and rows_deleted
isDebug()
Is debug mode or not
public
static isDebug() : bool
Return values
bool —pgSqlTimeFormat()
Takes a mixed object and returns a Postgres safe timestamp
public
static pgSqlTimeFormat( $timestamp) : string
Takes either a PHP DateTime object, a unix timestamp, or a plain string
Parameters
Return values
string —toSqlArray()
Convert PHP-array to SQL-array
public
static toSqlArray(array<string|int, mixed> $data[, string $escape = 'pg_escape_string' ][, bool $string_override = false ]) : string
Parameters
- $data : array<string|int, mixed>
- $escape : string = 'pg_escape_string'
- $string_override : bool = false
-
use this to specifically indicate that the field is a string, useful for bits, geopoints, etc
Return values
string —createTimeSeriesEntryArray()
protected
static createTimeSeriesEntryArray(array<string|int, mixed> $values, array<string|int, mixed> $timestamps, array<string|int, mixed> $qualities) : string
Parameters
- $values : array<string|int, mixed>
- $timestamps : array<string|int, mixed>
- $qualities : array<string|int, mixed>