comparison artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java @ 9465:be9bd06a1e3f

bezugswst sounding select for miss'vol only (calc crashes)
author gernotbelger
date Thu, 30 Aug 2018 10:54:40 +0200
parents fd6621f47a72
children 2b83d3a96703
comparison
equal deleted inserted replaced
9464:c77255da734b 9465:be9bd06a1e3f
66 public BezugswstCalculation(final CallContext context) { 66 public BezugswstCalculation(final CallContext context) {
67 this.context = context; 67 this.context = context;
68 this.rows = new ArrayList<>(); 68 this.rows = new ArrayList<>();
69 } 69 }
70 70
71
72 /** 71 /**
73 * Calculates the result rows of a bundu bzws workflow 72 * Calculates the result rows of a bundu bzws workflow
74 */ 73 */
75 public CalculationResult calculate(final BUNDUArtifact bunduartifact) { 74 public CalculationResult calculate(final BUNDUArtifact bunduartifact) {
76 75
90 final BezugswstCalculationResults results = new BezugswstCalculationResults(calcModeLabel, user, riverInfo, access.getRange()); 89 final BezugswstCalculationResults results = new BezugswstCalculationResults(calcModeLabel, user, riverInfo, access.getRange());
91 90
92 final Calculation problems = new Calculation(); 91 final Calculation problems = new Calculation();
93 92
94 // Calculate the wspl for the selected river range as in fixa awspl 93 // Calculate the wspl for the selected river range as in fixa awspl
95 bunduartifact.addStringData("wq_isq", "true"); // macht doch Sinn hier, sorry! 94 bunduartifact.addStringData("wq_isq", "true");
96 final WinfoArtifactWrapper winfo = new WinfoArtifactWrapper(bunduartifact); 95 final WinfoArtifactWrapper winfo = new WinfoArtifactWrapper(bunduartifact);
97 final RiverInfoProvider riverInfoProvider = RiverInfoProvider.forRange(this.context, river, access.getRange(), true); 96 final RiverInfoProvider riverInfoProvider = RiverInfoProvider.forRange(this.context, river, access.getRange(), true);
98 final FixRealizingResult fixResult = calculateWspl(bunduartifact, problems); 97 final FixRealizingResult fixResult = calculateWspl(bunduartifact, problems);
99 if (fixResult == null) 98 if (fixResult == null)
100 return new CalculationResult(results, problems); 99 return new CalculationResult(results, problems);
101 100
102 final WQKms wqkms = fixResult.getWQKms()[0]; 101 final WQKms wqkms = fixResult.getWQKms()[0];
103 final WstInfo wstInfo = new WstInfo(wqkms.getName(), 0, riverInfoProvider.getReferenceGauge(), true); 102 final WstInfo wstInfo = new WstInfo(wqkms.getName(), 0, riverInfoProvider.getReferenceGauge(), true);
104 103
105 // Fetch the bed heights of the selected sounding 104 // Fetch the bed heights of the selected sounding
106 final int bedHeightId = access.getBedHeightID(); 105 final Integer bedHeightId = access.getBedHeightID(); // TODO: REMOVE BEDHEIGHTFINDER FROM CALCULATION - HOW?
107 final BedHeightsFinder bedHeightsFinder = BedHeightsFinder.forId(problems, bedHeightId, access.getRange()); 106 final BedHeightsFinder bedHeightsFinder = bedHeightId == null ? null : BedHeightsFinder.forId(problems, bedHeightId, access.getRange());
108 if (bedHeightsFinder == null)
109 return new CalculationResult(results, problems);
110 107
111 // Fetch the river channel data 108 // Fetch the river channel data
112 final ChannelFinder channelFinder = ChannelFinder.loadValues(problems, river, access.getBezugsJahr()); 109 final ChannelFinder channelFinder = ChannelFinder.loadValues(problems, river, access.getBezugsJahr());
113 if (channelFinder == null) 110 if (channelFinder == null)
114 return new CalculationResult(results, problems); 111 return new CalculationResult(results, problems);
115 112
116 // Compute the result rows 113 // Compute the result rows
117 for (int i = 0; i <= wqkms.size() - 1; i++) { 114 for (int i = 0; i <= wqkms.size() - 1; i++) {
115 // TODO: REMOVE BEDHEIGHTFINDER FROM CALCULATION - HOW?
118 this.rows.add(createRow(wqkms.getKm(i), wqkms.getW(i), wqkms.getQ(i), bedHeightsFinder, channelFinder, riverInfoProvider, wstInfo)); 116 this.rows.add(createRow(wqkms.getKm(i), wqkms.getW(i), wqkms.getQ(i), bedHeightsFinder, channelFinder, riverInfoProvider, wstInfo));
119 } 117 }
120 118
121 // Compute the missing volumes 119 // Compute the missing volumes
122 if (access.isCalculateMissingValue()) { 120 if (access.isCalculateMissingValue()) {
121 if (bedHeightsFinder == null)
122 return new CalculationResult(results, problems);
123 computeMissingVolumes(problems); 123 computeMissingVolumes(problems);
124 final BedQualityCalculator bqCalculator = computeDensities(problems, bunduartifact, access, river); 124 final BedQualityCalculator bqCalculator = computeDensities(problems, bunduartifact, access, river);
125 computeMissingMasses(problems, bqCalculator); 125 computeMissingMasses(problems, bqCalculator);
126 } 126 }
127 127
189 row.putValue(GeneralResultType.gaugeLabel, riverInfoProv.findGauge(station)); 189 row.putValue(GeneralResultType.gaugeLabel, riverInfoProv.findGauge(station));
190 row.putValue(GeneralResultType.location, riverInfoProv.getLocation(station)); 190 row.putValue(GeneralResultType.location, riverInfoProv.getLocation(station));
191 row.putValue(BunduResultType.sounding, bedHeightsFinder.getInfo().getDescription()); 191 row.putValue(BunduResultType.sounding, bedHeightsFinder.getInfo().getDescription());
192 192
193 // Set bed and channel bottom height 193 // Set bed and channel bottom height
194
195 // TODO: REMOVE BEDHEIGHTFINDER FROM CALCULATION - HOW?
194 final double msh = bedHeightsFinder.getMeanBedHeight(station); 196 final double msh = bedHeightsFinder.getMeanBedHeight(station);
195 row.putValue(SInfoResultType.meanBedHeight, msh); 197 row.putValue(SInfoResultType.meanBedHeight, msh);
196 if (!Double.isNaN(w) && !Double.isNaN(msh)) 198 if (!Double.isNaN(w) && !Double.isNaN(msh))
197 row.putValue(SInfoResultType.flowdepth, Formatter.roundFlowDepth(w).subtract(Formatter.roundFlowDepth(msh)).doubleValue()); 199 row.putValue(SInfoResultType.flowdepth, Formatter.roundFlowDepth(w).subtract(Formatter.roundFlowDepth(msh)).doubleValue());
198 else 200 else
199 row.putValue(SInfoResultType.flowdepth, Double.NaN); 201 row.putValue(SInfoResultType.flowdepth, Double.NaN);
202
200 final double channelDepth = channelFinder.getDepth(station); 203 final double channelDepth = channelFinder.getDepth(station);
201 row.putValue(BunduResultType.channelDepth, channelDepth); 204 row.putValue(BunduResultType.channelDepth, channelDepth);
202 double channelHeight; 205 double channelHeight;
203 if (!Double.isNaN(w) && !Double.isNaN(channelDepth)) 206 if (!Double.isNaN(w) && !Double.isNaN(channelDepth))
204 channelHeight = Formatter.roundFlowDepth(w).subtract(Formatter.roundFlowDepth(channelDepth)).doubleValue(); 207 channelHeight = Formatter.roundFlowDepth(w).subtract(Formatter.roundFlowDepth(channelDepth)).doubleValue();
237 } 240 }
238 if (isKmInMissingVolumeRange(station)) { 241 if (isKmInMissingVolumeRange(station)) {
239 row.putValue(BunduResultType.missDepthFields, fieldMissDepths); 242 row.putValue(BunduResultType.missDepthFields, fieldMissDepths);
240 row.putValue(BunduResultType.missWidthFields, fieldMissWidths); 243 row.putValue(BunduResultType.missWidthFields, fieldMissWidths);
241 row.putValue(BunduResultType.hasMissingDepth, (missFieldCnt >= 1)); 244 row.putValue(BunduResultType.hasMissingDepth, (missFieldCnt >= 1));
242 } 245 } else {
243 else {
244 row.putValue(BunduResultType.missDepthFields, fieldNulls); 246 row.putValue(BunduResultType.missDepthFields, fieldNulls);
245 row.putValue(BunduResultType.missWidthFields, fieldNulls); 247 row.putValue(BunduResultType.missWidthFields, fieldNulls);
246 row.putValue(BunduResultType.hasMissingDepth, null); 248 row.putValue(BunduResultType.hasMissingDepth, null);
247 } 249 }
248 row.putValue(BunduResultType.missVolumeFields, fieldNulls); 250 row.putValue(BunduResultType.missVolumeFields, fieldNulls);

http://dive4elements.wald.intevation.org