comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisPeriodsFacet.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 e4606eae8ea5
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.DateRange; 16 import org.dive4elements.river.artifacts.model.DateRange;
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; 19 import org.dive4elements.river.utils.KMIndex;
23
24 import org.apache.log4j.Logger;
25 20
26 /** 21 /**
27 * Facet to show W values for Q values at km for a date. 22 * Facet to show W values for Q values at km for a date.
28 * 23 *
29 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
30 */ 25 */
31 public class FixAnalysisPeriodsFacet 26 public class FixAnalysisPeriodsFacet extends FixingsFacet implements FacetTypes {
32 extends FixingsFacet 27
33 implements FacetTypes { 28 private static final long serialVersionUID = 1L;
34 29
35 /** House log. */ 30 /** House log. */
36 private static Logger log = Logger.getLogger(FixAnalysisPeriodsFacet.class); 31 private static Logger log = Logger.getLogger(FixAnalysisPeriodsFacet.class);
37 32
38 /** Trivial Constructor. */ 33 /** Trivial Constructor. */
39 public FixAnalysisPeriodsFacet() { 34 public FixAnalysisPeriodsFacet() {
40 } 35 }
41 36
42 37 public FixAnalysisPeriodsFacet(final int index, final String name, final String description) {
43 /** 38 super(index, name, description, ComputeType.ADVANCE, null, null);
44 * @param name
45 */
46 public FixAnalysisPeriodsFacet(int index, String name, String description) {
47 super(index,
48 name,
49 description,
50 ComputeType.ADVANCE,
51 null,
52 null);
53 } 39 }
54
55 40
56 /** 41 /**
57 * Returns the data this facet requires. 42 * Returns the data this facet requires.
58 * 43 *
59 * @param artifact the owner artifact. 44 * @param artifact
60 * @param context the CallContext (ignored). 45 * the owner artifact.
46 * @param context
47 * the CallContext (ignored).
61 * 48 *
62 * @return the data. 49 * @return the data.
63 */ 50 */
64 @Override 51 @Override
65 public Object getData(Artifact artifact, CallContext context) { 52 public Object getData(final Artifact artifact, final CallContext context) {
66 log.debug("FixAnalysisPeriodsFacet.getData"); 53 log.debug("FixAnalysisPeriodsFacet.getData");
67 54
68 if (artifact instanceof D4EArtifact) { 55 if (artifact instanceof D4EArtifact) {
69 D4EArtifact flys = (D4EArtifact)artifact; 56 final D4EArtifact flys = (D4EArtifact) artifact;
70 57
71 CalculationResult res = 58 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
72 (CalculationResult) flys.compute(context,
73 ComputeType.ADVANCE,
74 false);
75 59
76 FixAnalysisResult result = (FixAnalysisResult) res.getData(); 60 final FixAnalysisResult result = (FixAnalysisResult) res.getData();
77 double currentKm = getCurrentKm(context); 61 final double currentKm = getCurrentKm(context);
78 62
79 KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods(); 63 final KMIndex<AnalysisPeriod[]> kmPeriods = result.getAnalysisPeriods();
80 KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry = 64 final KMIndex.Entry<AnalysisPeriod[]> kmPeriodsEntry = kmPeriods.binarySearch(currentKm);
81 kmPeriods.binarySearch(currentKm); 65 if (kmPeriodsEntry == null)
66 return null;
82 67
83 if (kmPeriodsEntry == null) { 68 final AnalysisPeriod[] periods = kmPeriodsEntry.getValue();
69 if (periods == null)
84 return null; 70 return null;
85 }
86 71
87 AnalysisPeriod[] periods = kmPeriodsEntry.getValue(); 72 final DateRange[] dates = new DateRange[periods.length];
88
89 if (periods == null) {
90 return null;
91 }
92 DateRange[] dates = new DateRange[periods.length];
93 for (int i = 0; i < periods.length; i++) { 73 for (int i = 0; i < periods.length; i++) {
94 dates[i] = periods[i].getDateRange(); 74 dates[i] = periods[i].getDateRange();
95 } 75 }
76
96 return dates; 77 return dates;
97 } 78 }
98 else { 79
99 log.debug("Not an instance of FixationArtifact."); 80 log.debug("Not an instance of FixationArtifact.");
100 return null; 81 return null;
101 }
102 } 82 }
103
104 83
105 /** 84 /**
106 * Create a deep copy of this Facet. 85 * Create a deep copy of this Facet.
86 *
107 * @return a deep copy. 87 * @return a deep copy.
108 */ 88 */
109 @Override 89 @Override
110 public FixAnalysisPeriodsFacet deepCopy() { 90 public FixAnalysisPeriodsFacet deepCopy() {
111 FixAnalysisPeriodsFacet copy = new FixAnalysisPeriodsFacet(); 91 final FixAnalysisPeriodsFacet copy = new FixAnalysisPeriodsFacet();
112 copy.set(this); 92 copy.set(this);
113 return copy; 93 return copy;
114 } 94 }
115 } 95 }
116 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org