annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcProcessor.java @ 9487:504f63512379

Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
author mschaefer
date Tue, 18 Sep 2018 12:21:17 +0200
parents 08f46ccd37ba
children 1d4262a68f1f
rev   line source
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
2 * Software engineering by
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
5 *
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
9 */
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
10
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9205
diff changeset
11 package org.dive4elements.river.artifacts.sinfo.collision;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
12
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
13 import java.util.HashSet;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
14 import java.util.Set;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
15
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
17 import org.dive4elements.artifactdatabase.state.Facet;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
18 import org.dive4elements.artifacts.CallContext;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
19 import org.dive4elements.river.artifacts.common.AbstractCalculationResult;
9347
08f46ccd37ba salix.regional refactoring
gernotbelger
parents: 9215
diff changeset
20 import org.dive4elements.river.artifacts.common.AbstractProcessor;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
21 import org.dive4elements.river.artifacts.resources.Resources;
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9205
diff changeset
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
23 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
24 import org.dive4elements.river.exports.DiagramGenerator;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
25 import org.dive4elements.river.themes.ThemeDocument;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
26
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
27 /**
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
28 * Processor to generate the facet and data series of calculated bed collision counts
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
29 *
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
30 * @author Matthias Schäfer
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
31 *
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
32 */
9347
08f46ccd37ba salix.regional refactoring
gernotbelger
parents: 9215
diff changeset
33 public final class CollisionCalcProcessor extends AbstractProcessor {
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
34
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
35 public static final String FACET_COLLISION_CALC_COUNT = "sinfo_facet_collision_calc_count";
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
36
9204
4f411c6ee3ae Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents: 9200
diff changeset
37 public static final String FACET_COLLISION_CALC_COUNT_2 = "sinfo_facet_collision_calc_count.2";
4f411c6ee3ae Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents: 9200
diff changeset
38
4f411c6ee3ae Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents: 9200
diff changeset
39 public static final String FACET_COLLISION_CALC_COUNT_3 = "sinfo_facet_collision_calc_count.3";
4f411c6ee3ae Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents: 9200
diff changeset
40
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
41 private static final String[] COLLISION_FACETS = new String[] { FACET_COLLISION_CALC_COUNT, FACET_COLLISION_CALC_COUNT_2, FACET_COLLISION_CALC_COUNT_3 };
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
42
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
43 private static final String I18N_AXIS_LABEL = "chart.collision_count.section.yaxis.label";
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
44
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
45 private static final String I18N_SERIES_NAME_PATTERN = "collision.count.title";
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
46
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
47 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
48
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
49 static {
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
50 HANDLED_FACET_TYPES.add(FACET_COLLISION_CALC_COUNT);
9204
4f411c6ee3ae Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents: 9200
diff changeset
51 HANDLED_FACET_TYPES.add(FACET_COLLISION_CALC_COUNT_2);
4f411c6ee3ae Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents: 9200
diff changeset
52 HANDLED_FACET_TYPES.add(FACET_COLLISION_CALC_COUNT_3);
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
53 }
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
54
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
55 public CollisionCalcProcessor() {
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
56 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
57 }
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
58
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
59 @Override
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
60 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
61
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9205
diff changeset
62 final CollisionCalcFacet facet = (CollisionCalcFacet) bundle.getFacet();
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
63
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
64 final CollisionCalcOverviewResult result = (CollisionCalcOverviewResult) getResult(generator, bundle);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
65
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9347
diff changeset
66 final double[][] points = result.getStationPointsByYear(SInfoResultType.collisionCount, facet.getYears());
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
67
9347
08f46ccd37ba salix.regional refactoring
gernotbelger
parents: 9215
diff changeset
68 return buildSeriesForPoints(points, generator, bundle, theme, visible, null);
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
69 }
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
70
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
71 public static final Facet createFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result,
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
72 final int resultIndex, final int year, final int themeCount) {
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
73
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
74 // REMARK: we are using themeCount as facet index, because we get several lines (with the same facet name) for the same
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9204
diff changeset
75 // result index; however name and index are used on client side as unique id.
9204
4f411c6ee3ae Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents: 9200
diff changeset
76
4f411c6ee3ae Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents: 9200
diff changeset
77 final CollisionCalcOverviewResult ccoResult = (CollisionCalcOverviewResult) result;
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9347
diff changeset
78 final String years = CollisionCalculation.yearsToString(ccoResult.getIsEpochs(), ccoResult.getYears().get(themeCount));
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9347
diff changeset
79 final String facetDescription = Resources.getMsg(context.getMeta(), I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, years);
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9347
diff changeset
80 return new CollisionCalcFacet(themeCount, resultIndex, years, COLLISION_FACETS[themeCount % 3], facetDescription, I18N_AXIS_LABEL,
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9347
diff changeset
81 ComputeType.ADVANCE, hash, id);
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
82 }
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents:
diff changeset
83 }

http://dive4elements.wald.intevation.org