comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixLongitudinalAnalysisFacet.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 5e38e2924c07
children
comparison
equal deleted inserted replaced
9414:096f151a0a9f 9415:9744ce3c3853
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.apache.log4j.Logger;
12
13 import org.dive4elements.artifacts.Artifact; 12 import org.dive4elements.artifacts.Artifact;
14 import org.dive4elements.artifacts.CallContext; 13 import org.dive4elements.artifacts.CallContext;
15 import org.dive4elements.river.artifacts.D4EArtifact; 14 import org.dive4elements.river.artifacts.D4EArtifact;
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 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; 18 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
20 import org.dive4elements.river.utils.KMIndex;
21 19
22 /** 20 /**
23 * Facet to show average W values for Q sectors. 21 * Facet to show average W values for Q sectors.
24 * 22 *
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 23 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
26 */ 24 */
27 public class FixLongitudinalAnalysisFacet 25 public class FixLongitudinalAnalysisFacet extends DataFacet implements FacetTypes {
28 extends DataFacet 26
29 implements FacetTypes { 27 private static final long serialVersionUID = 1L;
30 28
31 /** House log. */ 29 /** House log. */
32 private static Logger log = Logger.getLogger( 30 private static Logger log = Logger.getLogger(FixLongitudinalAnalysisFacet.class);
33 FixLongitudinalAnalysisFacet.class); 31
32 private int periodIndex;
33
34 private int columnId;
34 35
35 /** Trivial Constructor. */ 36 /** Trivial Constructor. */
36 public FixLongitudinalAnalysisFacet() { 37 public FixLongitudinalAnalysisFacet() {
37 } 38 }
38 39
40 public FixLongitudinalAnalysisFacet(final int facetIndex, final int periodIndex, final int columnId, final String name, final String description) {
41 super(facetIndex, name, description, ComputeType.ADVANCE, null, null);
39 42
40 public FixLongitudinalAnalysisFacet( 43 this.periodIndex = periodIndex;
41 int ndx, 44 this.columnId = columnId;
42 String name,
43 String description)
44 {
45 super(
46 ndx,
47 name,
48 description,
49 ComputeType.ADVANCE,
50 null,
51 null);
52 } 45 }
53
54 46
55 /** 47 /**
56 * Returns the data this facet requires. 48 * Returns the data this facet requires.
57 * 49 *
58 * @param artifact the owner artifact. 50 * @param artifact
59 * @param context the CallContext. 51 * the owner artifact.
52 * @param context
53 * the CallContext.
60 * 54 *
61 * @return the data as KMIndex. 55 * @return the data as KMIndex.
62 */ 56 */
63 @Override 57 @Override
64 public Object getData(Artifact artifact, CallContext context) { 58 public Object getData(final Artifact artifact, final CallContext context) {
65 log.debug("FixLongitudinalAnalysisFacet.getData"); 59 log.debug("FixLongitudinalAnalysisFacet.getData");
66 60
67 if (artifact instanceof D4EArtifact) { 61 if (artifact instanceof D4EArtifact) {
68 D4EArtifact flys = (D4EArtifact)artifact; 62 final D4EArtifact flys = (D4EArtifact) artifact;
69 63
70 CalculationResult res = 64 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
71 (CalculationResult) flys.compute(context,
72 ComputeType.ADVANCE,
73 false);
74 65
75 FixAnalysisResult result = (FixAnalysisResult) res.getData(); 66 final FixAnalysisResult result = (FixAnalysisResult) res.getData();
76 67
77 KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods(); 68 final AnalysisPeriodEventResults eventResults = result.getAnalysisEventResults();
78 if (kmPeriods == null) { 69 final FixResultColumns eventResult = eventResults.getEventResults(this.periodIndex);
79 log.warn("No analysis periods found."); 70 if (eventResult == null) {
71 log.error("No event result for period: " + this.periodIndex);
80 return null; 72 return null;
81 } 73 }
82 int periodNdx = index >> 8; 74
83 int qwdNdx = index & 255; 75 final FixResultColumn event = eventResult.getColumn(this.columnId);
84 KMIndex<QWD> resPeriods = 76 if (event == null) {
85 new KMIndex<QWD>(); 77 log.error("Missing event with columnId: " + this.columnId);
86 for (KMIndex.Entry<AnalysisPeriod[]> entry: kmPeriods) { 78 return null;
87 AnalysisPeriod ap = entry.getValue()[periodNdx];
88 QWD[] qwds = ap.qwds;
89 for(int i = 0; i < qwds.length; i++) {
90 if(qwds[i].getIndex() == qwdNdx) {
91 resPeriods.add(entry.getKm(), qwds[i]);
92 }
93 }
94 } 79 }
95 80
81 return event.getQWDs();
82 }
96 83
97 return resPeriods; 84 log.warn("Artifact is no instance of D4EArtifact.");
98 } 85 return null;
99 else {
100 log.warn("Artifact is no instance of D4EArtifact.");
101 return null;
102 }
103 } 86 }
104
105 87
106 /** 88 /**
107 * Create a deep copy of this Facet. 89 * Create a deep copy of this Facet.
90 *
108 * @return a deep copy. 91 * @return a deep copy.
109 */ 92 */
110 @Override 93 @Override
111 public FixLongitudinalAnalysisFacet deepCopy() { 94 public FixLongitudinalAnalysisFacet deepCopy() {
112 FixLongitudinalAnalysisFacet copy = new FixLongitudinalAnalysisFacet(); 95 final FixLongitudinalAnalysisFacet copy = new FixLongitudinalAnalysisFacet();
113 copy.set(this); 96 copy.set(this);
97 copy.periodIndex = this.periodIndex;
98 copy.columnId = this.columnId;
114 return copy; 99 return copy;
115 } 100 }
116 } 101 }
117 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org