It was on
my task list to provide an example where interpreting an XQuery with time &
frequency elements would be very difficult (for an editor, for example).
Symptoms
below.
We will be
searching for 3 or more occurrences within 30 second interval of
application/responsetime/threshold/breach where Subject is identical.
<?xml version="1.0" encoding="UTF-8"?>
<SymptomStore>
<Symptom>
<SymptomId>com/ca/symptom/1</SymptomId>
<SymptomType>application/responsetime/threshold/breach</SymptomType>
<CreationDate>2011-05-23T10:00:00</CreationDate>
<Confidence>ModerateConfidence</Confidence>
<Reporter>com/ca/application/apm</Reporter>
<Subject>APP1@server1.ca.com</Subject>
<Content></Content>
</Symptom>
<Symptom>
<SymptomId>com/ca/symptom/2</SymptomId>
<SymptomType>system/process/memory/threshold/breach</SymptomType>
<CreationDate>2011-05-23T10:01:00</CreationDate>
<Confidence>ModerateConfidence</Confidence>
<Reporter>com/ca/system/nsm</Reporter>
<Subject>APP1@server1.ca.com</Subject>
<Content></Content>
</Symptom>
<Symptom>
<SymptomId>com/ca/symptom/3</SymptomId>
<SymptomType>system/process/memory/threshold/breach</SymptomType>
<CreationDate>2011-05-23T10:02:00</CreationDate>
<Confidence>ModerateConfidence</Confidence>
<Reporter>com/ca/system/nsm</Reporter>
<Subject>APP2@server2.ca.com</Subject>
<Content></Content>
</Symptom>
<Symptom>
<SymptomId>com/ca/symptom/4</SymptomId>
<SymptomType>application/responsetime/threshold/breach</SymptomType>
<CreationDate>2011-05-23T10:00:15</CreationDate>
<Confidence>ModerateConfidence</Confidence>
<Reporter>com/ca/application/apm</Reporter>
<Subject>APP1@server1.ca.com</Subject>
<Content></Content>
</Symptom>
<Symptom>
<SymptomId>com/ca/symptom/5</SymptomId>
<SymptomType>application/responsetime/threshold/breach</SymptomType>
<CreationDate>2011-05-23T10:00:20</CreationDate>
<Confidence>ModerateConfidence</Confidence>
<Reporter>com/ca/application/apm</Reporter>
<Subject>APP1@server1.ca.com</Subject>
<Content></Content>
</Symptom>
</SymptomStore>
Here is one
possible xquery. Note: Some liberties were taken to keep simple.
let $s := doc('file:///c:/docs/_symptoms/symptomstore.xml')/SymptomStore/Symptom[SymptomType='application/responsetime/threshold/breach' and
Subject='APP1@server1.ca.com']
let $freq := count($s)
return
if ($freq >= 3) then (
if ((fn:seconds-from-dateTime($s[$freq]/CreationDate)
- fn:seconds-from-dateTime($s[1]/CreationDate))
<= 30) then (
$s
)
else
()
)
else
()
How is it possible to
consistently extract the time interval (30) and the frequency (3) from such an
xquery, for the purposes of rendering in an editor?