[PATCH] Fix MacDive import to convert Imperial temperature

Miika Turkia miika.turkia at gmail.com
Tue Feb 26 21:39:05 PST 2013


So we should do this for temperatures as well as pressure readings,
judging from the sample file I just received.

I did a bit of prototyping on this and it turns out that it can be
done with XSLT. However, the real implementation has to wait until
after work...

miika

On Wed, Feb 27, 2013 at 7:14 AM, Dirk Hohndel <dirk at hohndel.org> wrote:
> I think we should ignore a dive with all 0°C samples.
> Which I don't think you can do in xslt
>
> /D
>
> --
> From my Nexus 7. Please excuse brevity and text prediction errors.
>
>
>
>
> On February 26, 2013 9:09:22 PM Miika Turkia <miika.turkia at gmail.com> wrote:
>>
>> It looks like we will have to do a bit more magic with the MacDive
>> import. The last sample we received has only the "header" water
>> temperature set and all the samples are 0C - presumably meaning that
>> there is no data for that. Giving Subsurface the following input:
>>
>>       <temperature air="0.0 C" water="8.0 C"/>
>>       <divemaster/>
>>       <buddy/>
>>       <sample time="0:20 min" depth="2.700528 m" pressure="0 bar"
>> temp="0.0 C"/>
>>       <sample time="0:40 min" depth="4.09956 m" pressure="0 bar" temp="0.0
>> C"/>
>>       <sample time="1:00 min" depth="4.401312 m" pressure="0 bar"
>> temp="0.0 C"/>
>>
>> we still end up with water temperature as zero in GUI because
>> sanitation function overrides the temperature tag's water temperature
>> with the "actual" readings. So would it be safe enough to ignore
>> temperature readings of 0C in MacDive import? Or what is the magic to
>> apply here?
>>
>> miika
>>
>> On Wed, Feb 27, 2013 at 7:01 AM, Miika Turkia <miika.turkia at gmail.com>
>> wrote:
>> > MacDive import needs to convert temperatures to Celcius. However, it
>> > seems that MacDive reports no reading as 32F (and probably 0C when using
>> > Metric). There is no way of knowing whether we have no reading or
>> > the temperature is actually zero, so we use the given temperature
>> > currently as 0C is a valid temperature...
>> >
>> > Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
>> > ---
>> >  xslt/MacDive.xslt |   41 ++++++++++++++++++++++++++++++++++++-----
>> >  1 file changed, 36 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/xslt/MacDive.xslt b/xslt/MacDive.xslt
>> > index c7c4065..35a5a78 100644
>> > --- a/xslt/MacDive.xslt
>> > +++ b/xslt/MacDive.xslt
>> > @@ -208,22 +208,34 @@
>> >        <temperature>
>> >          <xsl:if test="tempAir != ''">
>> >            <xsl:attribute name="air">
>> > -            <xsl:value-of select="concat(tempAir, ' C')"/>
>> > +            <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:if>
>> >          <xsl:if test="tempLow != ''">
>> >            <xsl:attribute name="water">
>> > -            <xsl:value-of select="concat(tempLow, ' C')"/>
>> > +            <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:if>
>> >          <xsl:if test="tempair != ''">
>> >            <xsl:attribute name="air">
>> > -            <xsl:value-of select="concat(tempair, ' C')"/>
>> > +            <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:if>
>> >          <xsl:if test="templow != ''">
>> >            <xsl:attribute name="water">
>> > -            <xsl:value-of select="concat(templow, ' C')"/>
>> > +            <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:if>
>> >        </temperature>
>> > @@ -288,7 +300,10 @@
>> >            </xsl:if>
>> >            <xsl:if test="temperature != ''">
>> >              <xsl:attribute name="temp">
>> > -              <xsl:value-of select="concat(temperature, ' C')"/>
>> > +              <xsl:call-template name="tempConvert">
>> > +                <xsl:with-param name="temp" select="temperature"/>
>> > +                <xsl:with-param name="units" select="$units"/>
>> > +              </xsl:call-template>
>> >              </xsl:attribute>
>> >            </xsl:if>
>> >          </sample>
>> > @@ -378,6 +393,22 @@
>> >    </xsl:template>
>> >    <!-- end convert pressure -->
>> >
>> > +  <!-- convert temperature to C -->
>> > +  <xsl:template name="tempConvert">
>> > +    <xsl:param name="temp"/>
>> > +    <xsl:param name="units"/>
>> > +
>> > +    <xsl:choose>
>> > +      <xsl:when test="$units = 'Imperial'">
>> > +        <xsl:value-of select="concat(format-number(($temp - 32) * 5 div
>> > 9, '0.0'), ' C')"/>
>> > +      </xsl:when>
>> > +      <xsl:otherwise>
>> > +        <xsl:value-of select="concat($temp, ' C')"/>
>> > +      </xsl:otherwise>
>> > +    </xsl:choose>
>> > +  </xsl:template>
>> > +  <!-- end convert temperature -->
>> > +
>> >    <!-- convert time in seconds to minutes:seconds -->
>> >    <xsl:template name="timeConvert">
>> >      <xsl:param name="timeSec"/>
>> > --
>> > 1.7.9.5
>> >
>> _______________________________________________
>> subsurface mailing list
>> subsurface at hohndel.org
>> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
>
>
>


More information about the subsurface mailing list