changeset 2695:ae0742f92cd5

Added model to store fitting results into cache. flys-artifacts/trunk@4403 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 14 May 2012 16:57:58 +0000
parents 28c3f6588011
children 1bc35de0b786
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java
diffstat 2 files changed, 153 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon May 14 10:34:56 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon May 14 16:57:58 2012 +0000
@@ -1,3 +1,8 @@
+2012-05-14	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/Parameters.java:
+	  New. Model for storing fitting results in cache.
+	  
 2012-05-14  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java:
@@ -40,7 +45,7 @@
 2012-05-11  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* doc/conf/meta-data.xml: Allow hyk loading also when in non-
-       	  recommendation mode.
+	  recommendation mode.
 
 2012-05-11  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
@@ -51,7 +56,7 @@
 
 	* src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
 	  Corrected middle height calculated, have a very verbose label for
-          the time being.
+	  the time being.
 
 2012-05-11  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java	Mon May 14 16:57:58 2012 +0000
@@ -0,0 +1,146 @@
+package de.intevation.flys.artifacts.model;
+
+import gnu.trove.TDoubleArrayList;
+
+import java.util.Map;
+
+import java.io.Serializable;
+
+public class Parameters
+implements   Serializable
+{
+    public static class Parameter
+    implements          Serializable
+    {
+        public String name;
+        public double value;
+
+        public Parameter() {
+        }
+
+        public Parameter(String name, double value) {
+            this.name  = name;
+            this.value = value;
+        }
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public double getValue() {
+            return value;
+        }
+
+        public void setValue(double value) {
+            this.value = value;
+        }
+    } // Parameter
+
+    protected String []           columnNames;
+    protected TDoubleArrayList [] columns;
+
+    public Parameters() {
+    }
+
+    public Parameters(String [] columnNames) {
+        if (columnNames == null || columnNames.length < 1) {
+            throw new IllegalArgumentException("columnNames too short.");
+        }
+        this.columnNames = columnNames;
+        columns = new TDoubleArrayList[columnNames.length];
+        for (int i = 0; i < columns.length; ++i) {
+            columns[i] = new TDoubleArrayList();
+        }
+    }
+
+    public int columnIndex(String name) {
+        for (int i = 0; i < columnNames.length; ++i) {
+            if (name.equals(name)) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    public void add(Parameter [] parameters) {
+
+        int N = columns[0].size();
+
+        for (int i = 0; i < columns.length; ++i) {
+            columns[i].add(Double.NaN);
+        }
+
+        for (Parameter parameter: parameters) {
+            int index = columnIndex(parameter.getName());
+            if (index >= 0) {
+                columns[index].setQuick(N, parameter.getValue());
+            }
+        }
+    }
+
+    public void add(Map<String, Double> parameters) {
+
+        int N = columns[0].size();
+
+        for (int i = 0; i < columns.length; ++i) {
+            columns[i].add(Double.NaN);
+        }
+
+        for (Map.Entry<String, Double> entry: parameters.entrySet()) {
+            int index = columnIndex(entry.getKey());
+            Double v = entry.getValue();
+            if (index >= 0 && v != null) {
+                columns[index].setQuick(N, v);
+            }
+        }
+    }
+
+    public Parameter [] get(int i) {
+        Parameter [] parameters = new Parameter[columns.length];
+        for (int j = 0; i < parameters.length; ++j) {
+            parameters[j] = new Parameter(columnNames[j], Double.NaN);
+        }
+        return get(i, parameters);
+    }
+
+    public Parameter [] get(int i, Parameter [] parameters) {
+        for (Parameter parameter: parameters) {
+            int index = columnIndex(parameter.getName());
+            if (index >= 0) {
+                parameter.setValue(columns[index].getQuick(i));
+            }
+        }
+        return parameters;
+    }
+
+    public double get(int i, int index) {
+        return columns[index].getQuick(i);
+    }
+
+    public double get(int i, String columnName) {
+        int index = columnIndex(columnName);
+        return index >= 0
+            ? columns[index].getQuick(i)
+            : Double.NaN;
+    }
+
+    public int size() {
+        return columns[0].size();
+    }
+
+    public int getNumberColumns() {
+        return columnNames.length;
+    }
+
+    public String [] getColumnNames() {
+        return columnNames;
+    }
+
+    public void removeNaNs() {
+        W.removeNaNs(columns);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org