this should fix the upload of manually added dives to divelogs.de

miika
From 8c8d47195dfc7c45b7c5492b81f7c565f641750a Mon Sep 17 00:00:00 2001
From: Miika Turkia <[email protected]>
Date: Tue, 8 Apr 2014 23:08:58 +0300
Subject: [PATCH 2/2] No negative depth on divelogs.de export

Crafting depth samples produced a negative depth for the last sample.
This patch checks that negative last sample is ignored. (This occurred
when last manual sample is not full minutes.)

Signed-off-by: Miika Turkia <[email protected]>
---
 xslt/divelogs-export.xslt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/xslt/divelogs-export.xslt b/xslt/divelogs-export.xslt
index 287b28c..614fafd 100644
--- a/xslt/divelogs-export.xslt
+++ b/xslt/divelogs-export.xslt
@@ -214,11 +214,13 @@
         </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
-        <SAMPLE>
-          <DEPTH>
-            <xsl:value-of select="$curdepth div 1000"/>
-          </DEPTH>
-        </SAMPLE>
+        <xsl:if test="$curdepth &gt; 0">
+          <SAMPLE>
+            <DEPTH>
+              <xsl:value-of select="$curdepth div 1000"/>
+            </DEPTH>
+          </SAMPLE>
+        </xsl:if>
       </xsl:otherwise>
     </xsl:choose>
 
-- 
1.8.3.2

From ab77981792e9b0ae5013077a42408e32f6698a10 Mon Sep 17 00:00:00 2001
From: Miika Turkia <[email protected]>
Date: Tue, 8 Apr 2014 22:31:45 +0300
Subject: [PATCH 1/2] Create synthetic depth samples for manual dives

This patch creates artificial depth samples for manually entered dives
every 60 seconds. This is used for export to divelogs.de.

Fixes #486

Signed-off-by: Miika Turkia <[email protected]>
---
 xslt/divelogs-export.xslt | 116 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 110 insertions(+), 6 deletions(-)

diff --git a/xslt/divelogs-export.xslt b/xslt/divelogs-export.xslt
index cfd0f4c..287b28c 100644
--- a/xslt/divelogs-export.xslt
+++ b/xslt/divelogs-export.xslt
@@ -93,6 +93,17 @@
     <WATERTEMPMAXDEPTH>
       <xsl:value-of select="substring-before(node()/temperature/@water, ' ')"/>
     </WATERTEMPMAXDEPTH>
+    <xsl:variable name="manual">
+      <xsl:choose>
+        <xsl:when test="divecomputer/@model = 'manually added dive'">
+          <xsl:value-of select="1"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="0"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+
     <SAMPLEINTERVAL>
       <xsl:variable name="first">
         <xsl:call-template name="time2sec">
@@ -108,16 +119,109 @@
           </xsl:with-param>
         </xsl:call-template>
       </xsl:variable>
-      <xsl:value-of select="$second - $first"/>
+      <xsl:choose>
+        <xsl:when test="$manual = 1">
+          <xsl:value-of select="$second - $first"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="60"/>
+        </xsl:otherwise>
+      </xsl:choose>
     </SAMPLEINTERVAL>
     <xsl:for-each select="divecomputer[1]/sample">
-      <SAMPLE>
-        <DEPTH>
-          <xsl:value-of select="substring-before(./@depth, ' ')"/>
-        </DEPTH>
-      </SAMPLE>
+      <xsl:choose>
+        <xsl:when test="$manual = 1 and @time != '0:00 min'">
+          <xsl:variable name="timesecond">
+            <xsl:call-template name="time2sec">
+              <xsl:with-param name="time" select="@time"/>
+            </xsl:call-template>
+          </xsl:variable>
+          <xsl:variable name="timefirst">
+            <xsl:call-template name="time2sec">
+              <xsl:with-param name="time" select="preceding-sibling::sample[1]/@time"/>
+            </xsl:call-template>
+          </xsl:variable>
+          <xsl:call-template name="while">
+            <xsl:with-param name="until">
+              <xsl:value-of select="($timesecond - $timefirst) div 60 - 1"/>
+            </xsl:with-param>
+            <xsl:with-param name="count">
+              <xsl:value-of select="0"/>
+            </xsl:with-param>
+            <xsl:with-param name="timefirst">
+              <xsl:value-of select="$timefirst"/>
+            </xsl:with-param>
+            <xsl:with-param name="timesecond">
+              <xsl:value-of select="$timesecond"/>
+            </xsl:with-param>
+            <xsl:with-param name="depthsecond">
+              <xsl:call-template name="depth2mm">
+                <xsl:with-param name="depth">
+                  <xsl:value-of select="./@depth"/>
+                </xsl:with-param>
+              </xsl:call-template>
+            </xsl:with-param>
+            <xsl:with-param name="depthfirst">
+              <xsl:call-template name="depth2mm">
+                <xsl:with-param name="depth">
+                  <xsl:value-of select="preceding-sibling::sample[1]/@depth"/>
+                </xsl:with-param>
+              </xsl:call-template>
+            </xsl:with-param>
+          </xsl:call-template>
+          <!--  <name select="{concat(@time, ' - ', preceding-sibling::sample[1]/@time)}"/>-->
+        </xsl:when>
+        <xsl:otherwise>
+          <SAMPLE>
+            <DEPTH>
+              <xsl:value-of select="substring-before(./@depth, ' ')"/>
+            </DEPTH>
+          </SAMPLE>
+        </xsl:otherwise>
+      </xsl:choose>
     </xsl:for-each>
     </DIVELOGSDATA>
   </xsl:template>
 
+  <xsl:template name="while">
+    <xsl:param name="timefirst"/>
+    <xsl:param name="timesecond"/>
+    <xsl:param name="depthfirst"/>
+    <xsl:param name="depthsecond"/>
+    <xsl:param name="count"/>
+    <xsl:param name="until"/>
+
+    <xsl:variable name="curdepth">
+      <xsl:value-of select="format-number(((($timefirst + 60) - $timefirst) div ($timesecond - $timefirst) * ($depthsecond - $depthfirst) + $depthfirst), '#.##')"/>
+    </xsl:variable>
+    <xsl:variable name="curtime">
+      <xsl:value-of select="$timefirst + 60"/>
+    </xsl:variable>
+    <xsl:choose>
+      <xsl:when test="$count &lt; $until">
+        <SAMPLE>
+          <DEPTH>
+            <xsl:value-of select="$curdepth div 1000"/>
+          </DEPTH>
+        </SAMPLE>
+        <xsl:call-template name="while">
+          <xsl:with-param name="timefirst" select="$curtime"/>
+          <xsl:with-param name="timesecond" select="$timesecond"/>
+          <xsl:with-param name="depthfirst" select="$curdepth"/>
+          <xsl:with-param name="depthsecond" select="$depthsecond"/>
+          <xsl:with-param name="count" select="$count + 1"/>
+          <xsl:with-param name="until" select="$until"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <SAMPLE>
+          <DEPTH>
+            <xsl:value-of select="$curdepth div 1000"/>
+          </DEPTH>
+        </SAMPLE>
+      </xsl:otherwise>
+    </xsl:choose>
+
+  </xsl:template>
+
 </xsl:stylesheet>
-- 
1.8.3.2

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to