Documentation

ValueStream implements ArrayAccess, Countable, Iterator, JsonSerializable

Class ValueStream allows the creation of the PHP Value Steam Object.

This class implements the ArrayAccess interface which will allow user to do things like: $values = $value_stream['values']. This also give us hooks into methods like __toString and jsonSerialize if we choose to implement. This will allow SQL like so: "history.evaluate_expression($stream1 * $stream2)"

Table of Contents

Interfaces

ArrayAccess
Countable
Iterator
JsonSerializable

Constants

TS_FORMATS  = ['UNIX', 'OBJECT', 'STRING']
Supported Timeseries Timestamp formats.

Properties

$aggregates  : array<string|int, mixed>
$attribute_name  : string|null
$current_timestamp_format  : string|null
$data_type  : string|null
$end_timestamp  : DateTimeInterface|string
$enumeration_type  : EnumerationType|null
$event_object_type_name  : string|null
$interpolation_method  : string|null
$measurement_unit  : null|MeasurementUnit
$object_history_meta_data  : array<string|int, mixed>
$quantity_kind  : null|QuantityKind
$source_id  : int|null
$start_timestamp  : DateTimeInterface|string
$position  : int
$time_series  : array<string|int, mixed>

Methods

__construct()  : mixed
ValueStream constructor.
__toString()  : string
Do not call this method externally, its purpose is to turn a PHP object into a string that Postgres can rehydrate as a value stream object.
count()  : int
Allows calling the count() method on the ValueStream Class.
current()  : array<string|int, mixed>
part of Iterator interface
deduceTimestampFormat()  : string
filter()  : ValueStream
Filter the ValueStream based off the filter type
intervalToMilliseconds()  : int
Converts Interval to milliseconds.
intervalToSeconds()  : float|int
Converts Interval to seconds.
jsonSerialize()  : string
Converts the ValueStream into JavaScript Object Notation
key()  : int
part of Iterator interface
mergeMedia()  : self
Handles merging pre-signed s3 media with time series data.
next()  : void
part of Iterator interface
offsetExists()  : bool
part of ArrayAccess interface
offsetGet()  : mixed
part of ArrayAccess interface
offsetSet()  : void
part of ArrayAccess interface
offsetUnset()  : void
part of ArrayAccess interface
pg_encode()  : string
Do not call this method externally, it is used as part of building a Postgres interpretable object.
processValueStreamTimeLine()  : void
processValueStreamTimeLine processes the value stream. Included are: - producing of timeline (seconds) - uptime-timeline (secondsUptime)
resample()  : ValueStream
Produces a new ValueStream based on $this, resampled at a specific rate
rewind()  : void
part of Iterator interface
setPosition()  : mixed
part of Iterator interface
setTimeStampFormat()  : void
Sets all the timestamps to a format
setUnit()  : void
Handles Setting measurement unit.
totalize()  : ValueStream
Sums the amount of value changes for this valuestream.
valid()  : bool
part of Iterator interface

Constants

TS_FORMATS

Supported Timeseries Timestamp formats.

public mixed TS_FORMATS = ['UNIX', 'OBJECT', 'STRING']
  • UNIX: UNIX time in milliseconds
  • OBJECT: object conforming to PHP DateTimeInterface
  • STRING: string with the format DateTimeInterface::RFC3339_EXTENDED (e.g. 2005-08-15T15:52:01.000+00:00)

Properties

$aggregates

public array<string|int, mixed> $aggregates = []

$attribute_name

public string|null $attribute_name = null

$current_timestamp_format

public string|null $current_timestamp_format = null
  • Can be UNIX, STRING, OBJECT

$data_type

public string|null $data_type
  • float, int, string, etc. see the type model.scalar_type_enum in the database

$end_timestamp

public DateTimeInterface|string $end_timestamp
  • last timestamp in the stream

$event_object_type_name

public string|null $event_object_type_name = null

$interpolation_method

public string|null $interpolation_method
  • 'none', 'previous', 'next', 'linear'. see model.interpolation_method_enum

$object_history_meta_data

public array<string|int, mixed> $object_history_meta_data = []

key value array of object event attribute name and measurement unit id/null. e.g. ['weight' => 54, 'license_plate' = null]

$source_id

public int|null $source_id
  • attribute or tag id

$start_timestamp

public DateTimeInterface|string $start_timestamp
  • first timestamp in the stream

$position

private int $position = 0
  • indicates the Iterator position; used in foreach loops

$time_series

private array<string|int, mixed> $time_series = []
  • holds the value, timestamp, and status information

Methods

__construct()

ValueStream constructor.

public __construct(array<string|int, mixed> $values, array<string|int, mixed> $timestamps[, array<string|int, mixed>|null $statuses = [] ][, string|null $interpolation_method = 'linear' ][, string|null $data_type = null ][, int|null $source_id = null ]) : mixed
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
$statuses : array<string|int, mixed>|null = []
  • An array of strings ("good" or "bad") that determine whether the quality is good or bad.
$interpolation_method : string|null = 'linear'
  • 'none', 'previous', 'next', 'linear'. see model.interpolation_method_enum
$data_type : string|null = null
  • float, int, string, etc. see the type model.scalar_type_enum in the database
$source_id : int|null = null
  • attribute or tag id
Tags
throws
Exception

__toString()

Do not call this method externally, its purpose is to turn a PHP object into a string that Postgres can rehydrate as a value stream object.

public __toString() : string
Return values
string

count()

Allows calling the count() method on the ValueStream Class.

public count() : int

Useful for writing a control loop like this: for ( $i = 0 ; $i < count($value_stream) ; $i++ ) }

Return values
int

current()

part of Iterator interface

public current() : array<string|int, mixed>
Return values
array<string|int, mixed>

deduceTimestampFormat()

public deduceTimestampFormat() : string
Return values
string

filter()

Filter the ValueStream based off the filter type

public filter([string $method = 'moving_average' ][, array<string|int, mixed> $config = [] ]) : ValueStream
Parameters
$method : string = 'moving_average'
$config : array<string|int, mixed> = []
Tags
throws
Exception
Return values
ValueStream

intervalToMilliseconds()

Converts Interval to milliseconds.

public static intervalToMilliseconds(DateInterval $interval) : int
Parameters
$interval : DateInterval
  • A date interval Object stores either a fixed amount of time (in years, months, days, hours etc.) or a relative time string in the format that DateTimeImmutable and DateTime's constructors support.
Return values
int

intervalToSeconds()

Converts Interval to seconds.

public static intervalToSeconds(DateInterval $interval) : float|int
Parameters
$interval : DateInterval
  • A date interval Object stores either a fixed amount of time (in years, months, days, hours etc.) or a relative time string in the format that DateTimeImmutable and DateTime's constructors support.
Return values
float|int

jsonSerialize()

Converts the ValueStream into JavaScript Object Notation

public jsonSerialize() : string
Return values
string

key()

part of Iterator interface

public key() : int
Return values
int

mergeMedia()

Handles merging pre-signed s3 media with time series data.

public mergeMedia(array<string|int, mixed> $result, array<string|int, mixed> $imageLinks, mixed $imageStepInfo) : self

Method gets called from getTimeSeriesWithMedia.

Parameters
$result : array<string|int, mixed>
  • The results for the time series data with the assign timestamps.
$imageLinks : array<string|int, mixed>
  • s3 media array.
$imageStepInfo : mixed
Return values
self

next()

part of Iterator interface

public next() : void

offsetExists()

part of ArrayAccess interface

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
  • The time series property offset value.
Return values
bool

offsetGet()

part of ArrayAccess interface

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed
  • The time series property offset value.

offsetSet()

part of ArrayAccess interface

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
  • The time series property offset value.
$value : mixed
  • The value we are going to be inserting into the time series property.

offsetUnset()

part of ArrayAccess interface

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed
  • The time series property offset value.

pg_encode()

Do not call this method externally, it is used as part of building a Postgres interpretable object.

public pg_encode() : string
Return values
string

processValueStreamTimeLine()

processValueStreamTimeLine processes the value stream. Included are: - producing of timeline (seconds) - uptime-timeline (secondsUptime)

public processValueStreamTimeLine() : void

while scanning through the timeline we compute running averages, both, time weighted and sample based we honor expirations, data gaps, and interpolation settings.

we populate an aggregates object with totalized summary kpi's.

NOTE: This processing only works for numeric value streams, you can't interpolate a string, object, etc.

Tags
throws
Exception

resample()

Produces a new ValueStream based on $this, resampled at a specific rate

public resample(DateInterval|string $interval) : ValueStream
Parameters
$interval : DateInterval|string
Tags
throws
Exception
Return values
ValueStream

rewind()

part of Iterator interface

public rewind() : void

setPosition()

part of Iterator interface

public setPosition(mixed $position) : mixed
Parameters
$position : mixed

setTimeStampFormat()

Sets all the timestamps to a format

public setTimeStampFormat(string $format) : void
Parameters
$format : string

Options: UNIX, OBJECT, STRING

setUnit()

Handles Setting measurement unit.

public setUnit(string|MeasurementUnit $m_u[, string $default_lib = 'thinkiq_base_library' ]) : void
Parameters
$m_u : string|MeasurementUnit
  • if a string is passed it needs to be the relative_name of a measurement from the base library.
$default_lib : string = 'thinkiq_base_library'
  • Library that we are going to be using.
Tags
throws
Exception

totalize()

Sums the amount of value changes for this valuestream.

public totalize([string $method = 'totalize' ][, array<string|int, mixed> $config = [] ]) : ValueStream

TODO: Add callback support so objects can specify their own totalizers

Parameters
$method : string = 'totalize'
$config : array<string|int, mixed> = []
Return values
ValueStream

valid()

part of Iterator interface

public valid() : bool
Return values
bool

        
On this page

Search results