[PATCH 1/2] Add support for Shearwater Desktop XML logs

Miika Turkia miika.turkia at gmail.com
Sat Feb 8 04:00:53 UTC 2014


Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
 subsurface.qrc           |   1 +
 xslt/commonTemplates.xsl |  40 +++++++++++++++++
 xslt/shearwater.xslt     | 110 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 xslt/shearwater.xslt

diff --git a/subsurface.qrc b/subsurface.qrc
index 20cd4dd..7e9e03e 100644
--- a/subsurface.qrc
+++ b/subsurface.qrc
@@ -43,5 +43,6 @@
         <file>xslt/uddf.xslt</file>
         <file>xslt/sensuscsv.xslt</file>
         <file>xslt/manualcsv2xml.xslt</file>
+        <file>xslt/shearwater.xslt</file>
  </qresource>
  </RCC>
diff --git a/xslt/commonTemplates.xsl b/xslt/commonTemplates.xsl
index a238d11..9900e44 100644
--- a/xslt/commonTemplates.xsl
+++ b/xslt/commonTemplates.xsl
@@ -165,4 +165,44 @@
     <xsl:value-of select="concat(floor($depth div 1000), '.', format-number($depth mod 1000, '00'))"/>
   </xsl:template>
 
+  <!-- Convert date format "Sun Jan 19 11:02:56 2014 UTC" => 2014-1-19
+       11:02 -->
+  <xsl:template name="convertDate">
+    <xsl:param name="dateTime"/>
+
+    <xsl:variable name="mnth">
+      <xsl:value-of select="substring-before(substring-after($dateTime, ' '), ' ')"/>
+    </xsl:variable>
+
+    <xsl:variable name="month">
+      <xsl:choose>
+        <xsl:when test="$mnth = 'Jan'">1</xsl:when>
+        <xsl:when test="$mnth = 'Feb'">2</xsl:when>
+        <xsl:when test="$mnth = 'Mar'">3</xsl:when>
+        <xsl:when test="$mnth = 'Apr'">4</xsl:when>
+        <xsl:when test="$mnth = 'May'">5</xsl:when>
+        <xsl:when test="$mnth = 'Jun'">6</xsl:when>
+        <xsl:when test="$mnth = 'Jul'">7</xsl:when>
+        <xsl:when test="$mnth = 'Aug'">8</xsl:when>
+        <xsl:when test="$mnth = 'Sept'">9</xsl:when>
+        <xsl:when test="$mnth = 'Oct'">10</xsl:when>
+        <xsl:when test="$mnth = 'Nov'">11</xsl:when>
+        <xsl:when test="$mnth = 'Dec'">12</xsl:when>
+      </xsl:choose>
+    </xsl:variable>
+
+    <xsl:variable name="year">
+      <xsl:value-of select="substring-before(substring-after(substring-after($dateTime, ':'), ' '), ' ')"/>
+    </xsl:variable>
+
+    <xsl:variable name="day">
+      <xsl:value-of select="substring-before(substring-after(substring-after($dateTime, ' '), ' '), ' ')"/>
+    </xsl:variable>
+
+    <xsl:variable name="time">
+      <xsl:value-of select="substring-before(substring-after(substring-after(substring-after($dateTime, ' '), ' '), ' '), ' ')"/>
+    </xsl:variable>
+
+    <xsl:value-of select="concat($year, '-', $month, '-', $day, ' ', $time)"/>
+  </xsl:template>
 </xsl:stylesheet>
diff --git a/xslt/shearwater.xslt b/xslt/shearwater.xslt
new file mode 100644
index 0000000..ae6501a
--- /dev/null
+++ b/xslt/shearwater.xslt
@@ -0,0 +1,110 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+  <xsl:strip-space elements="*"/>
+  <xsl:output method="xml" indent="yes"/>
+  <xsl:include href="commonTemplates.xsl"/>
+
+  <xsl:template match="/">
+    <divelog program='subsurface-import' version='2'>
+      <dives>
+        <xsl:apply-templates select="/dive/diveLog"/>
+      </dives>
+    </divelog>
+  </xsl:template>
+
+  <xsl:template match="diveLog">
+    <xsl:variable name="units">
+      <xsl:choose>
+        <xsl:when test="imperialUnits = 'true'">
+          <xsl:value-of select="'imperial'"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="'metric'"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+
+    <dive>
+      <xsl:attribute name="number">
+        <xsl:value-of select="number"/>
+      </xsl:attribute>
+
+      <xsl:variable name="datetime">
+        <xsl:call-template name="convertDate">
+          <xsl:with-param name="dateTime">
+            <xsl:value-of select="startDate"/>
+          </xsl:with-param>
+        </xsl:call-template>
+      </xsl:variable>
+      <xsl:attribute name="date">
+        <xsl:value-of select="substring-before($datetime, ' ')"/>
+      </xsl:attribute>
+      <xsl:attribute name="time">
+        <xsl:value-of select="substring-after($datetime, ' ')"/>
+      </xsl:attribute>
+
+      <xsl:attribute name="duration">
+        <xsl:value-of select="concat(maxTime, ' min')"/>
+      </xsl:attribute>
+
+      <depth>
+        <xsl:attribute name="max">
+          <xsl:choose>
+            <xsl:when test="$units = 'imperial'">
+              <xsl:value-of select="maxDepth * 0.3048"/>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:value-of select="maxDepth"/>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:attribute>
+      </depth>
+
+      <surface>
+        <xsl:attribute name="pressure">
+          <xsl:value-of select="concat(startSurfacePressure div 1000, ' bar')"/>
+        </xsl:attribute>
+      </surface>
+
+      <divecomputer>
+        <xsl:attribute name="model">
+          <xsl:value-of select="'Shearwater'"/>
+        </xsl:attribute>
+        <xsl:attribute name="deviceid">
+          <xsl:value-of select="computerSerial"/>
+        </xsl:attribute>
+      </divecomputer>
+
+      <xsl:for-each select="diveLogRecords/diveLogRecord">
+        <sample>
+          <xsl:attribute name="time">
+            <xsl:call-template name="sec2time">
+              <xsl:with-param name="timeSec">
+                <xsl:value-of select="currentTime"/>
+              </xsl:with-param>
+            </xsl:call-template>
+          </xsl:attribute>
+          <xsl:attribute name="depth">
+            <xsl:choose>
+              <xsl:when test="$units = 'imperial'">
+                <xsl:value-of select="format-number(currentDepth * 0.3048, '0.00')"/>
+              </xsl:when>
+              <xsl:otherwise>
+                <xsl:value-of select="currentDepth"/>
+              </xsl:otherwise>
+            </xsl:choose>
+          </xsl:attribute>
+          <xsl:attribute name="temp">
+            <xsl:choose>
+              <xsl:when test="$units = 'imperial'">
+                <xsl:value-of select="concat(format-number((waterTemp - 32) * 5 div 9, '0.0'), ' C')"/>
+              </xsl:when>
+              <xsl:otherwise>
+                <xsl:value-of select="waterTemp"/>
+              </xsl:otherwise>
+            </xsl:choose>
+          </xsl:attribute>
+        </sample>
+      </xsl:for-each>
+    </dive>
+  </xsl:template>
+</xsl:stylesheet>
-- 
1.8.3.2



More information about the subsurface mailing list