Re: Looking for elegant solution to sensor / reading / alert database design.

From: Nilone <reaanb_at_gmail.com>
Date: Thu, 9 Dec 2010 15:57:39 -0800 (PST)
Message-ID: <15c92f81-f8d2-4f4e-bfe7-49c66ab19132_at_k21g2000vbd.googlegroups.com>


On Dec 9, 12:46 pm, "Mark S. (UK)" <ma..._at_someaccount.net> wrote:
> The upper and lower limit is the limits to which the measured element
> must stay between - and if it goes outside of these limits (for a
> configured length of time) an alert is generated.

Based on the suggestions in my previous post, you could use a view like the following to find the length of time sensors are out of bounds.

CREATE VIEW SensorLimitsExceeded AS
SELECT a.Sensor, a.Time, a.Reading, a.Time - b.Time AS AlertDuration   FROM SensorReadings cur, SensorReadings prv, SensorLimits lim

 WHERE cur.Sensor = prv.Sensor
   AND cur.Reading NOT BETWEEN lim.LowerLimit AND lim.UpperLimit
   AND prv.Time = (SELECT Max(hst.Time) FROM SensorReadings hst,
SensorLimits lmh
 WHERE hst.Sensor = cur.Sensor AND hst.Sensor = lmh.Sensor
   AND hst.Time < cur.Time
   AND hst.Reading BETWEEN lmh.LowerLimit AND lmh.UpperLimit)
Received on Fri Dec 10 2010 - 00:57:39 CET

Original text of this message