Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/process/KMIndexProcessor.java @ 4446:05a54b4d579d
Remove AbstractFixGenerator and use new KMIndexProcessor instead
Don't use same base class for minfo and fixings artifacts. Instead use the new
KMIndexProcessor to generate the same output for the same data types and facets.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 07 Nov 2012 14:34:13 +0100 |
parents | |
children | f59fbc9bd04a |
comparison
equal
deleted
inserted
replaced
4445:0eca080fc162 | 4446:05a54b4d579d |
---|---|
1 package de.intevation.flys.exports.process; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 import org.jfree.data.xy.XYSeries; | |
5 import org.jfree.data.xy.XYSeriesCollection; | |
6 import org.w3c.dom.Document; | |
7 | |
8 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | |
9 import de.intevation.artifacts.CallContext; | |
10 import de.intevation.flys.artifacts.model.FacetTypes; | |
11 import de.intevation.flys.artifacts.model.fixings.AnalysisPeriod; | |
12 import de.intevation.flys.artifacts.model.fixings.QWD; | |
13 import de.intevation.flys.exports.XYChartGenerator; | |
14 import de.intevation.flys.jfree.StyledXYSeries; | |
15 import de.intevation.flys.utils.KMIndex; | |
16 | |
17 public class KMIndexProcessor implements Processor { | |
18 | |
19 private static final Logger logger = Logger.getLogger(KMIndexProcessor.class); | |
20 | |
21 @Override | |
22 public void doOut(XYChartGenerator generator, ArtifactAndFacet aandf, | |
23 Document theme, boolean visible, int index) { | |
24 String facettype = aandf.getFacetName(); | |
25 if (facettype.contains(FacetTypes.FIX_SECTOR_AVERAGE_LS)) { | |
26 doSectorAverageOut(generator, aandf, theme, visible, index); | |
27 } | |
28 else if (facettype.equals(FacetTypes.FIX_REFERENCE_EVENTS_LS)) { | |
29 doReferenceEventsOut(generator, aandf, theme, visible, index); | |
30 } | |
31 else if (facettype.equals(FacetTypes.FIX_ANALYSIS_EVENTS_LS)) { | |
32 doAnalysisEventsOut(generator, aandf, theme, visible, index); | |
33 } | |
34 | |
35 } | |
36 | |
37 @Override | |
38 public boolean canHandle(String facettype) { | |
39 if (facettype == null) { | |
40 return false; | |
41 } | |
42 | |
43 if (facettype.equals(FacetTypes.FIX_SECTOR_AVERAGE_LS) | |
44 || facettype.equals(FacetTypes.FIX_REFERENCE_EVENTS_LS) | |
45 || facettype.equals(FacetTypes.FIX_ANALYSIS_EVENTS_LS)) | |
46 { | |
47 return true; | |
48 } | |
49 return false; | |
50 } | |
51 | |
52 private void doSectorAverageOut(XYChartGenerator generator, ArtifactAndFacet aaf, | |
53 Document doc, boolean visible, int idx) { | |
54 logger.debug("doSectorAverageOut" + aaf.getFacet().getIndex()); | |
55 | |
56 CallContext context = generator.getCallContext(); | |
57 int index = aaf.getFacet().getIndex(); | |
58 int sectorNdx = index & 3; | |
59 | |
60 @SuppressWarnings("unchecked") | |
61 KMIndex<AnalysisPeriod> kms = | |
62 (KMIndex<AnalysisPeriod>)aaf.getData(context); | |
63 | |
64 if(kms == null) { | |
65 return; | |
66 } | |
67 | |
68 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc); | |
69 | |
70 for (KMIndex.Entry<AnalysisPeriod> entry: kms) { | |
71 double km = entry.getKm(); | |
72 AnalysisPeriod ap = entry.getValue(); | |
73 QWD qwd = ap.getQSectorAverages()[sectorNdx]; | |
74 if (qwd == null) { | |
75 continue; | |
76 } | |
77 double deltaW = qwd.getDeltaW(); | |
78 series.add(km, deltaW); | |
79 } | |
80 | |
81 generator.addAxisSeries(series, idx, visible); | |
82 } | |
83 | |
84 private void doReferenceEventsOut(XYChartGenerator generator, | |
85 ArtifactAndFacet aaf, Document doc, boolean visible, int idx) { | |
86 logger.debug("doReferenceEventOut"); | |
87 | |
88 CallContext context = generator.getCallContext(); | |
89 | |
90 @SuppressWarnings("unchecked") | |
91 KMIndex<QWD> kms = | |
92 (KMIndex<QWD>)aaf.getData(context); | |
93 | |
94 if(kms == null) { | |
95 return; | |
96 } | |
97 | |
98 XYSeriesCollection col = new XYSeriesCollection(); | |
99 | |
100 StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, | |
101 doc); | |
102 | |
103 for (KMIndex.Entry<QWD> entry: kms) { | |
104 double km = entry.getKm(); | |
105 QWD qwd = entry.getValue(); | |
106 | |
107 series.add(km, qwd.getDeltaW()); | |
108 } | |
109 col.addSeries(series); | |
110 | |
111 generator.addAxisDataset(col, idx, visible); | |
112 } | |
113 | |
114 private void doAnalysisEventsOut(XYChartGenerator generator, | |
115 ArtifactAndFacet aaf, Document doc, boolean visible, int idx) { | |
116 logger.debug("doAnalysisEventsOut"); | |
117 | |
118 CallContext context = generator.getCallContext(); | |
119 | |
120 @SuppressWarnings("unchecked") | |
121 KMIndex<QWD> kms = | |
122 (KMIndex<QWD>)aaf.getData(context); | |
123 | |
124 if(kms == null) { | |
125 return; | |
126 } | |
127 | |
128 XYSeriesCollection col = new XYSeriesCollection(); | |
129 | |
130 StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc); | |
131 | |
132 for (KMIndex.Entry<QWD> entry: kms) { | |
133 double km = entry.getKm(); | |
134 QWD qwd = entry.getValue(); | |
135 | |
136 series.add(km, qwd.getDeltaW()); | |
137 } | |
138 col.addSeries(series); | |
139 | |
140 generator.addAxisDataset(col, idx, visible); | |
141 } | |
142 } |