Statistics allow you to collect commulated information about your data. An example for an easy statistic that is already delivered by BYRD itself is the compliance statistic in your dashboard.
To create your own statistics an statistics script needs to be registered in the pim.xml of your Datamodel:
<pim>
<statistics>/my-statistics-script.rb</statistics>
</pim>
The basic idea behind statistics in BYRD are as followed:
new_item
) as well as to the item state before (old_item
).The following snippet shows an example statistics script, that counts all items, that are heavier then 1000kg or lighter then 1kg
PIM::Statistics.calculate_statistics do
statistic 'extremeWeights' do
if old_item
decr('over_1000') if old_item['weight_kg'].to_i > 1000
decr('below_1') if old_item['weight_kg'].to_i < 1
end
if new_item
incr('over_1000') if new_item['weight_kg'].to_i > 1000
incr('below_1') if new_item['weight_kg'].to_i < 1
end
end
end
As you can see, we define two dimensions here: "over_1000= and "below_1".
To understand whats going on here, consider we are storing an item that previously had a weight of 0,5 kg and was now set to 2000kg. When accessing the first if-statement the 'below_1' dimensions is decremented via the decr
function (as the prior value was bellow 1). Accessing the second if-statement then increases the 'over_1000' dimension: Both dimensions are now in a correct state!
To access the data collected by your statistics you can use our REST-API. Doing an HTTP-GET on the following address:
http://app.syncmanager.com/api/v1/statistics/dynamic/extremeWeights
will result in a JSON Result with this format:
[
{
"name": "extremeWeights",
"key": "below_1",
"dimension": null,
"count": 1,
"version": 1,
"nonShardedId": "extremeWeights:below_1:1"
},
{
"name": "extremeWeights",
"key": "over_1000",
"dimension": null,
"count": 1,
"version": 1,
"nonShardedId": "extremeWeights:over_1000:1"
}
]