Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisResult.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 gnu.trove.TIntObjectHashMap; | |
12 | |
13 import java.util.Collection; | |
14 import java.util.Date; | |
15 import java.util.TreeMap; | |
16 import java.util.TreeSet; | |
17 | |
18 import org.apache.log4j.Logger; | |
19 import org.dive4elements.river.artifacts.model.Parameters; | 11 import org.dive4elements.river.artifacts.model.Parameters; |
20 | |
21 import org.dive4elements.river.utils.KMIndex; | 12 import org.dive4elements.river.utils.KMIndex; |
22 | 13 |
23 public class FixAnalysisResult | 14 public class FixAnalysisResult extends FixResult { |
24 extends FixResult | |
25 { | |
26 private static Logger log = | |
27 Logger.getLogger(FixAnalysisResult.class); | |
28 | 15 |
29 protected KMIndex<AnalysisPeriod []> analysisPeriods; | 16 private static final long serialVersionUID = 1L; |
30 | 17 |
31 public FixAnalysisResult() { | 18 private final KMIndex<AnalysisPeriod[]> analysisKmPeriods; |
19 | |
20 private final AnalysisPeriodEventResults analysisEventResults; | |
21 | |
22 public FixAnalysisResult(final Parameters parameters, final FixResultColumns fixResultColumns, final KMIndex<AnalysisPeriod[]> analysisKmPeriods, | |
23 final AnalysisPeriodEventResults analysisEventResults) { | |
24 super(parameters, fixResultColumns); | |
25 | |
26 this.analysisKmPeriods = analysisKmPeriods; | |
27 this.analysisEventResults = analysisEventResults; | |
32 } | 28 } |
33 | 29 |
34 public FixAnalysisResult( | 30 public final int getUsedSectorsInAnalysisPeriods() { |
35 Parameters parameters, | |
36 KMIndex<QWD []> fixings, | |
37 KMIndex<AnalysisPeriod []> analysisPeriods | |
38 ) { | |
39 super(parameters, fixings); | |
40 this.analysisPeriods = analysisPeriods; | |
41 } | |
42 | |
43 public int getUsedSectorsInAnalysisPeriods() { | |
44 int result = 0; | 31 int result = 0; |
45 for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) { | 32 for (final KMIndex.Entry<AnalysisPeriod[]> entry : this.analysisKmPeriods) { |
46 for (AnalysisPeriod period: entry.getValue()) { | 33 for (final AnalysisPeriod period : entry.getValue()) { |
47 for (int i = 0; i < 4; ++i) { | 34 for (int i = 0; i < 4; ++i) { |
48 result |= period.getQSectorAverage(i) != null | 35 result |= period.getQSectorAverage(i) != null ? (1 << i) : 0; |
49 ? (1 << i) | |
50 : 0; | |
51 } | 36 } |
52 // XXX: Stop early on result == ~(~0 << 4)) ? | 37 // XXX: Stop early on result == ~(~0 << 4)) ? |
53 } | 38 } |
54 } | 39 } |
55 return result; | 40 return result; |
56 } | 41 } |
57 | 42 |
58 | 43 public final KMIndex<AnalysisPeriod[]> getAnalysisPeriods() { |
59 public void makeAnalysisEventsUnique() { | 44 return this.analysisKmPeriods; |
60 TIntObjectHashMap dums = new TIntObjectHashMap(); | |
61 | |
62 for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) { | |
63 AnalysisPeriod [] aps = entry.getValue(); | |
64 for (int i = 0; i < aps.length; ++i) { | |
65 AnalysisPeriod ap = aps[i]; | |
66 QWD [] qwds = ap.getQWDs(); | |
67 if (qwds == null) { | |
68 continue; | |
69 } | |
70 DateUniqueMaker dum = (DateUniqueMaker)dums.get(i); | |
71 if (dum == null) { | |
72 dums.put(i, dum = new DateUniqueMaker()); | |
73 } | |
74 for (QWD qwd: qwds) { | |
75 dum.makeUnique(qwd); | |
76 } | |
77 } | |
78 } | |
79 } | 45 } |
80 | 46 |
81 public Collection<Date> getAnalysisEventsDates(int analysisPeriod) { | 47 public AnalysisPeriodEventResults getAnalysisEventResults() { |
82 TreeSet<Date> dates = new TreeSet<Date>(); | 48 return this.analysisEventResults; |
83 for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) { | |
84 QWD [] qwds = entry.getValue()[analysisPeriod].getQWDs(); | |
85 if (qwds != null) { | |
86 for (QWD qwd: qwds) { | |
87 dates.add(qwd.date); | |
88 } | |
89 } | |
90 } | |
91 return dates; | |
92 } | |
93 | |
94 public Collection<Integer> getAnalysisEventsIndices(int analysisPeriod) { | |
95 TreeMap<Date, Integer> dates = new TreeMap<Date, Integer>(); | |
96 for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) { | |
97 QWD [] qwds = entry.getValue()[analysisPeriod].getQWDs(); | |
98 if (qwds != null) { | |
99 for (QWD qwd: qwds) { | |
100 dates.put(qwd.date, qwd.index); | |
101 } | |
102 } | |
103 } | |
104 return dates.values(); | |
105 } | |
106 | |
107 public void remapAnalysisEventsIndicesToRank(int analysisPeriod) { | |
108 RankRemapper remapper = new RankRemapper(); | |
109 for (Integer index: getAnalysisEventsIndices(analysisPeriod)) { | |
110 remapper.toMap(index); | |
111 } | |
112 for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) { | |
113 QWD [] qwds = entry.getValue()[analysisPeriod].getQWDs(); | |
114 if (qwds != null) { | |
115 for (QWD qwd: qwds) { | |
116 remapper.remap(qwd); | |
117 } | |
118 } | |
119 } | |
120 } | |
121 | |
122 public KMIndex<AnalysisPeriod []> getAnalysisPeriods() { | |
123 return analysisPeriods; | |
124 } | |
125 | |
126 public void setAnalysisPeriods(KMIndex<AnalysisPeriod []> analysisPeriods) { | |
127 this.analysisPeriods = analysisPeriods; | |
128 } | 49 } |
129 } | 50 } |
130 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |