Skip to content

Instantly share code, notes, and snippets.

@pierre-ernst
Last active December 26, 2019 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierre-ernst/3c8b6fba9270125696c2afcdecfd600f to your computer and use it in GitHub Desktop.
Save pierre-ernst/3c8b6fba9270125696c2afcdecfd600f to your computer and use it in GitHub Desktop.
Garmin FoodPod sensor (FPS) calibration tool. Generates CSV data allowing to compare GPS/FPS distance measurements. Based on original idea from https://fellrnr.com/wiki/Garmin_Foot_Pod_Calibration
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tcdb="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"
xmlns:ext="http://www.garmin.com/xmlschemas/ActivityExtension/v2"
version="1.0"
>
<!--
Garmin FoodPod sensor (FPS) calibration tool.
Generates CSV data allowing to compare GPS/FPS distance measurements
Input = TCX file from Garmin running activity
new calibration factor = Actual distance / sensor distance * previous calibration factor
based on original idea from https://fellrnr.com/wiki/Garmin_Foot_Pod_Calibration
-->
<xsl:output method="text" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:text>&quot;Interval&quot;, &quot;GPS distance(m)&quot;, &quot;FPS distance(m)&quot;, "Cadence(spm)", "Stride Length(m)"&#10;</xsl:text>
<xsl:for-each
select="/tcdb:TrainingCenterDatabase/tcdb:Activities/tcdb:Activity/tcdb:Lap/tcdb:Track/tcdb:Trackpoint">
<xsl:if test="./tcdb:Extensions/ext:TPX/ext:Speed &gt; 0 and ./tcdb:Extensions/ext:TPX/ext:RunCadence &gt; 0">
<xsl:variable name="currentDistance" select="./tcdb:DistanceMeters"/>
<xsl:variable name="previousDistance"
select="preceding-sibling::tcdb:Trackpoint[1]/tcdb:DistanceMeters"/>
<xsl:variable name="currentTimestamp">
<xsl:call-template name="toSecondsInDay">
<xsl:with-param name="date" select="./tcdb:Time"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="previousTimestamp">
<xsl:call-template name="toSecondsInDay">
<xsl:with-param name="date" select="preceding-sibling::tcdb:Trackpoint[1]/tcdb:Time"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="gpsDistance" select="$currentDistance - $previousDistance"/>
<xsl:variable name="fpsDistance"
select="./tcdb:Extensions/ext:TPX/ext:Speed * ( $currentTimestamp - $previousTimestamp) "/>
<xsl:variable name="fpsCadence" select="2 * ./tcdb:Extensions/ext:TPX/ext:RunCadence"/>
<xsl:variable name="strideLength" select="./tcdb:Extensions/ext:TPX/ext:Speed div $fpsCadence * 60"/>
<xsl:if test="string(number($gpsDistance)) != 'NaN' and string(number($fpsDistance)) != 'NaN'">
<xsl:value-of
select="concat(position(),', ',$gpsDistance,', ',$fpsDistance,', ',$fpsCadence,', ',$strideLength)"/>
<xsl:text>&#10;</xsl:text>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="toSecondsInDay">
<xsl:param name="date"/>
<!-- e.g. 2019-12-21T14:51:36.000Z -->
<xsl:variable name="h" select="substring($date, 12, 2)"/>
<xsl:variable name="m" select="substring($date, 15, 2)"/>
<xsl:variable name="s" select="substring($date, 18, 2)"/>
<xsl:value-of select="$s + 60*$m + 60*60*$h"/>
</xsl:template>
</xsl:stylesheet>
@pierre-ernst
Copy link
Author

Screen Shot 2019-12-26 at 18 33 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment