# HG changeset patch # User Sascha L. Teichmann # Date 1337014678 0 # Node ID ae0742f92cd5a8dbaad077322a106e4ee2a3308e # Parent 28c3f65880115f21a38378fb188c5ee367323d72 Added model to store fitting results into cache. flys-artifacts/trunk@4403 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 28c3f6588011 -r ae0742f92cd5 flys-artifacts/ChangeLog --- 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 + + * src/main/java/de/intevation/flys/artifacts/model/Parameters.java: + New. Model for storing fitting results in cache. + 2012-05-14 Ingo Weinzierl * src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java: @@ -40,7 +45,7 @@ 2012-05-11 Felix Wolfsteller * doc/conf/meta-data.xml: Allow hyk loading also when in non- - recommendation mode. + recommendation mode. 2012-05-11 Felix Wolfsteller @@ -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 diff -r 28c3f6588011 -r ae0742f92cd5 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java --- /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 parameters) { + + int N = columns[0].size(); + + for (int i = 0; i < columns.length; ++i) { + columns[i].add(Double.NaN); + } + + for (Map.Entry 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 :