diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2013-02-27 18:05:40 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-02-27 09:03:17 -0800 |
commit | cc9686016536ae6f2d7b5c4dd51a21cf3ce4d797 (patch) | |
tree | 14f6204c43e812f9751ac6626c46404d66079d92 /xslt/MacDive.xslt | |
parent | b54dacbeb2f8711495bb4998d5a94268d47804b2 (diff) | |
download | subsurface-cc9686016536ae6f2d7b5c4dd51a21cf3ce4d797.tar.gz |
MacDive import improvement
MacDive reports non-existent values as zero and in Imperial units it
would be 32F. This patch will try to make an educated guess whether we
have the proper temperature and pressure readings and ignore the zero
fields if it seems that there are no real samples from the dive
computer.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'xslt/MacDive.xslt')
-rw-r--r-- | xslt/MacDive.xslt | 91 |
1 files changed, 74 insertions, 17 deletions
diff --git a/xslt/MacDive.xslt b/xslt/MacDive.xslt index 35a5a783d..f3c87386a 100644 --- a/xslt/MacDive.xslt +++ b/xslt/MacDive.xslt @@ -30,6 +30,19 @@ <xsl:template match="dive"> <xsl:variable name="units" select="/dives/units"/> + + <!-- Count the amount of temeprature samples during the dive --> + <xsl:variable name="temperatureSamples"> + <xsl:call-template name="temperatureSamples" select="/dives/dive/samples"> + <xsl:with-param name="units" select="$units"/> + </xsl:call-template> + </xsl:variable> + + <!-- Count the amount of pressure samples during the dive --> + <xsl:variable name="pressureSamples"> + <xsl:call-template name="pressureSamples" select="/dives/dive/samples"/> + </xsl:variable> + <dive> <xsl:attribute name="number"> <xsl:choose> @@ -122,12 +135,14 @@ </xsl:for-each> </location> - <xsl:if test="sitelat != ''"> + <!-- This will discard GPS coordinates of 0 0 but I suppose that + is better than all non-gps dives to be in that location --> + <xsl:if test="sitelat != 0"> <gps> <xsl:value-of select="concat(sitelat, ' ', sitelon)"/> </gps> </xsl:if> - <xsl:if test="siteLat != ''"> + <xsl:if test="siteLat != 0"> <gps> <xsl:value-of select="concat(siteLat, ' ', siteLon)"/> </gps> @@ -163,7 +178,7 @@ <xsl:value-of select="concat(helium, '%')"/> </xsl:attribute> </xsl:if> - <xsl:if test="pressureStart != ''"> + <xsl:if test="pressureStart > 0"> <xsl:attribute name="start"> <xsl:call-template name="pressureConvert"> <xsl:with-param name="number" select="pressureStart"/> @@ -171,7 +186,7 @@ </xsl:call-template> </xsl:attribute> </xsl:if> - <xsl:if test="pressureEnd != ''"> + <xsl:if test="pressureEnd > 0"> <xsl:attribute name="end"> <xsl:call-template name="pressureConvert"> <xsl:with-param name="number" select="pressureEnd"/> @@ -179,7 +194,7 @@ </xsl:call-template> </xsl:attribute> </xsl:if> - <xsl:if test="tankSize != ''"> + <xsl:if test="tankSize > 0"> <xsl:attribute name="size"> <xsl:call-template name="sizeConvert"> <xsl:with-param name="singleSize" select="tankSize"/> @@ -189,7 +204,7 @@ </xsl:call-template> </xsl:attribute> </xsl:if> - <xsl:if test="workingPressure != ''"> + <xsl:if test="workingPressure > 0"> <xsl:attribute name="workpressure"> <xsl:call-template name="pressureConvert"> <xsl:with-param name="number" select="workingPressure"/> @@ -206,37 +221,63 @@ </xsl:for-each> <temperature> + + <!-- If we have temperature reading and it is non-zero, we use + it. If the temperature is zero, we only use it if we have + temperature samples from the dive. --> <xsl:if test="tempAir != ''"> - <xsl:attribute name="air"> + <xsl:variable name="air"> <xsl:call-template name="tempConvert"> <xsl:with-param name="temp" select="tempAir"/> <xsl:with-param name="units" select="$units"/> </xsl:call-template> - </xsl:attribute> + </xsl:variable> + <xsl:if test="substring-before($air, ' ') != 0 or $temperatureSamples > 0"> + <xsl:attribute name="air"> + <xsl:value-of select="$air"/> + </xsl:attribute> + </xsl:if> </xsl:if> + <xsl:if test="tempLow != ''"> - <xsl:attribute name="water"> + <xsl:variable name="water"> <xsl:call-template name="tempConvert"> <xsl:with-param name="temp" select="tempLow"/> <xsl:with-param name="units" select="$units"/> </xsl:call-template> - </xsl:attribute> + </xsl:variable> + <xsl:if test="substring-before($water, ' ') != 0 or $temperatureSamples > 0"> + <xsl:attribute name="water"> + <xsl:value-of select="$water"/> + </xsl:attribute> + </xsl:if> </xsl:if> + <xsl:if test="tempair != ''"> - <xsl:attribute name="air"> + <xsl:variable name="air"> <xsl:call-template name="tempConvert"> <xsl:with-param name="temp" select="tempair"/> <xsl:with-param name="units" select="$units"/> </xsl:call-template> - </xsl:attribute> + </xsl:variable> + <xsl:if test="substring-before($air, ' ') != 0 or $temperatureSamples > 0"> + <xsl:attribute name="air"> + <xsl:value-of select="$air"/> + </xsl:attribute> + </xsl:if> </xsl:if> <xsl:if test="templow != ''"> - <xsl:attribute name="water"> + <xsl:variable name="water"> <xsl:call-template name="tempConvert"> <xsl:with-param name="temp" select="temlow"/> <xsl:with-param name="units" select="$units"/> </xsl:call-template> - </xsl:attribute> + </xsl:variable> + <xsl:if test="substring-before($water, ' ') != 0 or $temperatureSamples > 0"> + <xsl:attribute name="water"> + <xsl:value-of select="$water"/> + </xsl:attribute> + </xsl:if> </xsl:if> </temperature> @@ -290,7 +331,7 @@ <xsl:with-param name="units" select="$units"/> </xsl:call-template> </xsl:attribute> - <xsl:if test="pressure != ''"> + <xsl:if test="pressure != '' and $pressureSamples > 0"> <xsl:attribute name="pressure"> <xsl:call-template name="pressureConvert"> <xsl:with-param name="number" select="pressure"/> @@ -298,7 +339,7 @@ </xsl:call-template> </xsl:attribute> </xsl:if> - <xsl:if test="temperature != ''"> + <xsl:if test="temperature != '' and $temperatureSamples > 0"> <xsl:attribute name="temp"> <xsl:call-template name="tempConvert"> <xsl:with-param name="temp" select="temperature"/> @@ -393,7 +434,7 @@ </xsl:template> <!-- end convert pressure --> - <!-- convert temperature to C --> + <!-- convert temperature from F to C --> <xsl:template name="tempConvert"> <xsl:param name="temp"/> <xsl:param name="units"/> @@ -459,4 +500,20 @@ </xsl:template> <!-- end convert weight --> + <xsl:template name="temperatureSamples"> + <xsl:param name="units"/> + <xsl:choose> + <xsl:when test="$units = 'Imperial'"> + <xsl:value-of select="count(descendant::temperature[. != 32])"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="count(descendant::temperature[. != 0])"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <xsl:template name="pressureSamples"> + <xsl:value-of select="count(descendant::pressure[. > 0])"/> + </xsl:template> + </xsl:stylesheet> |