Documentation

TimeSeries
in package
uses DatabaseTrait, VisionTrait

Fetches and manipulates time series data

Table of Contents

Constants

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

Properties

$error_message  : string

Methods

configErrorMessage()  : string
Returns the configuration error message.
createTimeSeriesEntryArray()  : string
Handles the creation of the times series entry array
deleteTimeSeriesAfter()  : array<string|int, mixed>
Deletes time series data for an attribute after a specified timestamp
deleteTimeSeriesBefore()  : array<string|int, mixed>
Deletes time series data for an attribute before a specified timestamp
deleteTimeSeriesRange()  : array<string|int, mixed>
Deletes time series data for an attribute within a specified time range
evaluateExpression()  : ValueStream
eventSerialize()  : array<string|int, mixed>
Takes an array of Objects and turns them into JSON data that can be historized
generateS3PresignedURLs()  : array<string|int, mixed>
Generate and return presigned S3 URLs for the provided S3 Storage Paths.
generateStoragePresignedURLs()  : array<string|int, mixed>
Generate and return pre-signed Storage URLs for the provided Storage Paths
getConfig()  : TiqConfig
Gets the TIQ configuration.
getDb()  : PgSQL
Gets database instance.
getEventsById()  : array<string|int, mixed>
Takes an array of object values and returns an array of value streams with the objects hydrated
getTimeSeries()  : array<string|int, mixed>|ValueStream
Flexible method to get time series data.
getTimeSeriesBulk()  : array<string|int, mixed>
Gets timeseries data for an array of node ids (tags or attributes) and returns an array of ValueStreams, with differing length depending on the data
getTimeSeriesWithMedia()  : array<string|int, mixed>|ValueStream
Gets time series with media; also, it will add media links if found for given time span
getValueAtTime()  : array<string|int, mixed>
This function returns a value at a time for a given node_id respecting interpolation
getVisionDataWithMedia()  : mixed|Tag|null
Get the vision data with media for the given node id.
getVisionGatewayInfo()  : array<string|int, mixed>
Get the vision gateway Info.
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.
hydrateEvents()  : ValueStream
Takes a value stream of objects and hydrates them
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
reduceDataByLimit()  : array<string|int, mixed>
Returns a new dataset with the data averaged over the given interval.
toSqlArray()  : string
Convert PHP-array to SQL-array

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

$error_message

public static string $error_message = 'An issue occurred, please contact ThinkIQ for Support and enable debugging'
  • Base error message

Methods

configErrorMessage()

Returns the configuration error message.

public static configErrorMessage() : string
Return values
string

createTimeSeriesEntryArray()

Handles the creation of the times series entry array

public static createTimeSeriesEntryArray(array<string|int, mixed> $values, array<string|int, mixed> $timestamps, array<string|int, string> $qualities) : string
Parameters
$values : array<string|int, mixed>
  • An array of values that we want to set its quality and timestamp.
$timestamps : array<string|int, mixed>
  • An array that contains php Datetime or an SQL safe string
$qualities : array<string|int, string>
  • An array of strings ("good" or "bad") that determine whether the quality is good or bad.
Tags
throws
Exception
Return values
string

deleteTimeSeriesAfter()

Deletes time series data for an attribute after a specified timestamp

public static deleteTimeSeriesAfter(string|int $node_id, DateTimeInterface|string $timestamp) : array<string|int, mixed>
Parameters
$node_id : string|int
  • FQN or tag_id or attribute_id
$timestamp : DateTimeInterface|string
  • php DateTime or an SQL safe string representing the cutoff time
Tags
throws
Exception
Return values
array<string|int, mixed>
  • array with keys 'rows_deleted' indicating the number of records removed

deleteTimeSeriesBefore()

Deletes time series data for an attribute before a specified timestamp

public static deleteTimeSeriesBefore(string|int $node_id, DateTimeInterface|string $timestamp) : array<string|int, mixed>

Note that this method is EXTREMELY dangerous and can result in memory exhaustion... maybe we shouldn't allow this...

Parameters
$node_id : string|int
  • FQN or tag_id or attribute_id
$timestamp : DateTimeInterface|string
  • php DateTime or an SQL safe string representing the cutoff time
Tags
throws
Exception
Return values
array<string|int, mixed>
  • array with keys 'rows_deleted' indicating the number of records removed

deleteTimeSeriesRange()

Deletes time series data for an attribute within a specified time range

public static deleteTimeSeriesRange(string|int $node_id, DateTimeInterface|string $start, DateTimeInterface|string $end) : array<string|int, mixed>

Note that for Event Objects, their id's will still exist in other parts of the application like the Material Flow...

Parameters
$node_id : string|int
  • FQN or tag_id or attribute_id
$start : DateTimeInterface|string
  • php DateTime or an SQL safe string representing the start time
$end : DateTimeInterface|string
  • php DateTime or an SQL safe string representing the end time
Tags
throws
TimeSeriesOperationException

When time series operations fail

throws
HistoryTableResolutionException

When history table cannot be resolved

throws
NotImplementedException

When trying to manipulate unsupported data types

throws
Exception

For other unexpected errors

Return values
array<string|int, mixed>
  • array with keys 'rows_deleted' and 'rows_inserted' indicating records affected

evaluateExpression()

public static evaluateExpression(string $expression) : ValueStream
Parameters
$expression : string
  • All variables must be ValueStream Objects
Tags
throws
Exception
Return values
ValueStream

eventSerialize()

Takes an array of Objects and turns them into JSON data that can be historized

public static eventSerialize(array<string|int, mixed> $values, int $type_id) : array<string|int, mixed>
Parameters
$values : array<string|int, mixed>
$type_id : int
Return values
array<string|int, mixed>

generateS3PresignedURLs()

Generate and return presigned S3 URLs for the provided S3 Storage Paths.

public static generateS3PresignedURLs(array<string|int, mixed> $measures[, mixed $expiration_time = '20 minutes' ]) : array<string|int, mixed>

Note: The reason why we are doing this, is because there are many scripts in the platform that are using the S3 URLs method and we want to keep this scripts working, without having to change any existing scripts.

Parameters
$measures : array<string|int, mixed>
  • The PHP associative array-object with keys as < and values as array of Storage paths
$expiration_time : mixed = '20 minutes'
  • duration in minutes - default value '20 minutes' if not specified
Tags
throws
Exception
Return values
array<string|int, mixed>
  • The PHP associative array-object with keys as and values as array

generateStoragePresignedURLs()

Generate and return pre-signed Storage URLs for the provided Storage Paths

public static generateStoragePresignedURLs(array<string|int, mixed> $measures[, string|DateInterval $expiration_time = '20 minutes' ]) : array<string|int, mixed>
Parameters
$measures : array<string|int, mixed>
  • The PHP associative array-object with keys as < and values as array of Storage paths
$expiration_time : string|DateInterval = '20 minutes'
  • duration in minutes - default value '20 minutes' if not specified
Tags
throws
Exception
Return values
array<string|int, mixed>
  • The PHP associative array-object with keys as and values as array of pre-signed Storage URLs.

getConfig()

Gets the TIQ configuration.

public static getConfig() : TiqConfig
Return values
TiqConfig

getDb()

Gets database instance.

public static getDb() : PgSQL

The database connection is stored in a static property within the DatabaseConnectionManager class, ensuring that it is truly a singleton across the entire application, regardless of which class calls this method.

Return values
PgSQL

getEventsById()

Takes an array of object values and returns an array of value streams with the objects hydrated

public static getEventsById(array<string|int, mixed> $ids[, bool $display_names = false ]) : array<string|int, mixed>
Parameters
$ids : array<string|int, mixed>
$display_names : bool = false
Tags
throws
Exception
Return values
array<string|int, mixed>

of Value streams of length 1.

getTimeSeries()

Flexible method to get time series data.

public static getTimeSeries(string|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 : string|int
  • FQN or tag_id or attribute_id
$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
throws
Exception
Return values
array<string|int, mixed>|ValueStream

see the ValueStream object

getTimeSeriesBulk()

Gets timeseries data for an array of node ids (tags or attributes) and returns an array of ValueStreams, with differing length depending on the data

public static getTimeSeriesBulk(array<string|int, mixed> $node_ids, DateTimeInterface|string $start, DateTimeInterface|string $end[, int $max_values = 0 ]) : array<string|int, mixed>
Parameters
$node_ids : array<string|int, mixed>
$start : DateTimeInterface|string
$end : DateTimeInterface|string
$max_values : int = 0
Tags
throws
Exception
Return values
array<string|int, mixed>

getTimeSeriesWithMedia()

Gets time series with media; also, it will add media links if found for given time span

public static getTimeSeriesWithMedia(string|int $node_id, DateTimeInterface|string $start, DateTimeInterface|string $end[, bool $withMedia = false ][, int $limitMedia = 5 ]) : array<string|int, mixed>|ValueStream
Parameters
$node_id : string|int
  • FQN or tag_id or attribute_id
$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
$withMedia : bool = false
  • if true, will add media links to the result
$limitMedia : int = 5
  • limit of Vision media links to add to the result, if the user passes 0, it will add all media links
Tags
throws
Exception
see
getTimeSeries
Return values
array<string|int, mixed>|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) : array<string|int, mixed>
Parameters
$node_id : string|int
  • FQN or tag_id or attribute_id
$timestamp : DateTimeInterface|string
  • php Datetime or an SQL safe string
Tags
throws
Exception
Return values
array<string|int, mixed>

[ 'value' => mixed | null, 'status' => null | string, 'time_stamp' => string, ];

getVisionDataWithMedia()

Get the vision data with media for the given node id.

public static getVisionDataWithMedia(int $attribute_id, DateTimeInterface|string $start_date, DateTimeInterface|string $end_date) : mixed|Tag|null
Parameters
$attribute_id : int
$start_date : DateTimeInterface|string
$end_date : DateTimeInterface|string
Tags
throws
Exception
Return values
mixed|Tag|null

getVisionGatewayInfo()

Get the vision gateway Info.

public static getVisionGatewayInfo(int $attribute_id) : array<string|int, mixed>
Parameters
$attribute_id : int
Tags
throws
Exception
Return values
array<string|int, mixed>
  • returns array containing step_input_key, gateway_id, step_function, step_name and FDW

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')
Tags
throws
Exception

hydrateEvents()

Takes a value stream of objects and hydrates them

public static hydrateEvents(ValueStream $value_stream, int $type_id[, bool $display_names = true ]) : ValueStream
Parameters
$value_stream : ValueStream
$type_id : int
$display_names : bool = true
Return values
ValueStream

insertTimeSeries()

Inserts Time Series data into an attribute given equal length arrays of data, timestamps, and optional quality

public static insertTimeSeries(string|int $node_id, array<string|int, mixed> $values, array<string|int, mixed> $timestamps[, array<string|int, string>|null $quality = [] ][, bool $flush = true ]) : array<string|int, mixed>
Parameters
$node_id : string|int
  • FQN or tag_id or attribute_id
$values : array<string|int, mixed>
  • An array of values that we want to set its quality and timestamp.
$timestamps : array<string|int, mixed>
  • An array that contains php Datetime or an SQL safe string
$quality : array<string|int, string>|null = []
  • An array of strings ("good" or "bad") that determine whether the quality is good or bad.
$flush : bool = true
  • default true, will flush the current values in history, otherwise will append the new values
Tags
throws
Exception
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(DateTimeInterface|string $timestamp) : string

Takes either a PHP DateTime object, a unix timestamp, or a plain string

Parameters
$timestamp : DateTimeInterface|string
  • php Datetime or an SQL safe string
Return values
string

reduceDataByLimit()

Returns a new dataset with the data averaged over the given interval.

public static reduceDataByLimit(array<string|int, mixed> $data, int $min, int $max[, int $limit = 5 ][, array<string|int, mixed> $newData = [] ]) : array<string|int, mixed>

This is useful for reducing the amount of data returned from a query. The data returned will be the average of the data in the given interval.

Parameters
$data : array<string|int, mixed>
  • the data set to reduce.
$min : int
  • the minimum index of the data set.
$max : int
  • the maximum index of the data set.
$limit : int = 5
  • the maximum number of data points to return.
$newData : array<string|int, mixed> = []
  • the new data set to return.
Return values
array<string|int, mixed>
  • the new data set.

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>
  • The PHP array that contains the data that we want to convert to SQL array.
$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

        
On this page

Search results