diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java @ 3217:79dd823733e2

FixA: Added parameter exporter. flys-artifacts/trunk@4840 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 30 Jun 2012 22:02:37 +0000
parents ae14f412ba10
children e0e9a2629d7d
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Sat Jun 30 19:44:39 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Sat Jun 30 22:02:37 2012 +0000
@@ -45,7 +45,6 @@
 extends      DefaultState
 implements   FacetTypes
 {
-
     /** The log used in this class. */
     private static Logger log = Logger.getLogger(FixationCompute.class);
 
@@ -63,24 +62,27 @@
 
     private static final String I18N_REFERENCEDEVIATION = "fix.reference.deviation";
 
-    public static class IdGenerator {
-	private int id;
-
-	public IdGenerator() {
-	}
+    public static final String [] SECTOR_LABELS = {
+        "[0 - (MNQ+MQ)/2)",
+        "[(MNQ+MQ)/2 - (MQ+MHQ)/2)",
+        "[(MQ+MHQ)/2 - HQ5)",
+        "[HQ5 - \u221e)"
+    };
 
-	public IdGenerator(int id) {
-	    this.id = id;
-	}
+    public static class IdGenerator {
+        private int id;
 
-	public int next() {
-	    return id++;
-	}
+        public IdGenerator() {
+        }
 
-	public int next(int s) {
-	    return id += s;
-	}
-    }
+        public IdGenerator(int id) {
+            this.id = id;
+        }
+
+        public int next() {
+            return id++;
+        }
+    } // class IdGenerator
 
     /**
      * The default constructor that initializes an empty State object.
@@ -98,7 +100,6 @@
     ) {
         log.debug("FixationCompute.computeAdvance");
 
-
         CalculationResult res;
 
         FixationArtifactAccess access =
@@ -128,64 +129,69 @@
 
         facets.add(
             new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id));
+        facets.add(
+            new DataFacet(
+                FIX_PARAMETERS, "parameters", ComputeType.ADVANCE, hash, id));
 
         int maxId = -100;
 
-        int count = access.getAnalysisPeriods().length;
-
         int sectorMask = fr.getUsedSectorsInAnalysisPeriods();
 
-        for (int i = 0; i < count; i++) {
-            DateRange period = access.getAnalysisPeriods()[i];
-            DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
+        int qsS = access.getQSectorStart();
+        int qsE = access.getQSectorEnd();
+
+        // TODO: i18n
+        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
+
+        DateRange [] periods = access.getAnalysisPeriods();
+
+        for (int i = 0; i < periods.length; i++) {
+            DateRange period = periods[i];
             String startDate = df.format(period.getFrom());
             String endDate = df.format(period.getTo());
 
-            for (int j = access.getQSectorStart().intValue();
-                 j <= access.getQSectorEnd().intValue();
-                 j++) {
+            for (int j = qsS; j <= qsE; j++) {
 
-                // Only emit facet for sectors that really have data.
+                // Only emit facets for sectors that really have data.
                 if ((sectorMask & (1 << j)) == 0) {
                     continue;
                 }
 
-                String sector = "";
-                switch (j) {
-                    case 0: sector = "[0 - (MNQ+MQ)/2)"; break;
-                    case 1: sector = "[(MNQ+MQ)/2 - (MQ+MHQ)/2)"; break;
-                    case 2: sector = "[(MQ+MHQ)/2 - HQ5)"; break;
-                    case 3: sector = "[HQ5 - \u221e)"; break;
-                }
+                String sector = SECTOR_LABELS[j];
                 String description = sector + ": " +
                                      startDate + " - " +
                                      endDate;
 
-                int sectorNdx = j - access.getQSectorStart().intValue();
+                int sectorNdx = j - qsS;
                 int facetNdx = i << 2;
                 facetNdx = facetNdx | j;
 
-		if (facetNdx > maxId)
-		    maxId = facetNdx;
+                if (facetNdx > maxId) {
+                    maxId = facetNdx;
+                }
 
                 facets.add(
-                    new FixAvSectorFacet(facetNdx,
-                                         FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx,
-                                         description));
+                    new FixAvSectorFacet(
+                        facetNdx,
+                        FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx,
+                        description));
                 facets.add(
-                    new FixLongitudinalAnalysisFacet(facetNdx,
-                                         FIX_SECTOR_AVERAGE_LS + "_" + sectorNdx,
-                                         description));
+                    new FixLongitudinalAnalysisFacet(
+                        facetNdx,
+                        FIX_SECTOR_AVERAGE_LS + "_" + sectorNdx,
+                        description));
                 // TODO: i18n
                 String dev = "Abweichung: " + description;
                 facets.add(
-                    new FixLongitudinalAnalysisFacet(facetNdx,
-                                         FIX_SECTOR_AVERAGE_LS_DEVIATION + "_" + sectorNdx,
-                                         dev));
+                    new FixLongitudinalAnalysisFacet(
+                        facetNdx,
+                        FIX_SECTOR_AVERAGE_LS_DEVIATION + "_" + sectorNdx,
+                        dev));
                 facets.add(
-                    new FixAvSectorFacet(facetNdx,
-                                         FIX_SECTOR_AVERAGE_WQ + "_" + sectorNdx,
-                                         description));
+                    new FixAvSectorFacet(
+                        facetNdx,
+                        FIX_SECTOR_AVERAGE_WQ + "_" + sectorNdx,
+                        description));
 
             }
 
@@ -205,7 +211,7 @@
                 eventDesc));
         }
 
-	IdGenerator idg = new IdGenerator(maxId + 1);
+        IdGenerator idg = new IdGenerator(maxId + 1);
 
         String i18n_ref = Resources.getMsg(context.getMeta(),
                 I18N_REFERENCEPERIOD,
@@ -248,20 +254,24 @@
         Boolean preprocessing = access.getPreprocessing();
 
         if (preprocessing != null && preprocessing) {
-            facets.add(new FixOutlierFacet(idg.next(), FIX_OUTLIER,
-                Resources.getMsg(context.getMeta(), I18N_OUTLIER, I18N_OUTLIER)));
+            facets.add(new FixOutlierFacet(
+                idg.next(),
+                FIX_OUTLIER,
+                Resources.getMsg(
+                    context.getMeta(), I18N_OUTLIER, I18N_OUTLIER)));
         }
 
         facets.add(new FixDerivateFacet(
-	    idg.next(),
-	    FIX_DERIVATE,
-            Resources.getMsg(context.getMeta(),
+            idg.next(),
+            FIX_DERIVATE,
+            Resources.getMsg(
+                context.getMeta(),
                 I18N_DERIVATIVE,
                 I18N_DERIVATIVE)));
 
         facets.add(new FixDeviationFacet(
-	    idg.next(),
-	    FIX_DEVIATION_DWT,
+            idg.next(),
+            FIX_DEVIATION_DWT,
             Resources.getMsg(context.getMeta(),
                 I18N_DEVIATION,
                 I18N_DEVIATION)));

http://dive4elements.wald.intevation.org