Skip to content

Instantly share code, notes, and snippets.

@jogo3000
Created January 1, 2017 05:20
Show Gist options
  • Save jogo3000/e21e05f07728e01d2fa547cdadb4f8db to your computer and use it in GitHub Desktop.
Save jogo3000/e21e05f07728e01d2fa547cdadb4f8db to your computer and use it in GitHub Desktop.
BaseX xQuery for exporting a database of TCX moves to a csv file
(:
Outputs all Trackpoints in the BaseX database 'moves' in CSV format with columns in following order
ID - Activity identifier
SPORT - Sport (Running|Biking|Other)
TIMESTAMP - Timestamp as UNIX epoch
LAT - Latitude as degrees
LONG - Longitude as degrees
HR - Heart rate as BPM (integer)
ALT - Altitude as float
CAD - Cadence as integer
:)
declare function local:get-val($el as node()*) {
if (empty($el)) then (
<empty></empty>
) else (
$el
)
};
for $a in db:open('moves')//*:Activity
for $tp in $a/*/*/*:Trackpoint
let $ts := convert:dateTime-to-integer(xs:dateTime($tp/*:Time))
let $lat := local:get-val($tp/*/*:LatitudeDegrees)
let $long := local:get-val($tp/*/*:LongitudeDegrees)
let $hr := local:get-val($tp/*:HeartRateBpm/*:Value)
let $alt := local:get-val($tp/*:AltitudeMeters)
let $cad := local:get-val($tp/*:Cadence)
return string-join(($a/*:Id,$a/@Sport,$ts,$lat,$long,$hr,$alt,$cad), ",")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment