Optimize UDDF export

Writing the samples/waypoints to UDDF export in a totally new way.
Previously the preparations for approximating waypoints was done for
every sample, now only for the events.

A few days ago it took 36 seconds for my test set of 8 dives to export
to UDDF.  This optimization round took it down from 0m4.745s to
0m0.253s.

Fixes #508

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2014-05-03 07:51:28 +03:00 committed by Dirk Hohndel
parent 3e17690525
commit 088017f67c

View file

@ -186,34 +186,44 @@
</informationbeforedive> </informationbeforedive>
<samples> <samples>
<xsl:for-each select="./divecomputer[1]/sample">
<!-- Position of previous waypoint --> <xsl:for-each select="divecomputer[1]/event | divecomputer[1]/sample">
<xsl:sort select="substring-before(@time, ':') * 60 + substring-before(substring-after(@time, ':'), ' ')" data-type="number" order="ascending"/>
<xsl:variable name="events">
<xsl:value-of select="count(preceding-sibling::event)"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="name() = 'event'">
<xsl:variable name="position"> <xsl:variable name="position">
<xsl:value-of select="position() - 1"/> <xsl:value-of select="position()"/>
</xsl:variable> </xsl:variable>
<!-- Times of surrounding waypoints --> <!-- Times of surrounding waypoints -->
<xsl:variable name="timefirst"> <xsl:variable name="timefirst">
<xsl:choose>
<xsl:when test="../sample[position() = $position - 1 - $events]/@time != ''">
<xsl:call-template name="time2sec"> <xsl:call-template name="time2sec">
<xsl:with-param name="time"> <xsl:with-param name="time">
<xsl:value-of select="../sample[position() = $position]/@time"/> <xsl:value-of select="../sample[position() = $position - 1 - $events]/@time"/>
</xsl:with-param> </xsl:with-param>
</xsl:call-template> </xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable> </xsl:variable>
<xsl:variable name="timesecond"> <xsl:variable name="timesecond">
<xsl:choose>
<xsl:when test="../sample[position() = $position - $events]/@time != ''">
<xsl:call-template name="time2sec"> <xsl:call-template name="time2sec">
<xsl:with-param name="time"> <xsl:with-param name="time">
<xsl:value-of select="./@time"/> <xsl:value-of select="../sample[position() = $position - $events]/@time"/>
</xsl:with-param> </xsl:with-param>
</xsl:call-template> </xsl:call-template>
</xsl:variable>
<!-- Time difference between surrounding waypoints -->
<xsl:variable name="delta">
<xsl:choose>
<xsl:when test="$timefirst &gt;= 0">
<xsl:value-of select="$timesecond - $timefirst"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="0"/> <xsl:value-of select="0"/>
@ -223,31 +233,39 @@
<!-- Depths of surrounding waypoints --> <!-- Depths of surrounding waypoints -->
<xsl:variable name="depthfirst"> <xsl:variable name="depthfirst">
<xsl:choose>
<xsl:when test="../sample[position() = $position - 1 - $events]/@depth != ''">
<xsl:call-template name="depth2mm"> <xsl:call-template name="depth2mm">
<xsl:with-param name="depth"> <xsl:with-param name="depth">
<xsl:value-of select="../sample[position() = $position]/@depth"/> <xsl:value-of select="../sample[position() = $position - 1 - $events]/@depth"/>
</xsl:with-param> </xsl:with-param>
</xsl:call-template> </xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable> </xsl:variable>
<xsl:variable name="depthsecond"> <xsl:variable name="depthsecond">
<xsl:choose>
<xsl:when test="../sample[position() = $position - $events]/@depth != ''">
<xsl:call-template name="depth2mm"> <xsl:call-template name="depth2mm">
<xsl:with-param name="depth"> <xsl:with-param name="depth">
<xsl:value-of select="./@depth"/> <xsl:value-of select="../sample[position() = $position - $events]/@depth"/>
</xsl:with-param> </xsl:with-param>
</xsl:call-template> </xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable> </xsl:variable>
<!-- Approximated waypoints --> <xsl:variable name="time">
<xsl:variable name="timesec"> <xsl:value-of select="substring-before(@time, ':') * 60 + substring-before(substring-after(@time, ':'), ' ')"/>
<xsl:call-template name="time2sec">
<xsl:with-param name="time">
<xsl:value-of select="./@time"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable> </xsl:variable>
<!-- Crafting waypoints for events in-between samples --> <xsl:if test="$timesecond != $time">
<xsl:for-each select="preceding-sibling::event[substring-before(@time, ':') * 60 + substring-before(substring-after(@time, ':'), ' ')&lt;$timesec and substring-before(@time, ':') * 60 + substring-before(substring-after(@time, ':'), ' ')&gt;($timesec - $delta)]">
<waypoint> <waypoint>
<depth> <depth>
<xsl:call-template name="approximatedepth"> <xsl:call-template name="approximatedepth">
@ -273,13 +291,7 @@
</xsl:call-template> </xsl:call-template>
</depth> </depth>
<divetime> <divetime><xsl:value-of select="$time"/></divetime>
<xsl:call-template name="time2sec">
<xsl:with-param name="time">
<xsl:value-of select="@time"/>
</xsl:with-param>
</xsl:call-template>
</divetime>
<xsl:if test="@name = 'gaschange'"> <xsl:if test="@name = 'gaschange'">
<switchmix> <switchmix>
@ -302,8 +314,9 @@
</xsl:if> </xsl:if>
</waypoint> </waypoint>
</xsl:for-each> </xsl:if>
<!-- Approximated waypoints --> </xsl:when>
<xsl:otherwise>
<!-- Recorded waypoints and events occurring at the exact same time --> <!-- Recorded waypoints and events occurring at the exact same time -->
<waypoint> <waypoint>
@ -356,6 +369,8 @@
</xsl:for-each> </xsl:for-each>
<!-- Recorded waypoints --> <!-- Recorded waypoints -->
</waypoint> </waypoint>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each> </xsl:for-each>
</samples> </samples>