|
195 | 195 | var fieldDataFiltered = rawFieldData.filter(item => ( item[0] >= segmentData[0][0] && item[0] <= segmentData[1][0]));
|
196 | 196 |
|
197 | 197 |
|
198 |
| - // 3.2 Calculate model data from new rc equation, collect and prepaire output |
| 198 | + // 3.2 Calculate model data from new rc equation, collect and prepare output |
199 | 199 | var stage = fieldDataFiltered.map( item => (item[0]));
|
200 | 200 | var q_field = fieldDataFiltered.map( item => (item[1]));
|
201 | 201 | var q_model = stage.map(s => C * (s - offset) ** slope);
|
202 | 202 | // Calculate statistical parameters; residuals
|
203 | 203 | var newResiduals = fieldDataFiltered.map(item => ( 100 * (C * (item[0] - offset) ** slope - item[1]) / item[1] ) );
|
204 | 204 |
|
205 |
| - // Collect and prepaire output |
| 205 | + // Collect and prepare output |
206 | 206 | var newSegData = [];
|
207 | 207 | for (let t = 0; t < q_model.length; t++) {
|
208 | 208 | newSegData.push([stage[t], q_model[t], newResiduals[t]]);
|
|
214 | 214 | });
|
215 | 215 |
|
216 | 216 | // 3.3 Update residualData
|
217 |
| - residualData[idx+1].data = newSegData; |
| 217 | + try { |
| 218 | + residualData[idx+1].data = newSegData; |
| 219 | + } catch { |
| 220 | + // this is likely a manual segment, skip it |
| 221 | + continue |
| 222 | + } |
| 223 | + |
218 | 224 | // add boundary points to segment data (for plotting on rcChart)
|
219 | 225 | newSegData.unshift([segmentData[0][0], segmentData[0][1], 0]);
|
220 | 226 | newSegData.push([segmentData[1][0], segmentData[1][1], 0]);
|
|
361 | 367 | offset_thisline = offsetData[rc_trueidx]
|
362 | 368 | param = rcDict.parameters[rc_trueidx]
|
363 | 369 |
|
| 370 | + // in case a manual segment is defined, skip it |
| 371 | + if (param == undefined) { |
| 372 | + // TODO: this breaks interpolation for the manual segment |
| 373 | + // FIX: get parameters from the correct data, rcDict shouldn't be used here |
| 374 | + continue |
| 375 | + } |
| 376 | + |
364 | 377 | // create an array that will be used to calculate the line point positions
|
365 | 378 | const arr = [];
|
366 | 379 | for (let i = 0; i < 1; i += 1/interpolation_points)
|
|
987 | 1000 | // Get filtered field data within segment bounds (used with to calculate RMSE and residuals)
|
988 | 1001 | var rawFieldData = rcData[0]['data'];
|
989 | 1002 | var fieldDataFiltered = rawFieldData.filter(item => ( item[0] >= compStartBounds && item[0] <= compEndBounds));
|
990 |
| - // Calculate model data from new rc equation, collect and prepaire output |
| 1003 | + // Calculate model data from new rc equation, collect and prepare output |
991 | 1004 | var stage = fieldDataFiltered.map( item => (item[0]));
|
992 | 1005 | var q_field_compare = fieldDataFiltered.map( item => (item[1]));
|
993 | 1006 | var q_model_compare = stage.map(s => compConst * (s - compOffset) ** compExp);
|
994 | 1007 | // Calculate statistical parameters; residuals
|
995 |
| - var compResiduals = fieldDataFiltered.map(item => ( 100 * (compConst * (item[0] - compOffset) ** compExp - item[1]) / item[1] ) ); |
996 |
| - // Collect and prepaire output |
| 1008 | + var compResiduals = fieldDataFiltered.map(item => ( -100 * (compConst * (item[0] - compOffset) ** compExp - item[1]) / item[1] ) ); |
| 1009 | + // Collect and prepare output |
997 | 1010 | var compData = [];
|
998 | 1011 | for (let t = 0; t < q_model_compare.length; t++) {
|
999 | 1012 | compData.push([stage[t], q_model_compare[t], compResiduals[t]]);
|
|
1007 | 1020 | compRcData = [...compData];
|
1008 | 1021 | compRcData.unshift([lowerH, lowerQ, 0])
|
1009 | 1022 | compRcData.push([upperH, upperQ, 0])
|
| 1023 | + |
| 1024 | + // 2.9 interpolate data for residual chart |
| 1025 | + var stageInterpolated = []; |
| 1026 | + for (let i = 0; i < interpolation_points; i++) { |
| 1027 | + stageInterpolated.push(lowerH + i * (upperH - lowerH) / interpolation_points); |
| 1028 | + } |
| 1029 | + var q_model_interpolated = stageInterpolated.map(s => compConst * (s - compOffset) ** compExp); |
| 1030 | + |
1010 | 1031 | // 3. Calculate statistical parameters; RMSE
|
1011 | 1032 | stats_compare = calculate_stats(q_field_compare, q_model_compare)
|
1012 | 1033 |
|
1013 |
| - // 4. Prepaire output |
1014 |
| - var compChartData = compRcData.map(item => ({ x: item[1], y: item[0] })); |
| 1034 | + // 4. Prepare output |
| 1035 | + var compChartData = stageInterpolated.map((item, index) => ({ x: q_model_interpolated[index], y: item })); |
1015 | 1036 | var compResChartData = compData.map(item => ({ x: item[2], y: item[0] }));
|
| 1037 | + // 4.1 Sort by x value |
| 1038 | + compChartData.sort((a, b) => a.x - b.x); |
1016 | 1039 |
|
1017 | 1040 | // 5. If data is calculated, plot on RC chart and residual chart
|
1018 | 1041 | if (compChartData.length > 1) {
|
|
1201 | 1224 | // prevent dragging
|
1202 | 1225 | return false
|
1203 | 1226 | }
|
| 1227 | + |
| 1228 | + // prevent dragging of manually added comparison curves |
| 1229 | + if (dataset.backgroundColor === '#DDCC77') { |
| 1230 | + return false |
| 1231 | + } |
1204 | 1232 |
|
1205 | 1233 | // hide interpolation line for current RC curve:
|
1206 | 1234 | var datasetLabel = dataset.label
|
|
0 commit comments