This is an old revision of the document!


Cupcake Example

In this case, we're going to ask for both the oven temperature and final colour on a cupcake-making machine. These two pieces of equipment are 50m apart from one-another. We want the values synchronised with the conveyor system, compensating for the lag between the two components.

srv = ardiapi.Server('demo.optrix.com.au/s/pl')
 
lcq = samplestream.LagCorrectedQuery(srv)
lcq.RateLagQuery('Strip Meters',"'Paint Line' ASSET 'Speed - Actual' PROPERTY VALUES")
lcq.AddQuery("'Finish Oven Zone 1' ASSET 'Temperature - Oven' PROPERTY VALUES")
lcq.AddQuery("'Prime Oven Zone 1' ASSET 'Temperature - Oven' PROPERTY VALUES",lag=50)
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)

Key Functions

 lcq.RateLagQuery('Meters',"'Conveyor' ASSET 'Speed' PROPERTY VALUES")

This line tells the class that we are going to correct for lag based on the Speed property from our Conveyor. This is a rate of change, so we'll use the RateLagQuery function.

 lcq.AddQuery("'Inspection Station' ASSET 'Darkness' PROPERTY VALUES")

This line adds a query for the 'darkness' of our cupcakes, measured at the Inspection Station. This station is our end asset (the machine at the end of our process), so we won't include a lag for it.

 lcq.AddQuery("'Oven' ASSET 'Temperature' PROPERTY VALUES",lag=50)

This line adds another query, this time for the Oven. In this case, we've added a lag of '50' - the distance in meters between the the inspection station and the ovens.

We then send a request for the last hour of data.


In our results, we get the following…

MetersInspection DarknessOven Temp
0.060%132.1
1.262%132.0
2.461%131.9
3.660%131.8
4.855%120.7
6.062%131.6

You'll notice that you don't have a time index anymore in the resulting dataframe. Instead, you've got a total amount of whatever you're measuring as a rate or total (in this case, it's meters).

What It Means

Originally, a chart of our values looked like this…

Where people may certainly suspect that there's a direct relationship between the two dips, but it requires technical knowledge and very clean data to be confident.

But after lag compensation, our chart looks like this…

Each of the values are synchronised - so when meters is 0, we're seeing the darkness and the oven temperature for Cupcake #1, even though those two points were measured minutes apart.

Looking at the data, you'll see a drop at 3.6m into our data. Both the darkness and oven temperature decreased.

If this was a normal query or trend, these two events would appear 5 minutes apart, making it awkward to clearly display that the issues are related.

But by compensating for the lag between components, our dataframe shows an extremely clear link between the drop in temperature and the quality of our cupcake.