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>
<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:value-of select="position() - 1"/>
<xsl:value-of select="position()"/>
</xsl:variable>
<!-- Times of surrounding waypoints -->
<xsl:variable name="timefirst">
<xsl:choose>
<xsl:when test="../sample[position() = $position - 1 - $events]/@time != ''">
<xsl:call-template name="time2sec">
<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:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="timesecond">
<xsl:choose>
<xsl:when test="../sample[position() = $position - $events]/@time != ''">
<xsl:call-template name="time2sec">
<xsl:with-param name="time">
<xsl:value-of select="./@time"/>
<xsl:value-of select="../sample[position() = $position - $events]/@time"/>
</xsl:with-param>
</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:otherwise>
<xsl:value-of select="0"/>
@ -223,31 +233,39 @@
<!-- Depths of surrounding waypoints -->
<xsl:variable name="depthfirst">
<xsl:choose>
<xsl:when test="../sample[position() = $position - 1 - $events]/@depth != ''">
<xsl:call-template name="depth2mm">
<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:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="depthsecond">
<xsl:choose>
<xsl:when test="../sample[position() = $position - $events]/@depth != ''">
<xsl:call-template name="depth2mm">
<xsl:with-param name="depth">
<xsl:value-of select="./@depth"/>
<xsl:value-of select="../sample[position() = $position - $events]/@depth"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Approximated waypoints -->
<xsl:variable name="timesec">
<xsl:call-template name="time2sec">
<xsl:with-param name="time">
<xsl:value-of select="./@time"/>
</xsl:with-param>
</xsl:call-template>
<xsl:variable name="time">
<xsl:value-of select="substring-before(@time, ':') * 60 + substring-before(substring-after(@time, ':'), ' ')"/>
</xsl:variable>
<!-- Crafting waypoints for events in-between samples -->
<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)]">
<xsl:if test="$timesecond != $time">
<waypoint>
<depth>
<xsl:call-template name="approximatedepth">
@ -273,13 +291,7 @@
</xsl:call-template>
</depth>
<divetime>
<xsl:call-template name="time2sec">
<xsl:with-param name="time">
<xsl:value-of select="@time"/>
</xsl:with-param>
</xsl:call-template>
</divetime>
<divetime><xsl:value-of select="$time"/></divetime>
<xsl:if test="@name = 'gaschange'">
<switchmix>
@ -302,8 +314,9 @@
</xsl:if>
</waypoint>
</xsl:for-each>
<!-- Approximated waypoints -->
</xsl:if>
</xsl:when>
<xsl:otherwise>
<!-- Recorded waypoints and events occurring at the exact same time -->
<waypoint>
@ -356,6 +369,8 @@
</xsl:for-each>
<!-- Recorded waypoints -->
</waypoint>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</samples>