1

Given this trades.xml:

<trades>
 <trade stock="ACO" price="200" time="12:00:00.1"/>
 <trade stock="ACO" price="202" time="12:00:00.2"/>
 <trade stock="BCO" price="200" time="12:00:00.3"/>
 <trade stock="CCO" price="300" time="12:00:00.4"/>
 <trade stock="CCO" price="299" time="12:00:00.5"/>
 <trade stock="CCO" price="290" time="12:00:00.6"/>
 <trade stock="ACO" price="200" time="12:00:00.7"/>
 <trade stock="ACO" price="205" time="12:00:03.1"/>
</trades>

Do you know why this query doesn't work? I'd like to have sliding windows of one second and to see how many trades with stock "AC0" have been sold in that windows of 1 second:

let $onesec := xs:dayTimeDuration('PT1S')
for sliding window $w
in doc("C:\Users\Lorenzo Enzino Vinci\Desktop\seminarioMontesi\trades.xml")//trade
start $s when $s/@stock eq "ACO"
end next $n when $n/@time > ($s/@time + $onesec) (: ******************** :)
let $occurrences := count ($w[@stock eq $s/@stock])where $occurrences gt 1
return <run stock="{$s/@stock}"
occurrences="{$occurrences}"
time="{$s/@time}"/>

When I try to execute, it says:

"[XPTY0004] '+' operator: number expected, xs:dayTimeDuration found."
at line with (: ******************** :)

So – how can I sum timestamps?

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
SagittariusA
  • 5,289
  • 15
  • 73
  • 127
  • "this query doesn't work?" is no reasonable problem description. Please have a look on [how to provide an SSCCE](http://www.sscce.org) and revise your question (edit, do not post as comments), so somebody is able to help you. – Jens Erat May 29 '14 at 13:57

1 Answers1

2

The error occurs as you want to add a duration ($onesec) to a string ($s/@time). Cast the string (which luckily is in an appropriate format) into a time: $s/@time cast as xs:time + $onesec.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96