« Back to Product

Documentation

AC_GetAggregatedValues

Require: IP-Symcon >= 3.0

 array AC_GetAggregatedValues (int $InstanceID, int $VariableID, int $AggregationLevel, int $StartTime, int $EndTime, int $Limit) 

Parameters

InstanceID

ID for the archive

VariableID

ID of the variable to be queried

AggregationLevel
Aggregationsstufe Beschreibung
0 Stündliche Aggregation
(00:00 - 59:59)
1 Tägliche Aggregation
(00:00:00 - 23:59:59)
2 Wöchentliche Aggregation
(Montag 00:00:00 - Sonntag 23:59:59)
3 Monatliche Aggregation
(Erster Monatstag 00:00:00 - Letzter Monatstag 23:59:59)
4 Jährliche Aggregation
(01.01. 00:00:00 - 31.12. 23:59:59)
5 5-Minütige Aggregation (Aus Rohdaten berechnet)
6 1-Minütige Aggregation (Aus Rohdaten berechnet)
StartTime

Date/time as Unix Timestamp (0 = from the beginning)

EndTime

Date/time as Unix Timestamp (0 = until now)

Limit

Maximum number of datasets. (0 = no limit, 10000 is the hard limit, which always applies)

Returns

An array with the following key => value pairs.

Warning

The output starts with the newest dataset and then, in descending order, with the older data sets.

Meaning of the fields for the aggregation type Standard

Index Type Description
Avg variant Average value within this aggregation period
Duration integer Duration of the aggregation period in seconds
Max variant Largest value within this aggregation period
MaxTime variant Date/time of Max as Unix Timestamp
Min variant Smallest value within this aggregation period
MinTime variant Date/time of min as Unix Timestamp
TimeStamp integer Date/time of the start of the aggregation period as a Unix Timestamp

Meaning of the fields for the aggregation type Counter

Index Type Description
Avg variant Sum of the positive delta within this aggregation period
Duration integer Duration of the aggregation period in seconds
Max variant Largest positive delta within this aggregation period
MaxTime variant Date/time of Max as Unix Timestamp
Min variant Smallest positive delta within this aggregation period
MinTime variant Date/time of min as Unix Timestamp
TimeStamp integer Date/time of the start of the aggregation period as a Unix Timestamp

Description

This command returns the aggregated data that was logged and calculated via the archive for a variable with the VariableID. The Start- and EndTime can be specified as parameters. The parameter Limit limits the maximum number of data records returned, whereby the limit of 10000 data records per query can never be exceeded.

Warning

This function guarantees that all data records between the StartTime and the EndTime are also available and are put out. This means that there are no time gaps between the data records. Data records are put out up to the current point in time.

Warning

Whole aggregated time periods are always queried. For this, the StartTime (depending on the aggregation level) of the hour/day/week/month/year in the period of StartTime and EndTime must be included.

Warning

The aggregation levels 5-minute/1-minute aggregation are calculated from the raw data, so that if there is a lot of raw data, they may require more system performance than the other aggregation levels

Example

// Query all data records from 01/01/2013 to 12/31/2013 (daily aggregation level) 
// e.g. to determine the consumption on the respective day or the average temperature on the respective day
$values = AC_GetAggregatedValues(12345, 55554, 1 /* daily */, mktime(0, 0, 0, 1, 1, 2013), mktime(23, 59, 59, 12, 31, 2013), 0); //55554 is the variable ID, 12345 from the archive        

// Query all current data records (daily aggregation level)
// e.g. to determine today's consumption or today's average temperature
$values = AC_GetAggregatedValues(12345, 55554, 1 /* daily */, strtotime("today 00:00"), time(), 0); //55554 is the ID of the variable, 12345 from the archive        

// Query all yesterday's records (hourly aggregation level)
// For example, to check yesterday's consumption or the average wind speed every hour          
$values = AC_GetAggregatedValues(12345, 55554, 0 /* hourly */, strtotime("yesterday 00:00"), strtotime("today 00:00")-1, 0); //55554 is the ID of the variable, 12345 from the archive        
        
// This part creates an output in the script window with the queried values        
foreach($values as $value) {
	echo date("d.m.Y H:i:s", $value['TimeStamp']) . " -> " . $value['Avg'] . PHP_EOL;
}
Any questions?