annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java @ 3627:096598c3bd30

fix issue817, removed double entries from dc conf. flys-artifacts/trunk@5325 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 31 Aug 2012 11:11:17 +0000
parents 1df6984628c3
children 1ddbf66a2b0a
rev   line source
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
3 import de.intevation.flys.model.DischargeTable;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
4 import de.intevation.flys.model.Gauge;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
5 import de.intevation.flys.model.River;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
6
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
7 import de.intevation.flys.utils.DoubleUtil;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
8
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
9 import gnu.trove.TDoubleArrayList;
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.io.Serializable;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
13 import java.util.ArrayList;
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
14 import java.util.Collections;
3439
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
15 import java.util.Comparator;
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
16 import java.util.List;
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
18 import org.apache.log4j.Logger;
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
19
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public class Segment
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 implements Serializable
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 {
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
23 private static Logger log = Logger.getLogger(Segment.class);
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
3439
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
25 public static final Comparator<Segment> REF_CMP =
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
26 new Comparator<Segment>() {
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
27 @Override
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
28 public int compare(Segment a, Segment b) {
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
29 double d = a.referencePoint - b.referencePoint;
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
30 if (d < 0d) return -1;
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
31 return d > 0d ? +1 : 0;
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
32 }
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
33 };
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
34
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 protected double from;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 protected double to;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 protected double [] values;
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
38 protected double [] backup;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
39 protected double referencePoint;
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 public Segment() {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
44 public Segment(double referencePoint) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
45 this.referencePoint = referencePoint;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
46 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
47
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 public Segment(double from, double to, double [] values) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 this.from = from;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 this.to = to;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 this.values = values;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public boolean isUp() {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 return from < to;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
58 public boolean inside(double km) {
3552
1df6984628c3 S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3449
diff changeset
59 return from < to
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
60 ? km >= from && km <= to
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
61 : km >= to && km <= from;
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
62 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
63
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
64 @Override
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 public String toString() {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 StringBuilder sb = new StringBuilder("Segment: [");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 sb.append("from: ").append(from).append("; to: ")
670
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
68 .append(to)
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
69 .append("; ref: ").append(referencePoint)
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
70 .append("; values: (");
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 for (int i = 0; i < values.length; ++i) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 if (i > 0) sb.append(", ");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 sb.append(values[i]);
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 sb.append(")]");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 return sb.toString();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
79 public void setFrom(double from) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
80 this.from = from;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
81 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
82
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
83 public void backup() {
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
84 backup = values != null
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
85 ? (double [])values.clone()
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
86 : null;
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
87 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
88
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
89 public double [] getBackup() {
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
90 return backup;
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
91 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
92
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
93 public double getFrom() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
94 return from;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
95 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
96
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
97 public void setTo(double to) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
98 this.to = to;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
99 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
100
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
101 public double getTo() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
102 return to;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
103 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
104
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
105 public void setValues(double [] values) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
106 this.values = values;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
107 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
108
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
109 public double [] getValues() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
110 return values;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
111 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
112
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
113 public int numValues() {
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
114 return values.length;
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
115 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
116
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
117 public void setReferencePoint(double referencePoint) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
118 this.referencePoint = referencePoint;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
119 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
120
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
121 public double getReferencePoint() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
122 return referencePoint;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
123 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
124
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 public static List<Segment> parseSegments(String input) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 ArrayList<Segment> segments = new ArrayList<Segment>();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 TDoubleArrayList vs = new TDoubleArrayList();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 for (String segmentStr: input.split(":")) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132 String [] parts = segmentStr.split(";");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 if (parts.length < 3) {
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
134 log.warn("invalid segment: '" + segmentStr + "'");
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 continue;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 try {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 double from = Double.parseDouble(parts[0].trim());
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 double to = Double.parseDouble(parts[1].trim());
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 vs.clear();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 for (String valueStr: parts[2].split(",")) {
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
144 vs.add(DoubleUtil.round(
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
145 Double.parseDouble(valueStr.trim())));
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 double [] values = vs.toNativeArray();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 segments.add(new Segment(from, to, values));
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 catch (NumberFormatException nfe) {
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
152 log.warn("invalid segment: '" + segmentStr + "'");
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 return segments;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 }
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
158
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
159 public static boolean setReferencePointConvertQ(
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
160 List<Segment> segments,
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
161 River river,
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
162 boolean isQ,
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
163 Calculation report
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
164 ) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
165 int numResults = -1;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
166
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
167 boolean success = true;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
168
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
169 // assign reference points
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
170 for (Segment segment: segments) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
171 Gauge gauge = river.maxOverlap(segment.getFrom(), segment.getTo());
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
172
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
173 if (gauge == null) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
174 log.warn("no gauge found. Defaults to mid point.");
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
175 segment.setReferencePoint(
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
176 0.5*(segment.getFrom()+segment.getTo()));
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
177 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
178 else {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
179 double ref = gauge.getStation().doubleValue();
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
180 log.debug(
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
181 "reference gauge: " + gauge.getName() +
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
182 " (km " + ref + ")");
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
183 segment.setReferencePoint(ref);
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
184 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
185
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
186 double [] values = segment.values;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
187
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
188 if (numResults == -1) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
189 numResults = values.length;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
190 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
191 else if (numResults != values.length) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
192 log.warn("wrong length of values");
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
193 return false;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
194 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
195
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
196 // convert to Q if needed
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
197 if (!isQ && gauge != null) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
198
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
199 DischargeTable dt = gauge.fetchMasterDischargeTable();
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
200
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
201 double [][] table =
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
202 DischargeTables.loadDischargeTableValues(dt, 1);
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
203
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
204 // need the original values for naming
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
205 segment.backup();
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
206
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
207 for (int i = 0; i < values.length; ++i) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
208 double w = values[i] / 100.0;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
209 double [] qs = DischargeTables.getQsForW(table, w);
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
210 if (qs.length == 0) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
211 log.warn("No Qs found for W = " + values[i]);
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
212 report.addProblem("cannot.find.w.for.q", values[i]);
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
213 values[i] = Double.NaN;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
214 success = false;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
215 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
216 else {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
217 values[i] = qs[0];
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
218 if (qs.length > 1) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
219 log.warn(
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
220 "More than one Q found for W = " + values[i]);
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
221 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
222 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
223 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
224 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
225 } // for all segments
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
226
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
227 Collections.sort(segments, Segment.REF_CMP);
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
228
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
229 return success;
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
230 }
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org