Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java @ 3003:e5e6363e6cba
FixA: Explicit model for date ranges.
flys-artifacts/trunk@4559 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 30 May 2012 14:45:36 +0000 |
parents | 70469e3d34b9 |
children | 05a3fe8800b3 |
rev | line source |
---|---|
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import gnu.trove.TDoubleArrayList; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.io.Serializable; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
2785
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
7 import org.apache.log4j.Logger; |
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
8 |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 public class Parameters |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 implements Serializable |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 { |
2785
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
12 private static Logger log = Logger.getLogger(Parameters.class); |
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
13 |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 protected String [] columnNames; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 protected TDoubleArrayList [] columns; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 public Parameters() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public Parameters(String [] columnNames) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 if (columnNames == null || columnNames.length < 1) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 throw new IllegalArgumentException("columnNames too short."); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 this.columnNames = columnNames; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 columns = new TDoubleArrayList[columnNames.length]; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 for (int i = 0; i < columns.length; ++i) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 columns[i] = new TDoubleArrayList(); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public int columnIndex(String name) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 for (int i = 0; i < columnNames.length; ++i) { |
2993
70469e3d34b9
FixA: Made Delta W/t calculation finally work
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2785
diff
changeset
|
33 if (columnNames[i].equals(name)) { |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 return i; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 return -1; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
40 public int newRow() { |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 int N = columns[0].size(); |
2785
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
43 log.debug("new row: " + N); |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 for (int i = 0; i < columns.length; ++i) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 columns[i].add(Double.NaN); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
49 return N; |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 public double get(int i, int index) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 return columns[index].getQuick(i); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 public double get(int i, String columnName) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 int index = columnIndex(columnName); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 return index >= 0 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 ? columns[index].getQuick(i) |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 : Double.NaN; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
63 public void set(int i, String columnName, double value) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
64 int idx = columnIndex(columnName); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
65 if (idx >= 0) { |
2785
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
66 columns[idx].setQuick(i, value); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
67 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
68 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
69 |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 public int size() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 return columns[0].size(); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 public int getNumberColumns() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 return columnNames.length; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 public String [] getColumnNames() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 return columnNames; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 public void removeNaNs() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 W.removeNaNs(columns); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 } |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
85 |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
86 public int [] columnIndices(String [] columns) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
87 int [] indices = new int[columns.length]; |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
88 for (int i = 0; i < columns.length; ++i) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
89 indices[i] = columnIndex(columns[i]); |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
90 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
91 return indices; |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
92 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
93 |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
94 public void get(int row, int [] columnIndices, double [] values) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
95 for (int i = 0; i < columnIndices.length; ++i) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
96 int index = columnIndices[i]; |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
97 values[i] = index >= 0 && index < columns.length |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
98 ? columns[index].getQuick(row) |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
99 : Double.NaN; |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
100 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
101 } |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |