- Data Collection Query: Report light readings
from each sensor at the rate of one reading every 10 seconds.
Select Rstream (id, sample1(light) as light)
From Sensors [Range 10 Second
Slide 10 Second]
Group By id
Comments: sample1 is a user-defined relational-aggregate
that returns one value
uniformly at random from its input relation which in this case is the
bag of light readings over each successive ten minute interval.
- Light Monitoring Query: Sample data
from each sensor at the rate of one reading every second and monitor the
average light over the last 30 seconds.
SampleStream: Select Rstream (id, sample1(light) as light)
From Sensors [Range 1 Second
Slide 1 Second]
Group By id
AvgLight: Select Avg(light)
From SampleStream [Range 30 Second]
Comments: For readability we have specified the subquery for
producing the combined stream of one-second samples from all sensors
(SampleStream) separately. The subquery for
SampleStream uses the user-defined relational-aggregate sample1
from the Data Collection Query. The final result of the Light Monitoring
Query is the derived relation AvgLight as specified above.
- Event-Triggered Query: Whenever a
sensor reports a bird-detection event, sample data from all sensors within
10 meters of the event at the rate of one reading every second for 10
seconds and report the average light and temperature.
DelayedEventStream:
Select Dstream (*)
From Events [Range 10 Second]
Where type = 'BIRD-DETECT'
SampledSensorStream:
Select Rstream (id, location, sample1(light) as light,
sample1(temperature) as temp)
From Sensors [Range 1 Second
Slide 1 Second]
Group By id, location
Result:
Select Rstream (E.location, Avg(light) as light, Avg(temp) as temp)
From DelayedEventStream [Now] E,
SampledSensorStream [Range 10 Second] S
Where dist(E.location, S.location) < 10;
Comments: This query has been specified using two subqueries. The
first subquery produces DelayedEventStream which is the
Event stream delayed by 10 seconds. Each event is delayed by
10 seconds to allow all the readings for the event to be made. The second
subquery produces SampledSensorStream, the (sampled)
stream consisting of one reading per sensor per second. As expressed, the sampled
light and the sampled temperature may not correspond to a sensor reading
at the same time instant; however, a different user-defined
relational-aggregate can be used to solve this problem, if necessary.
Also, the second subquery assumes that
Sensor.location is functionally determined by
Sensor.id. The outermost query uses the user-defined function
dist that returns the distance in meters between two input
locations.
- Bird Counter Query: Keep a count of
the number of times birds have entered a particular nest.
Select Count(*)
From Events E
Where E.type = 'BIRD-ENTER' AND E.location = 'NEST-1012'
- Delta Compression Query: Report the
new light reading at a particular location every time it changes by 3.
Select Istream(delta_compr(light))
From Sensors
Where location = 'NEST-1012'
Comments: delta_compr is a user-defined
windowed-aggregate that outputs the
new light reading every time it changes by 3.
- Take Action Query: To keep birds and
animals away from the sensors, apply a low electric pulse whenever an
external body comes in contact with an active sensor on the field.
Select generate_pulse(location)
From Events E
Where E.type = 'EXTERNAL-CONTACT'
Comments:
generate_pulse is a user-defined function that
will make the sensor(s)
at location generate a low electric pulse.