diff artifacts/doc/conf/meta-data.xml @ 8120:b57f4bcd0f6f

Remove code duplications in sedimentload datacage.
author "Tom Gottfried <tom@intevation.de>"
date Fri, 22 Aug 2014 13:19:02 +0200
parents a9a6414b3563
children 82af749d5ab3
line wrap: on
line diff
--- a/artifacts/doc/conf/meta-data.xml	Fri Aug 22 08:04:43 2014 +0200
+++ b/artifacts/doc/conf/meta-data.xml	Fri Aug 22 13:19:02 2014 +0200
@@ -1354,7 +1354,7 @@
                 d.lower        AS depth_lower,
                 d.upper        AS depth_upper,
                 p.description  || '&lt;BR&gt;' ||
-                'Tiefe: ' || d.lower || ' - ' || d.upper 
+                'Tiefe: ' || d.lower || ' - ' || d.upper
                     || ' cm &lt;BR&gt;' ||
                 'Zeitraum: ' AS info,
                 t.start_time AS syear,
@@ -1409,42 +1409,20 @@
       </densities>
     </dc:macro>
 
-    <dc:macro name="one-load">
-      <dc:variable name="syear" type="string" expr="dc:date-format('yyyy', $year)"/>
-      <year description="{$syear}"
-            factory="sedimentload"
-            target_out="{$out}"
-            info="{$description}"
-            ids="{$syid};{$fraction};{$syear}" />
-    </dc:macro>
-
-    <dc:macro name="epoch-load">
-      <dc:variable name="syear" type="string" expr="dc:date-format('yyyy', $startyear)"/>
-      <dc:variable name="eyear" type="string" expr="dc:date-format('yyyy', $endyear)"/>
-      <year description="{$syear}-{$eyear}"
+    <dc:macro name="load">
+      <year description="{$timespan}"
             factory="sedimentload"
             target_out="{$out}"
             info="{$description}"
-            ids="{$syid};{$fraction};{$syear}-{$eyear}" />
+            ids="{$syid};{$fraction};{$timespan}" />
     </dc:macro>
 
-    <dc:macro name="one-load_ls">
-      <dc:variable name="syear" type="string" expr="dc:date-format('yyyy', $year)"/>
-      <year description="{$syear}"
+    <dc:macro name="load_ls">
+      <year description="{$timespan}"
             factory="sedimentload_ls"
             target_out="{$out}"
             info="{$description}"
-            ids="{$syid};{$syear}" />
-    </dc:macro>
-
-    <dc:macro name="epoch-load_ls">
-      <dc:variable name="syear" type="string" expr="dc:date-format('yyyy', $startyear)"/>
-      <dc:variable name="eyear" type="string" expr="dc:date-format('yyyy', $endyear)"/>
-      <year description="{$syear}-{$eyear}"
-            factory="sedimentload_ls"
-            target_out="{$out}"
-            info="{$description}"
-            ids="{$syid};{$syear}-{$eyear}" />
+            ids="{$syid};{$timespan}" />
     </dc:macro>
 
     <dc:macro name="loads">
@@ -1453,13 +1431,37 @@
          <dc:variable name="fraction_name" expr="concat('\${', dc:group-key(), '}')"/>
          <fraction description="{$fraction_name}">
            <dc:for-each>
-               <dc:macro-body/>
+             <dc:choose>
+               <dc:when test="string-length(dc:get('endyear')) = 0">
+                 <dc:variable name="timespan" type="string"
+                              expr="dc:date-format('yyyy', $startyear)"/>
+               </dc:when>
+               <dc:otherwise>
+                 <dc:variable name="timespan" type="string"
+                              expr="concat(dc:date-format('yyyy', $startyear),
+                                    '-', dc:date-format('yyyy', $endyear))"/>
+               </dc:otherwise>
+             </dc:choose>
+             <dc:macro-body/>
            </dc:for-each>
          </fraction>
        </dc:group>
      </dc:if>
     </dc:macro>
 
+    <dc:macro name="sedimentloads-filter">
+      <years>
+        <dc:filter expr="string-length(dc:get('endyear')) = 0" >
+          <dc:macro-body/>
+        </dc:filter>
+      </years>
+      <epochs>
+        <dc:filter expr="string-length(dc:get('endyear')) &gt; 0" >
+          <dc:macro-body/>
+        </dc:filter>
+      </epochs>
+    </dc:macro>
+
     <dc:macro name="sedimentloads">
       <dc:comment>
         This is the macro for static datacage "Sedimentloads".
@@ -1468,108 +1470,58 @@
       <sedimentloads>
         <dc:call-macro name="annotations_sediment_load_ls"/>
         <measurement_stations>
-          <years>
-            <dc:context>
-              <dc:statement>
-                SELECT DISTINCT
-                    sy.id          AS syid,
-                    sy.description AS description,
-                    ti.start_time  AS year,
-                    gf.name        AS fraction
-                FROM     sediment_load sy
-                    JOIN sediment_load_values syv
-                        ON sy.id = syv.sediment_load_id
-                    JOIN measurement_station ms
-                        ON ms.id = syv.measurement_station_id
-                    JOIN rivers r ON ms.river_id = r.id
-                    JOIN time_intervals ti ON sy.time_interval_id = ti.id
-                    JOIN grain_fraction gf ON gf.id = sy.grain_fraction_id
-                WHERE   r.id = ${river_id}
-                    AND ti.stop_time IS NULL
-                    AND ms.station BETWEEN ${fromkm} AND ${tokm}
-                ORDER BY fraction, year DESC
-              </dc:statement>
+          <dc:context>
+            <dc:statement>
+              SELECT DISTINCT
+                  sy.id          AS syid,
+                  sy.description AS description,
+                  ti.start_time  AS startyear,
+                  ti.stop_time   AS endyear,
+                  gf.name        AS fraction
+              FROM     sediment_load sy
+                  JOIN sediment_load_values syv
+                      ON sy.id = syv.sediment_load_id
+                  JOIN measurement_station ms
+                      ON ms.id = syv.measurement_station_id
+                  JOIN rivers r ON ms.river_id = r.id
+                  JOIN time_intervals ti ON sy.time_interval_id = ti.id
+                  JOIN grain_fraction gf ON gf.id = sy.grain_fraction_id
+              WHERE   r.id = ${river_id}
+                  AND ms.station BETWEEN ${fromkm} AND ${tokm}
+              ORDER BY fraction, startyear DESC, endyear DESC
+            </dc:statement>
+            <dc:call-macro name="sedimentloads-filter">
               <dc:call-macro name="loads">
-                <dc:call-macro name="one-load"/>
+                <dc:call-macro name="load"/>
               </dc:call-macro>
-            </dc:context>
-          </years>
-          <epochs>
-            <dc:context>
-              <dc:statement>
-                SELECT DISTINCT
-                    sy.id          AS syid,
-                    sy.description AS description,
-                    ti.start_time  AS startyear,
-                    ti.stop_time   AS endyear,
-                    gf.name        AS fraction
-                FROM     sediment_load sy
-                    JOIN sediment_load_values syv
-                        ON sy.id = syv.sediment_load_id
-                    JOIN measurement_station ms
-                        ON ms.id = syv.measurement_station_id
-                    JOIN rivers r ON ms.river_id = r.id
-                    JOIN time_intervals ti ON sy.time_interval_id = ti.id
-                    JOIN grain_fraction gf ON gf.id = sy.grain_fraction_id
-                WHERE   r.id = ${river_id}
-                    AND ti.stop_time IS NOT NULL
-                    AND ms.station BETWEEN ${fromkm} AND ${tokm}
-                ORDER BY fraction, startyear DESC, endyear DESC
-              </dc:statement>
-              <dc:call-macro name="loads">
-                <dc:call-macro name="epoch-load"/>
-              </dc:call-macro>
-            </dc:context>
-          </epochs>
+            </dc:call-macro>
+          </dc:context>
         </measurement_stations>
         <sediment_load_ls>
-          <years>
-            <dc:context>
-              <dc:statement>
-                SELECT DISTINCT
-                    sy.id          AS syid,
-                    sy.description AS description,
-                    ti.start_time  AS year,
-                    gf.name        AS fraction
-                FROM     sediment_load_ls sy
-                    JOIN rivers r ON sy.river_id = r.id
-                    JOIN sediment_load_ls_values syv ON sy.id = syv.sediment_load_ls_id
-                    JOIN time_intervals ti ON sy.time_interval_id = ti.id
-                    JOIN grain_fraction gf ON gf.id = sy.grain_fraction_id
-                WHERE   r.id = ${river_id}
-                    AND ti.stop_time IS NULL
-                    AND syv.station BETWEEN ${fromkm} AND ${tokm}
-                ORDER BY fraction, year DESC
-              </dc:statement>
+          <dc:context>
+            <dc:statement>
+              SELECT DISTINCT
+                  sy.id          AS syid,
+                  sy.description AS description,
+                  ti.start_time  AS startyear,
+                  ti.stop_time   AS endyear,
+                  gf.name        AS fraction
+              FROM     sediment_load_ls sy
+                  JOIN rivers r ON sy.river_id = r.id
+                  JOIN sediment_load_ls_values syv
+                      ON sy.id = syv.sediment_load_ls_id
+                  JOIN time_intervals ti ON sy.time_interval_id = ti.id
+                  JOIN grain_fraction gf ON gf.id = sy.grain_fraction_id
+              WHERE   r.id = ${river_id}
+                  AND syv.station BETWEEN ${fromkm} AND ${tokm}
+              ORDER BY fraction, startyear DESC, endyear DESC
+            </dc:statement>
+            <dc:call-macro name="sedimentloads-filter">
               <dc:call-macro name="loads">
-                <dc:call-macro name="one-load_ls"/>
+                <dc:call-macro name="load_ls"/>
               </dc:call-macro>
-            </dc:context>
-          </years>
-          <epochs>
-            <dc:context>
-              <dc:statement>
-                SELECT DISTINCT
-                    sy.id          AS syid,
-                    sy.description AS description,
-                    ti.start_time  AS startyear,
-                    ti.stop_time   AS endyear,
-                    gf.name        AS fraction
-                FROM     sediment_load_ls sy
-                    JOIN rivers r ON sy.river_id = r.id
-                    JOIN sediment_load_ls_values syv ON sy.id = syv.sediment_load_ls_id
-                    JOIN time_intervals ti ON sy.time_interval_id = ti.id
-                    JOIN grain_fraction gf ON gf.id = sy.grain_fraction_id
-                WHERE   r.id = ${river_id}
-                    AND ti.stop_time IS NOT NULL
-                    AND syv.station BETWEEN ${fromkm} AND ${tokm}
-                ORDER BY fraction, startyear DESC, endyear DESC
-              </dc:statement>
-              <dc:call-macro name="loads">
-                <dc:call-macro name="epoch-load_ls"/>
-              </dc:call-macro>
-            </dc:context>
-          </epochs>
+            </dc:call-macro>
+          </dc:context>
         </sediment_load_ls>
       </sedimentloads>
     </dc:macro>

http://dive4elements.wald.intevation.org