Aggregating Instances: Aggregate and Histogram¶
We assume that you have generated a SDK for the WindTurbine
model and have a client ready to go.
pygen
automatically generates an aggregate and a histogram method for the properties in the views.
In [2]:
Copied!
from wind_turbine import WindTurbineClient
from wind_turbine import WindTurbineClient
In [3]:
Copied!
pygen = WindTurbineClient.from_toml("config.toml")
pygen = WindTurbineClient.from_toml("config.toml")
In [5]:
Copied!
result = pygen.generating_unit.aggregate("avg", property="capacity")
result
result = pygen.generating_unit.aggregate("avg", property="capacity")
result
Out[5]:
[AvgValue(property='capacity', value=6.857142857142857)]
The aggregate
methods combines all the aggrgagations and properties pased in
In [7]:
Copied!
result = pygen.wind_turbine.aggregate(
"count",
property=["name", "windfarm", "capacity"],
)
result
result = pygen.wind_turbine.aggregate(
"count",
property=["name", "windfarm", "capacity"],
)
result
Out[7]:
[CountValue(property='capacity', value=5), CountValue(property='windfarm', value=5), CountValue(property='name', value=5)]
Typically, you have to specify which properties you want to aggregate on, however, for count you can skip the properties and pygen will just take the first property it finds.
In [8]:
Copied!
result = pygen.generating_unit.aggregate("count")
result
result = pygen.generating_unit.aggregate("count")
result
Out[8]:
[CountValue(property='externalId', value=7)]
You can also group by when you aggregate
In [9]:
Copied!
result = pygen.wind_turbine.aggregate("avg", property="capacity", group_by="windfarm")
result
result = pygen.wind_turbine.aggregate("avg", property="capacity", group_by="windfarm")
result
Out[9]:
aggregates | group | |
---|---|---|
0 | [{'aggregate': 'avg', 'property': 'capacity', ... | {'windfarm': 'Hornsea 1'} |
In [10]:
Copied!
result[0].group, result[0].aggregates
result[0].group, result[0].aggregates
Out[10]:
({'windfarm': 'Hornsea 1'}, [AvgValue(property='capacity', value=7.0)])
In addition, we have histogram
aggregation on a separate method
In [11]:
Copied!
result = pygen.sensor_position.histogram("position", interval=5.0)
result
result = pygen.sensor_position.histogram("position", interval=5.0)
result
Out[11]:
HistogramValue(property='position', interval=5.0, buckets=[])
In [30]:
Copied!
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
Next section: Querying
In [ ]:
Copied!
In [ ]:
Copied!