comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixLongitudinalReferenceFacet.java @ 9415:9744ce3c3853

Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets. The facets also put the valid station range into their xml-metadata
author gernotbelger
date Thu, 16 Aug 2018 16:27:53 +0200
parents ddcd52d239cd
children
comparison
equal deleted inserted replaced
9414:096f151a0a9f 9415:9744ce3c3853
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.artifacts.model.fixings; 9 package org.dive4elements.river.artifacts.model.fixings;
10 10
11 import org.apache.log4j.Logger;
11 import org.dive4elements.artifacts.Artifact; 12 import org.dive4elements.artifacts.Artifact;
12 import org.dive4elements.artifacts.CallContext; 13 import org.dive4elements.artifacts.CallContext;
13
14 import org.dive4elements.river.artifacts.D4EArtifact; 14 import org.dive4elements.river.artifacts.D4EArtifact;
15
16 import org.dive4elements.river.artifacts.model.CalculationResult; 15 import org.dive4elements.river.artifacts.model.CalculationResult;
17 import org.dive4elements.river.artifacts.model.DataFacet; 16 import org.dive4elements.river.artifacts.model.DataFacet;
18 import org.dive4elements.river.artifacts.model.FacetTypes; 17 import org.dive4elements.river.artifacts.model.FacetTypes;
19
20 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; 18 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
21
22 import org.dive4elements.river.utils.KMIndex;
23
24 import org.apache.log4j.Logger;
25
26 19
27 /** 20 /**
28 * Facet to show average W values for Q sectors. 21 * Facet to show average W values for Q sectors.
29 * 22 *
30 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 23 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
31 */ 24 */
32 public class FixLongitudinalReferenceFacet 25 public class FixLongitudinalReferenceFacet extends DataFacet implements FacetTypes {
33 extends DataFacet 26
34 implements FacetTypes { 27 private static final long serialVersionUID = 1L;
35 28
36 /** House log. */ 29 /** House log. */
37 private static Logger log = Logger.getLogger( 30 private static Logger log = Logger.getLogger(FixLongitudinalReferenceFacet.class);
38 FixLongitudinalReferenceFacet.class); 31
32 private int columnId;
39 33
40 /** Trivial Constructor. */ 34 /** Trivial Constructor. */
41 public FixLongitudinalReferenceFacet() { 35 public FixLongitudinalReferenceFacet() {
42 } 36 }
43 37
38 public FixLongitudinalReferenceFacet(final int facetIndex, final int columnId, final String name, final String description) {
39 super(facetIndex, name, description, ComputeType.ADVANCE, null, null);
44 40
45 public FixLongitudinalReferenceFacet( 41 this.columnId = columnId;
46 int ndx,
47 String name,
48 String description)
49 {
50 super(
51 ndx,
52 name,
53 description,
54 ComputeType.ADVANCE,
55 null,
56 null);
57 } 42 }
58
59 43
60 /** 44 /**
61 * Returns the data this facet requires. 45 * Returns the data this facet requires.
62 * 46 *
63 * @param artifact the owner artifact. 47 * @param artifact
64 * @param context the CallContext. 48 * the owner artifact.
49 * @param context
50 * the CallContext.
65 * 51 *
66 * @return the data as KMIndex. 52 * @return the data as KMIndex.
67 */ 53 */
68 @Override 54 @Override
69 public Object getData(Artifact artifact, CallContext context) { 55 public Object getData(final Artifact artifact, final CallContext context) {
70 log.debug("FixLongitudinalReferenceFacet.getData"); 56 log.debug("FixLongitudinalReferenceFacet.getData");
71 57
72 if (artifact instanceof D4EArtifact) { 58 if (artifact instanceof D4EArtifact) {
73 D4EArtifact flys = (D4EArtifact)artifact; 59 final D4EArtifact flys = (D4EArtifact) artifact;
74 60
75 CalculationResult res = 61 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
76 (CalculationResult) flys.compute(context,
77 ComputeType.ADVANCE,
78 false);
79 62
80 FixAnalysisResult result = (FixAnalysisResult) res.getData(); 63 final FixAnalysisResult result = (FixAnalysisResult) res.getData();
81 64
82 KMIndex<QWD []> kmReference = result.getFixings(); 65 final FixResultColumns resultColumns = result.getFixResultColumns();
83 66 final FixResultColumn event = resultColumns.getColumn(this.columnId);
84 if (kmReference == null) { 67 if (event == null) {
85 log.warn("No references found."); 68 log.error("Missing event witrh columnId: " + this.columnId);
86 return null; 69 return null;
87 } 70 }
88 71
89 int qwdNdx = index & 255; 72 return event.getQWDs();
90 73 }
91 final KMIndex<QWD> resReference = new KMIndex<>();
92
93 for (KMIndex.Entry<QWD[]> entry: kmReference) {
94 QWD[] qwds = entry.getValue();
95 for(int i = 0; i < qwds.length; i++) {
96 if(qwds[i].getIndex() == qwdNdx && !qwds[i].isOutlier() ) {
97 resReference.add(entry.getKm(), qwds[i]);
98 }
99 }
100 }
101 74
102 return resReference;
103 }
104
105 log.warn("Artifact is no instance of D4EArtifact."); 75 log.warn("Artifact is no instance of D4EArtifact.");
106 return null; 76 return null;
107 } 77 }
108 78
109 /** 79 /**
110 * Create a deep copy of this Facet. 80 * Create a deep copy of this Facet.
81 *
111 * @return a deep copy. 82 * @return a deep copy.
112 */ 83 */
113 @Override 84 @Override
114 public FixLongitudinalReferenceFacet deepCopy() { 85 public FixLongitudinalReferenceFacet deepCopy() {
115 FixLongitudinalReferenceFacet copy = 86 final FixLongitudinalReferenceFacet copy = new FixLongitudinalReferenceFacet();
116 new FixLongitudinalReferenceFacet();
117 copy.set(this); 87 copy.set(this);
88 copy.columnId = this.columnId;
118 return copy; 89 return copy;
119 } 90 }
120 } 91 }

http://dive4elements.wald.intevation.org