comparison etl/src/main/java/org/dive4elements/river/etl/aft/River.java @ 6895:e5675e85ac38

Potential fix for flys/1453.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 21 Aug 2013 16:15:37 +0200
parents 389bf6b7d371
children 60c894b71fed
comparison
equal deleted inserted replaced
6894:389bf6b7d371 6895:e5675e85ac38
13 13
14 import java.sql.ResultSet; 14 import java.sql.ResultSet;
15 import java.sql.SQLException; 15 import java.sql.SQLException;
16 16
17 import java.util.ArrayList; 17 import java.util.ArrayList;
18 import java.util.Comparator;
18 import java.util.HashMap; 19 import java.util.HashMap;
19 import java.util.List; 20 import java.util.List;
20 import java.util.Map; 21 import java.util.Map;
22 import java.util.TreeMap;
21 23
22 import org.apache.log4j.Logger; 24 import org.apache.log4j.Logger;
23 25
24 public class River 26 public class River
25 extends IdPair 27 extends IdPair
134 ResultSet gaugesRs = flysStatements 136 ResultSet gaugesRs = flysStatements
135 .getStatement("select.gauges") 137 .getStatement("select.gauges")
136 .clearParameters() 138 .clearParameters()
137 .setInt("river_id", id1).executeQuery(); 139 .setInt("river_id", id1).executeQuery();
138 140
141 TreeMap<Double, String> station2gaugeName = new TreeMap<Double, String>(
142 new Comparator<Double>() {
143 @Override
144 public int compare(Double a, Double b) {
145 double diff = a - b;
146 if (diff < -0.0001) return -1;
147 if (diff > 0.0001) return +1;
148 return 0;
149 }
150 });
151
139 try { 152 try {
140 while (gaugesRs.next()) { 153 while (gaugesRs.next()) {
141 int gaugeId = gaugesRs.getInt("id"); 154 int gaugeId = gaugesRs.getInt("id");
142 String name = gaugesRs.getString("name"); 155 String name = gaugesRs.getString("name");
143 long number = gaugesRs.getLong("official_number"); 156 long number = gaugesRs.getLong("official_number");
157 double station = gaugesRs.getDouble("station");
158 station2gaugeName.put(station, name);
159
144 if (gaugesRs.wasNull()) { 160 if (gaugesRs.wasNull()) {
145 log.warn("FLYS: Gauge '" + name + 161 log.warn("FLYS: Gauge '" + name +
146 "' has no official number. Ignored."); 162 "' has no official number. Ignored.");
147 continue; 163 continue;
148 } 164 }
161 } 177 }
162 finally { 178 finally {
163 gaugesRs.close(); 179 gaugesRs.close();
164 } 180 }
165 181
166 boolean modified = createGauges(context, aftDIPSGauges); 182 boolean modified = createGauges(
183 context, aftDIPSGauges, station2gaugeName);
167 184
168 modified |= updateGauges(context, updateGauges); 185 modified |= updateGauges(context, updateGauges);
169 186
170 return modified; 187 return modified;
171 } 188 }
362 return false; 379 return false;
363 } 380 }
364 381
365 protected boolean createGauges( 382 protected boolean createGauges(
366 SyncContext context, 383 SyncContext context,
367 Map<Long, DIPSGauge> gauges 384 Map<Long, DIPSGauge> gauges,
385 Map<Double, String> station2gaugeName
368 ) 386 )
369 throws SQLException 387 throws SQLException
370 { 388 {
371 ConnectedStatements flysStatements = context.getFlysStatements(); 389 ConnectedStatements flysStatements = context.getFlysStatements();
372 390
382 Long officialNumber = entry.getKey(); 400 Long officialNumber = entry.getKey();
383 DIPSGauge gauge = entry.getValue(); 401 DIPSGauge gauge = entry.getValue();
384 402
385 log.info("Gauge '" + gauge.getAftName() + 403 log.info("Gauge '" + gauge.getAftName() +
386 "' not in FLYS but in AFT/DIPS. -> Create"); 404 "' not in FLYS but in AFT/DIPS. -> Create");
405
406 String flysGaugeName = station2gaugeName.get(gauge.getStation());
407 if (flysGaugeName != null) {
408 log.warn("FLYS: AFT gauge " + gauge.getName() +
409 " has same station as FLYS gauge " + flysGaugeName +
410 " -> ignored.");
411 continue;
412 }
387 413
388 if (!gauge.hasDatums()) { 414 if (!gauge.hasDatums()) {
389 log.warn("DIPS: Gauge '" + 415 log.warn("DIPS: Gauge '" +
390 gauge.getAftName() + "' has no datum. Ignored."); 416 gauge.getAftName() + "' has no datum. Ignored.");
391 continue; 417 continue;

http://dive4elements.wald.intevation.org