annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/WstValueTableFactory.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/WstValueTableFactory.java@bd047b71ab37
children 4897a58c8746
rev   line source
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5423
diff changeset
1 package org.dive4elements.river.artifacts.model;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
3 import java.util.Arrays;
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
4 import java.util.List;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.util.ArrayList;
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
6
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
7 import net.sf.ehcache.Cache;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
8 import net.sf.ehcache.Element;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
9
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5423
diff changeset
10 import org.dive4elements.river.artifacts.cache.CacheFactory;
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
11
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5423
diff changeset
12 import org.dive4elements.river.backend.SessionHolder;
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
13
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
14 import org.apache.log4j.Logger;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
15
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5423
diff changeset
16 import org.dive4elements.river.model.River;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5423
diff changeset
17 import org.dive4elements.river.model.Wst;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import org.hibernate.Session;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import org.hibernate.Query;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import org.hibernate.SQLQuery;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 import org.hibernate.type.StandardBasicTypes;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
25 /**
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
26 * Creates WstValueTable s from database.
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
27 * WstValueTable s are used to interpolate given w/q/km values.
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
28 */
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public class WstValueTableFactory
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 private static Logger log = Logger.getLogger(WstValueTableFactory.class);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
33 public static final int DEFAULT_KIND = 0;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
34
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 // TODO: put this into a property file
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
36
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
37 public static final String HQL_WST =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
38 "from Wst where river=:river and kind=:kind";
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
39
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
40 public static final String SQL_SELECT_NAMES_POS =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
41 "SELECT position, name FROM wst_columns " +
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
42 "WHERE wst_id = :wst_id ORDER BY position";
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
43
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
44 /** Select Qs for wst (view sorted by column). */
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
45 public static final String SQL_SELECT_QS =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
46 "SELECT column_pos, q, a, b FROM wst_q_values " +
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
47 "WHERE wst_id = :wst_id";
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
48
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
49 // (sorted by km)
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
50 public static final String SQL_SELECT_WS =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
51 "SELECT km, w, column_pos FROM wst_w_values " +
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
52 "WHERE wst_id = :wst_id";
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
54 /** Statement to query qranges of a single column. */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
55 public static final String SQL_SELECT_QS_AT_COL =
2609
ed550e325248 Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1927
diff changeset
56 "SELECT q, a, b FROM wst_q_values " +
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
57 "WHERE wst_id = :wst_id AND column_pos = :column_pos";
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
58
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
59 // (sorted by km)
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
60 public static final String SQL_SELECT_WS_AT_COL =
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
61 "SELECT km, w FROM wst_w_values " +
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
62 "WHERE wst_id = :wst_id AND column_pos = :column_pos";
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
63
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
64
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 private WstValueTableFactory() {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
68
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 public static WstValueTable getTable(River river) {
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
70 return getTable(river, DEFAULT_KIND);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
73
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
74 /**
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
75 * Get WstValueTable to interpolate values of a given Wst.
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
76 */
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
77 public static WstValueTable getTable(int wst_id) {
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
78
1898
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
79 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
80
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
81 WstValueTableCacheKey cacheKey;
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
82
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
83 if (cache != null) {
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
84 // "-1" is the symbolic river-id for "no river, but wst_id".
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
85 cacheKey = new WstValueTableCacheKey(-1, wst_id);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
86 Element element = cache.get(cacheKey);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
87 if (element != null) {
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
88 log.debug("Got specific wst value table from cache");
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
89 return (WstValueTable) element.getValue();
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
90 }
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
91 }
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
92 else {
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
93 cacheKey = null;
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
94 }
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
95
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
96 Session session = SessionHolder.HOLDER.get();
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
97
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
98 // Fetch data for one column only.
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2610
diff changeset
99
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
100 WstValueTable.Column [] columns = loadColumns(session, wst_id);
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
101 int [] map = loadQRangesMap(session, columns, wst_id);
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
102 List<WstValueTable.Row> rows = loadRows(session, wst_id, columns.length, map);
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
103
1927
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
104 WstValueTable valueTable = new WstValueTable(columns, rows);
1898
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
105
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
106 if (valueTable != null && cacheKey != null) {
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
107 log.debug("Store wst value table in cache");
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
108 Element element = new Element(cacheKey, valueTable);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
109 cache.put(element);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
110 }
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
111
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
112 return valueTable;
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
113 }
1898
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
114
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
115 /**
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
116 * Get Table for a specific column of a wst.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
117 */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
118 public static WstValueTable getWstColumnTable(int wst_id, int col_pos) {
1898
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
119
1927
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
120 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
121
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
122 WstValueTableCacheKey cacheKey;
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
123
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
124 if (cache != null) {
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
125 // A negaitve/negative number is the symbolic 'river-id' for
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
126 // "no river and kind but wst_id and colpos".
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
127 cacheKey = new WstValueTableCacheKey(-wst_id, -col_pos);
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
128 Element element = cache.get(cacheKey);
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
129 if (element != null) {
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
130 log.debug("Got specific wst value table from cache");
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
131 return (WstValueTable) element.getValue();
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
132 }
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
133 }
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
134 else {
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
135 cacheKey = null;
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
136 }
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
137
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
138 Session session = SessionHolder.HOLDER.get();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
139
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
140 // Fetch data for one column only.
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2610
diff changeset
141
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
142 WstValueTable.Column [] columns = loadColumn(session, wst_id, col_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
143 loadQRanges(session, columns, wst_id, col_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
144 List<WstValueTable.Row> rows = loadRowsOneColumn(session, wst_id, col_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
145
1927
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
146 WstValueTable valueTable = new WstValueTable(columns, rows);
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
147
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
148 if (valueTable != null && cacheKey != null) {
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
149 log.debug("Store wst value table in cache (wst: "
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
150 + wst_id + "/ col: " + col_pos + ")");
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
151 Element element = new Element(cacheKey, valueTable);
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
152 cache.put(element);
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
153 }
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
154
1f90fdd4fa04 Resolved TODO about caching certain WstValueTables.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1909
diff changeset
155 return valueTable;
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
156 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
157
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
158
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
159 /**
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
160 * Get table for first wst of given kind at given river.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
161 */
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 public static WstValueTable getTable(River river, int kind) {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163
632
07640ab913fd First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 626
diff changeset
164 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165
626
e3ee131d5dd3 Moved WST value table cache key to a separate class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
166 WstValueTableCacheKey cacheKey;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 if (cache != null) {
626
e3ee131d5dd3 Moved WST value table cache key to a separate class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
169 cacheKey = new WstValueTableCacheKey(river.getId(), kind);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 Element element = cache.get(cacheKey);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 if (element != null) {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 log.debug("got wst value table from cache");
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 return (WstValueTable)element.getValue();
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 else {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 cacheKey = null;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 WstValueTable valueTable = getTableUncached(river, kind);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181
632
07640ab913fd First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 626
diff changeset
182 if (valueTable != null && cacheKey != null) {
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 log.debug("store wst value table in cache");
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 Element element = new Element(cacheKey, valueTable);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 cache.put(element);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 return valueTable;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
191 public static WstValueTable getTableUncached(River river) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
192 return getTableUncached(river, DEFAULT_KIND);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
193 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
194
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 public static WstValueTable getTableUncached(River river, int kind) {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 Session session = SessionHolder.HOLDER.get();
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
199 Wst wst = loadWst(session, river, kind);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
200
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
201 if (wst == null) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
202 return null;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
203 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
204
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
205 WstValueTable.Column [] columns = loadColumns(session, wst);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
206
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
207 int map [] = loadQRangesMap(session, columns, wst);
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
208
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
209 List<WstValueTable.Row> rows =
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
210 loadRows(session, wst.getId(), columns.length, map);
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
211
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
212 return new WstValueTable(columns, rows);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
213 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
214
1780
b503d92dd709 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 742
diff changeset
215 /**
b503d92dd709 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 742
diff changeset
216 * @param kind Kind of wst.
b503d92dd709 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 742
diff changeset
217 */
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
218 protected static Wst loadWst(Session session, River river, int kind) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
219 Query query = session.createQuery(HQL_WST);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220 query.setParameter("river", river);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 query.setInteger("kind", kind);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 List<Wst> wsts = query.list();
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
225 // TODO Multiple wsts can match, why return just the first one?
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
226 return wsts.isEmpty() ? null : wsts.get(0);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
227 }
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
229
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
230 /**
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
231 * Load rows with a single columns result.
3269
b2ea89a665bc Fix issues in 'documentation'.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
232 *
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
233 * @param session session to use for querying db.
3269
b2ea89a665bc Fix issues in 'documentation'.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
234 * @param wstId id of wst (in db).
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
235 * @param column_pos the column_pos (within the db) of the wst_value_table
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
236 * of which the values shall be fetched.
3269
b2ea89a665bc Fix issues in 'documentation'.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
237 *
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
238 * @return resultant rows.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
239 */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
240 protected static List<WstValueTable.Row> loadRowsOneColumn(
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
241 Session session,
2610
3c907758f0ab Added cacheable model for fixing column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2609
diff changeset
242 int wstId,
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
243 int column_pos
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
244 ) {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
245 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS_AT_COL)
2610
3c907758f0ab Added cacheable model for fixing column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2609
diff changeset
246 .addScalar("km", StandardBasicTypes.DOUBLE)
3c907758f0ab Added cacheable model for fixing column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2609
diff changeset
247 .addScalar("w", StandardBasicTypes.DOUBLE);
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
248
2610
3c907758f0ab Added cacheable model for fixing column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2609
diff changeset
249 sqlQuery.setInteger("wst_id", wstId);
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
250 sqlQuery.setInteger("column_pos", column_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
251
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
252 List<Object []> results = sqlQuery.list();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
253
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
254 double [] ws = null;
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
255
2610
3c907758f0ab Added cacheable model for fixing column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2609
diff changeset
256 List<WstValueTable.Row> rows =
3c907758f0ab Added cacheable model for fixing column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2609
diff changeset
257 new ArrayList<WstValueTable.Row>(results.size());
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
258
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
259 // Walk over rows.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
260 for (Object [] result: results) {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
261 ws = new double[1];
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
262 WstValueTable.Row row =
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
263 new WstValueTable.Row((Double) result[0], ws);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
264 rows.add(row);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
265
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
266 Double w = (Double) result[1];
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
267 ws[0] = w != null ? w : Double.NaN;
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
268 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
269
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
270 return rows;
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
271 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
272
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
273 protected static List<WstValueTable.Row> loadRows(
742
c09c9e05ecfa Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 633
diff changeset
274 Session session,
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
275 int wst_id,
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
276 int numColumns
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
277 ) {
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
278 return loadRows(session, wst_id, numColumns, null);
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
279 }
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
280
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
281 protected static List<WstValueTable.Row> loadRows(
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
282 Session session,
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
283 int wst_id,
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
284 int numColumns,
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
285 int [] map
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
286 ) {
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
287 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
288 .addScalar("km", StandardBasicTypes.DOUBLE)
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
289 .addScalar("w", StandardBasicTypes.DOUBLE)
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
290 .addScalar("column_pos", StandardBasicTypes.INTEGER);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
292 sqlQuery.setInteger("wst_id", wst_id);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
293
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
294 List<Object []> results = sqlQuery.list();
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
295
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
296 int lastColumn = Integer.MAX_VALUE;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
297 double [] ws = null;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
298
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
299 ArrayList<WstValueTable.Row> rows = new ArrayList<WstValueTable.Row>();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
300
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
301 for (Object [] result: results) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
302 int column = (Integer)result[2];
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
303 if (column < lastColumn) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
304 ws = new double[numColumns];
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
305 Arrays.fill(ws, Double.NaN);
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
306 WstValueTable.Row row =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
307 new WstValueTable.Row((Double)result[0], ws);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
308 rows.add(row);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
309 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
310 Double w = (Double)result[1];
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
311 int index = map != null ? map[column] : column;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
312 ws[index] = w != null ? w : Double.NaN;
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
313 lastColumn = column;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
314 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
315
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
316 rows.trimToSize();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
317 return rows;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
318 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
319
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
320 protected static List<WstValueTable.Row> loadRows(
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
321 Session session,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
322 Wst wst,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
323 int numColumns
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
324 ) {
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
325 return loadRows(session, wst.getId(), numColumns);
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
326 }
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
327
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
328
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
329 protected static WstValueTable.Column [] loadColumn(
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
330 Session session,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
331 int wst_id,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
332 int col_pos
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
333 ) {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
334 return new WstValueTable.Column [] {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
335 new WstValueTable.Column(WKmsFactory.getWKmsName(col_pos, wst_id))};
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
336 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
337
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
338
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
339 /**
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
340 * Get columns from wst-id.
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
341 */
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
342 protected static WstValueTable.Column [] loadColumns(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
343 Session session,
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
344 int wst_id
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
345 ) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
346 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_NAMES_POS)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
347 .addScalar("position", StandardBasicTypes.INTEGER)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
348 .addScalar("name", StandardBasicTypes.STRING);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
349
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
350 sqlQuery.setInteger("wst_id", wst_id);
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
351
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
352 List<Object []> columnNames = sqlQuery.list();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
353
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
354 WstValueTable.Column [] columns =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
355 new WstValueTable.Column[columnNames.size()];
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
356
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
357 for (int i = 0; i < columns.length; ++i) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
358 columns[i] = new WstValueTable.Column(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
359 (String)columnNames.get(i)[1]);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
360 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
361 return columns;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
362 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
363
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
364 /**
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
365 * Get columns from Wst.
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
366 */
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
367 protected static WstValueTable.Column [] loadColumns(
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
368 Session session,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
369 Wst wst
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
370 ) {
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
371 return loadColumns(session, wst.getId());
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
372 }
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
373
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
374
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
375 /**
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
376 * Build a QRange-Tree.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
377 */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
378 protected static void loadQRanges(
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
379 Session session,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
380 WstValueTable.Column [] columns,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
381 int wst_id,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
382 int column_pos
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
383 ) {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
384 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_QS_AT_COL)
2609
ed550e325248 Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1927
diff changeset
385 .addScalar("q", StandardBasicTypes.DOUBLE)
ed550e325248 Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1927
diff changeset
386 .addScalar("a", StandardBasicTypes.DOUBLE)
ed550e325248 Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1927
diff changeset
387 .addScalar("b", StandardBasicTypes.DOUBLE);
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
388
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
389 sqlQuery.setInteger("wst_id", wst_id);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
390 sqlQuery.setInteger("column_pos", column_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
391
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
392 List<Object []> qRanges = sqlQuery.list();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
393
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
394 int qSize = qRanges.size();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
395
2609
ed550e325248 Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1927
diff changeset
396 QRangeTree qRangeTree = new QRangeTree(
ed550e325248 Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1927
diff changeset
397 qRanges, QRangeTree.WITHOUT_COLUMN, 0, qSize);
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
398 columns[0].setQRangeTree(qRangeTree);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
399 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
400
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
401 protected static int [] loadQRangesMap(
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
402 Session session,
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
403 WstValueTable.Column [] columns,
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
404 int wst_id
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
405 ) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
406 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_QS)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
407 .addScalar("column_pos", StandardBasicTypes.INTEGER)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
408 .addScalar("q", StandardBasicTypes.DOUBLE)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
409 .addScalar("a", StandardBasicTypes.DOUBLE)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
410 .addScalar("b", StandardBasicTypes.DOUBLE);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
411
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
412 sqlQuery.setInteger("wst_id", wst_id);
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
413
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
414 List<Object []> qRanges = sqlQuery.list();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
415
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
416 int start = -1;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
417 int Q = qRanges.size();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
418 Integer lastColumn = null;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
419
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
420 for (int i = 0; i < Q; ++i) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
421 Object [] qRange = qRanges.get(i);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
422 Integer columnId = (Integer)qRange[0];
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
423 if (lastColumn == null) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
424 lastColumn = columnId;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
425 start = i;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
426 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
427 else if (!lastColumn.equals(columnId)) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
428 QRangeTree qRangeTree = new QRangeTree(qRanges, start, i);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
429 columns[lastColumn].setQRangeTree(qRangeTree);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
430 lastColumn = columnId;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
431 start = i;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
432 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
433 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
434
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
435 if (start != -1) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
436 QRangeTree qRangeTree = new QRangeTree(qRanges, start, Q);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
437 columns[lastColumn].setQRangeTree(qRangeTree);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
438 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
439
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
440 return sortColumnsByAverageQ(columns);
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
441
742
c09c9e05ecfa Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 633
diff changeset
442 /* This is debug code to visualize the q ranges trees
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
443
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
444 java.io.PrintWriter out = null;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
445 try {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
446 out = new java.io.PrintWriter(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
447 new java.io.FileWriter(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
448 "/tmp/qranges" + System.currentTimeMillis() + ".dot"));
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
449
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
450 out.println("graph \"Q ranges trees\" {");
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
451
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
452 for (int i = 0; i < columns.length; ++i) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
453 QRangeTree tree = columns[i].getQRangeTree();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
454 out.println(tree.toGraph());
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
455 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
456
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
457 out.println("}");
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
458
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
459 out.flush();
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
460 }
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
461 catch (java.io.IOException ioe) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
462 log.error(ioe);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
463 }
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
464 finally {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
465 if (out != null) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
466 out.close();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
467 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
468 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
469 */
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
470 }
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
471
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
472 private static final class QIndex implements Comparable<QIndex> {
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
473 double q;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
474 int index;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
475
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
476 QIndex(double q, int index) {
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
477 this.q = q;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
478 this.index = index;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
479 }
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
480
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
481 @Override
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
482 public int compareTo(QIndex other) {
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
483 double diff = q - other.q;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
484 if (diff < 0d) return -1;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
485 if (diff > 0d) return +1;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
486 return 0;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
487 }
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
488 } // class QIndex
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
489
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
490 /** Ensure that the q colums are sorted in ascending order. */
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
491 protected static int [] sortColumnsByAverageQ(WstValueTable.Column [] columns) {
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
492 QIndex [] order = new QIndex[columns.length];
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
493 for (int i = 0; i < order.length; ++i) {
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
494 QRangeTree tree = columns[i].getQRangeTree();
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
495 double avg = tree.averageQ();
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
496 double max = tree.maxQ();
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
497 double q = (avg+max)*0.5d;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
498 order[i] = new QIndex(q, i);
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
499 }
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
500 Arrays.sort(order);
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
501 WstValueTable.Column [] copy = new WstValueTable.Column[order.length];
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
502 int [] map = new int[order.length];
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
503 for (int i = 0; i < copy.length; ++i) {
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
504 copy[i] = columns[order[i].index];
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
505 map[order[i].index] = i;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
506 }
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
507 System.arraycopy(copy, 0, columns, 0, order.length);
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
508 return map;
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
509 }
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
510
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
511 protected static int [] loadQRangesMap(
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
512 Session session,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
513 WstValueTable.Column [] columns,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
514 Wst wst
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
515 ) {
5423
f4fd64a4d502 Fix Wstcalculation for non monotonous values.
Andre Heinecke <aheinecke@intevation.de>
parents: 3269
diff changeset
516 return loadQRangesMap(session, columns, wst.getId());
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
517 }
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
518
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
519 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
520 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org