SampleStream Example
In this case, we're going to perform a search for the last time Turbine #1 from the Optrix Wind Farm Demo was offline for more than a second.
First, we import the libraries we need…
import ardiapi import samplestream
Then we connect to our ARDI server…
srv = ardiapi.Server("demo.optrix.com.au/s/ex")
Now we create an AQL query to get our data.
query = "'Wind Turbine #1' ASSET 'Power' PROPERTY VALUES"
Next, set up our SampleStream. In this case we're going to look at our data one minute at-a-time, with one-second resolution.
sstream = samplestream.samplestream(srv,query,60,60,-60)
Next, set up the span of our search. We're going to want to look back up to four days.
sstream.Span(datetime.datetime.now() - datetime.timedelta(days=4),datetime.datetime.now())
And finally, we need to kick it all off!
stoptime = None #Loop until we find an outage or hit the end of the span while True: #Get the next sample sample = sstream.NextSample() if sample is None: #We reached the end of the span break #If power dropped near-zero over this 30 seconds, we've found our target if sample.data['Wind Turbine #1 Power'].min() < 0.1: stoptime = sample.time break if stoptime == False: print("No Stoppage Found") else: print("Stopped At " + str(stoptime))
This code walks through the samples until it finds one with a minimum value of 0.1. The power dropping to zero tells us the turbine was offline.
Other Examples
This is an example of a problem with unbounded timeframes - where we wanted to find something without having a good idea of when it happened. Because SampleStream queries the range piece-by-piece and only if needed, you can scan large time-ranges for events.
Another key application is with very fine time resolution, where you want to scan a particular period of time for events that are measured in milliseconds. Even though you'll usually be working with fixed periods of time, the volume of data is still very large - SampleStream allows you to be efficient with memory and server resources, and drop-out early if you've found what you're interested in.
And the final application is in AI - if you want to predict, model or classify something using a Machine Learning model that uses data over time, SampleStream makes it quite easy to extract the data to train and test your model.
See the SampleStream Class Reference.