This is an old revision of the document!


Adaptable Example

In the previous example, we hard-coded the distance between each of our assets when requesting a lag-corrected query.

This would mean the code wouldn't be able to adapt to changes or move between various different lines, or deal with flexible systems that adjust for specific products.

Using ARDI, it's also possible to use relationships and static properties to load these distance values dynamically - although it is still limited to only working on simple forms of lag.

srv = ardiapi.Server('cupcake.ardi')
 
#Get the 'Distance To End' property value for all assets down-stream from the oven...
req = ardiapi.AQLQuery(srv)
resp = req.Execute("'Oven' ASSET 'Sequence' RELATIONSHIP 'downi' RELATED 'Distance To End' PROPERTY VALUES")
 
#Go through each asset and write its lag value to a dictionary
lags = {}
for value in resp['response'][0]['value']:
    lags[value['name']] = value['rawvalue']
 
#Same as the previous query, but replaces the fixed lag value with a dictionary lookup
lcq = samplestream.LagCorrectedQuery(srv)
lcq.RateLagQuery('Meters',"'Conveyor' ASSET 'Speed' PROPERTY VALUES")
lcq.AddQuery("'Inspection Station' ASSET 'Brownness' PROPERTY VALUES")
lcq.AddQuery("'Oven' ASSET 'Temperature' PROPERTY VALUES",lag=lags['Oven'])
lcq.multiplier = 0.0166
lcq.shavems = True
 
starttime = datetime.datetime.utcnow()-datetime.timedelta(seconds=60*60)
endtime = datetime.datetime.utcnow()
 
df = lcq.Execute(starttime,endtime,samples=3600)

Using this technique, your logic…

  • Can adapt to temporary or permanent changes made to site,
  • Can be used across multiple product lines with different configurations, and
  • Can be used on multiple different sites