diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2013-12-24 18:08:19 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-12-24 08:20:06 -0800 |
commit | b07af31ea566eaa4237391ff3c1f7aae86f411a8 (patch) | |
tree | a4d31af257482bd91642171be3d82d9c0f4f564e /xslt | |
parent | 18f0489188422c3e835e5b6169fa8b65bfe27fdd (diff) | |
download | subsurface-b07af31ea566eaa4237391ff3c1f7aae86f411a8.tar.gz |
Try to detect whether DivingLog's samples are m/f
Seems that we can detect the unit of samples from DivingLog import when
comparing the maximum dive depth to the maximum recorded sample depth.
If sample is bigger, it is recorded in imperial. Of course this relies
on the assumption that the max depth of dive is recorded in metric unit,
but that seems to be the case, at least in the sample received.
It really does not make any sense to have both units in use for one dive
without any info on the unit used. But since that is the case, let's try
to cope with it.
Fixes #316
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'xslt')
-rw-r--r-- | xslt/DivingLog.xslt | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/xslt/DivingLog.xslt b/xslt/DivingLog.xslt index 4e7dc8b08..abf22d0d1 100644 --- a/xslt/DivingLog.xslt +++ b/xslt/DivingLog.xslt @@ -148,6 +148,30 @@ <xsl:value-of select="Comments"/> </notes> + <!-- Trying to detect if depth samples are in Imperial or Metric + units. This is based on an assumption that maximum depth of + a dive is recorded in metric and if samples contain bigger + values, they must be imperial. + --> + + <xsl:variable name="max"> + <xsl:for-each select="Profile/P/Depth"> + <xsl:sort select="." data-type="number" order="descending"/> + <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if> + </xsl:for-each> + </xsl:variable> + + <xsl:variable name="depthUnit"> + <xsl:choose> + <xsl:when test="$max > Depth + 1"> + <xsl:value-of select="'imperial'"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="'metric'"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + <divecomputer> <xsl:if test="Computer != ''"> <xsl:attribute name="model"> @@ -181,7 +205,14 @@ <xsl:value-of select="Press1"/> </xsl:attribute> <xsl:attribute name="depth"> - <xsl:value-of select="Depth"/> + <xsl:call-template name="depthConvert"> + <xsl:with-param name="depth"> + <xsl:value-of select="Depth"/> + </xsl:with-param> + <xsl:with-param name="depthUnit"> + <xsl:value-of select="$depthUnit"/> + </xsl:with-param> + </xsl:call-template> </xsl:attribute> </sample> </xsl:for-each> @@ -195,9 +226,17 @@ <!-- convert depth to meters --> <xsl:template name="depthConvert"> <xsl:param name="depth"/> + <xsl:param name="depthUnit"/> <xsl:if test="$depth != ''"> - <xsl:value-of select="concat($depth, ' m')"/> + <xsl:choose> + <xsl:when test="$depthUnit = 'imperial'"> + <xsl:value-of select="concat(format-number($depth div 3.2808, '##.#'), ' m')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="concat($depth, ' m')"/> + </xsl:otherwise> + </xsl:choose> </xsl:if> </xsl:template> <!-- end convert depth --> |