Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java @ 8877:9f7a285b0ee3
Some work on SINFO FlowDepth
author | gernotbelger |
---|---|
date | Thu, 08 Feb 2018 18:48:24 +0100 |
parents | 1009cab0f86b |
children | 64ca63f79f6f |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java Thu Feb 08 18:47:36 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java Thu Feb 08 18:48:24 2018 +0100 @@ -1,6 +1,6 @@ /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde - * Software engineering by - * Björnsen Beratende Ingenieure GmbH + * Software engineering by + * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) @@ -17,6 +17,7 @@ import org.dive4elements.river.artifacts.model.Calculation; import org.dive4elements.river.artifacts.model.CalculationResult; import org.dive4elements.river.artifacts.model.LocationProvider; +import org.dive4elements.river.artifacts.model.QKms; import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.artifacts.resources.Resources; import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; @@ -32,127 +33,159 @@ private static final String CSV_NOT_IN_GAUGE_RANGE = "export.waterlevel.csv.not.in.gauge.range"; - private CallContext context; - - public FlowDepthCalculation( final CallContext context ) { - this.context = context; - } - - public CalculationResult calculate(final SINFOArtifact sinfo) { - - // FIXME: find user of this artifact; probably only possible by selecting the collection that contains this artifact... - final String user = "unbekannt"; - - /* access input data */ - final FlowDepthAccess access = new FlowDepthAccess(sinfo); - final River river = access.getRiver(); - - final Collection<DifferencesPair> diffPairs = access.getDifferencePairs(); - - final double from = access.getFrom(); - final double to = access.getTo(); + private final CallContext context; - final boolean useTkh = access.isUseTransportBodies(); - - /* calculate results for each diff pair */ - final Calculation problems = new Calculation(); - - final List<Gauge> gauges = river.determineGauges(from, to); - final GaugeIndex gaugeIndex = new GaugeIndex(gauges); - - final String calcModeLabel = Resources.getMsg(context.getMeta(),sinfo.getCalculationMode().name() ); - - - final FlowDepthCalculationResults results = new FlowDepthCalculationResults(calcModeLabel, user, river, from, to, useTkh); - - for (final DifferencesPair diffPair : diffPairs) { - final FlowDepthCalculationResult result = calculateResult( river, from, to, diffPair, problems, gaugeIndex ); - if( result != null ) - results.addResult(result); - } - - return new CalculationResult(results,problems); + public FlowDepthCalculation( final CallContext context ) { + this.context = context; } - private FlowDepthCalculationResult calculateResult(final River river, final double from, final double to, final DifferencesPair diffPair, final Calculation problems, final GaugeIndex gaugeIndex) { - - /* access real input data from database */ - final String soundingId = diffPair.getSoundingId(); - final String wstId = diffPair.getWstId(); - - final BedHeight bedHeight = loadBedHeight( soundingId, from, to ); - final WKms wstKms = new WDifferencesState().getWKms(wstId, context, from, to); - if( bedHeight == null || wstKms == null ) - return null; - - final FlowDepthCalculationResult resultData = new FlowDepthCalculationResult(wstKms.getName(), bedHeight.getDescription()); - - final String notinrange = Resources.getMsg(context.getMeta(), CSV_NOT_IN_GAUGE_RANGE, CSV_NOT_IN_GAUGE_RANGE); - - // TODO: unklarheiten - // 'idealerweise alle 100m' was heisst das? kann doch nur durch datenverfügbarkeit bestimmt werden - // wie mit unterschiedlichen Ranges umgehen? Schnitt bilden? Fehlermeldung? ...? - // wie interpolieren? wst interpolieren? peilung interpolieren? - - // FIXME: für die Berechnung der TKH sind weitere 'in FLYS vorliegende' Daten notwendig. - // aktuell unklar ob das durch andere Barten berechnete Werte oder Basisdaten sind - // TODO: check Vergleiche BArt 'Transportkörperhöhen' - - // TODO: Berechnung der Transportkörperhöhen - // - woher kommen die zusätzlichen eingangsdaten? sind das fixe daten pro gewässer? --> falls ja, warum nicht einmal berechnen und in db ablegen? - - final String bedHeightLabel = bedHeight.getDescription(); - final String wstLabel = wstKms.getName(); - - for (int i = 0; i < wstKms.size(); i++) { - - final double km = wstKms.getKm(i); - final double wst = wstKms.getW(i); - // FIXME: interpolate from bedheights? - final double meanBedHeight = 79.32; + public CalculationResult calculate(final SINFOArtifact sinfo) { - final double flowDepth = wst - meanBedHeight; - - final double tkh = 0; - final double flowDepthTkh = flowDepth - tkh; - - // FIXME: discharge not available for all wst? or any? - final double discharge = 0.0; - - // REMARK: access the location once only during calculation - final String location = LocationProvider.getLocation(river.getName(), km); - - // REMARK: access the gauge once only during calculation - final Gauge gauge = gaugeIndex.findGauge(km); - final String gaugeLabel = gauge == null ? notinrange : gauge.getName(); - - resultData.addRow( km, flowDepth, flowDepthTkh, tkh, wst, discharge, wstLabel, gaugeLabel, meanBedHeight, bedHeightLabel, location ); - } - - return resultData; - } + // FIXME: find user of this artifact; probably only possible by selecting the collection that contains this artifact... + final String user = "unbekannt"; - private BedHeight loadBedHeight(final String soundingId, final double from, final double to) { - - // FIXME: absolutely unbelievable.... - // The way how bed-heights (and other data too) is accessed is different for nearly ever calculation-type throughout flys. - // The knowledge on how to parse the datacage-ids is spread thorugh the complete code-base... - - // We use here the way on how bed-heights are accessed by the BedDifferenceAccess/BedDifferenceCalculation, but this is plain random - final String[] parts = soundingId.split(";"); - - final BedHeightsArtifact artifact = (BedHeightsArtifact) RiverUtils.getArtifact(parts[0], context); + /* access input data */ + final FlowDepthAccess access = new FlowDepthAccess(sinfo); + final River river = access.getRiver(); - final Integer bedheightId = artifact.getDataAsInteger("height_id"); - // FIXME: this only works with type 'single'; unclear on how to distinguish from epoch data (or whatever the other type means) - // Luckily, the requirement is to only access 'single' data here. - // final String bedheightType = artifact.getDataAsString("type"); - - // FIXME: BedDifferences uses this, but we also need the metadata of the BedHeight - // FIXME: second absolutely awful thing: BedHeight is a hibernate binding class, accessing the database via hibernate stuff - // BedHeightFactory uses its own (direct) way of accessing the data, with its own implemented data classes. - //return BedHeightFactory.getHeight(bedheightType, bedheightId, from, to); - - return BedHeight.getBedHeightById(bedheightId); - } + final Collection<DifferencesPair> diffPairs = access.getDifferencePairs(); + + final double from = access.getFrom(); + final double to = access.getTo(); + + final boolean useTkh = access.isUseTransportBodies(); + + /* calculate results for each diff pair */ + final Calculation problems = new Calculation(); + + final List<Gauge> gauges = river.determineGauges(from, to); + final GaugeIndex gaugeIndex = new GaugeIndex(gauges); + + final String calcModeLabel = Resources.getMsg(this.context.getMeta(),sinfo.getCalculationMode().name() ); + + final FlowDepthCalculationResults results = new FlowDepthCalculationResults(calcModeLabel, user, river, from, to, useTkh); + + for (final DifferencesPair diffPair : diffPairs) { + final FlowDepthCalculationResult result = calculateResult( river, from, to, diffPair, problems, gaugeIndex ); + if( result != null ) + results.addResult(result); + } + + return new CalculationResult(results,problems); + } + + private FlowDepthCalculationResult calculateResult(final River river, final double from, final double to, final DifferencesPair diffPair, final Calculation problems, final GaugeIndex gaugeIndex) { + + /* access real input data from database */ + final String soundingId = diffPair.getSoundingId(); + final String wstId = diffPair.getWstId(); + + final BedHeight bedHeight = loadBedHeight( soundingId, from, to ); + if( bedHeight == null ) + { + final String message = Resources.format(this.context.getMeta(), "Failed to access sounding with id '{0}'", soundingId); + problems.addProblem(message); + return null; + } + + final WKms wstKms = new WDifferencesState().getWKms(wstId, this.context, from, to); + if( wstKms == null ) + { + final String message = Resources.format(this.context.getMeta(), "Failed to access waterlevel with id '{0}'", wstId); + problems.addProblem(message); + return null; + } + + // FIXME: woher bekommen? + final int wspYear = 0; + + final String wspLabel = wstKms.getName(); + final String soundingLabel = bedHeight.getDescription(); + final String label = String.format("%s - %s", wspLabel, soundingLabel); + + final BedHeightInfo sounding = BedHeightInfo.from(bedHeight); + final WstInfo wstInfo = new WstInfo(wspLabel, wspYear); + + final FlowDepthCalculationResult resultData = new FlowDepthCalculationResult(label, wstInfo, sounding); + + final String notinrange = Resources.getMsg(this.context.getMeta(), CSV_NOT_IN_GAUGE_RANGE, CSV_NOT_IN_GAUGE_RANGE); + + // TODO: prüfe diskretisierung wsp --> > 1000m --> Fehlermeldung + + // TODO: Berechnung der Transportkörperhöhen + // - woher kommen die zusätzlichen eingangsdaten? sind das fixe daten pro gewässer? --> falls ja, warum nicht einmal berechnen und in db ablegen? + + // Benötigte Daten + // - Abfluss / Station + // - kein Abfluss --> Fehler + if( !(wstKms instanceof QKms)) + { + final String message = Resources.format(this.context.getMeta(), "{0}: keine Abflussdaten vorhanden, Transportkörperhöhenberechnung nicht möglich", label); + problems.addProblem(message); + // TODO: keine Berechnung TKH + } + + // - Sohlbeschaffenheit (D50 Korndurchmesser aus Seddb) + // - Abhängig von Peiljahr + // - kein D50 vorhanden --> Fehler + // - Art der Gewässersohle (starr/mobil) + + + final String bedHeightLabel = bedHeight.getDescription(); + final String wstLabel = wstKms.getName(); + + // FIXME: basis der diskretisierung ist bedHeight, die wspl werden interpoliert + for (int i = 0; i < wstKms.size(); i++) { + + final double km = wstKms.getKm(i); + final double wst = wstKms.getW(i); + // FIXME: interpolate from bedheights? + final double meanBedHeight = 79.32; + + final double flowDepth = wst - meanBedHeight; + + final double discharge = wstKms instanceof QKms ? ((QKms) wstKms).getQ(i) : Double.NaN; + + // FIXME: calculate tkh + final double tkh = 0; + final double flowDepthTkh = flowDepth - tkh; + + + // REMARK: access the location once only during calculation + final String location = LocationProvider.getLocation(river.getName(), km); + + // REMARK: access the gauge once only during calculation + // FIXME: copy specific handling from original wst + final Gauge gauge = gaugeIndex.findGauge(km); + final String gaugeLabel = gauge == null ? notinrange : gauge.getName(); + + resultData.addRow( km, flowDepth, flowDepthTkh, tkh, wst, discharge, wstLabel, gaugeLabel, meanBedHeight, bedHeightLabel, location ); + } + + return resultData; + } + + private BedHeight loadBedHeight(final String soundingId, final double from, final double to) { + + // FIXME: absolutely unbelievable.... + // The way how bed-heights (and other data too) is accessed is different for nearly ever calculation-type throughout flys. + // The knowledge on how to parse the datacage-ids is spread through the complete code-base... + + // We use here the way on how bed-heights are accessed by the BedDifferenceAccess/BedDifferenceCalculation, but this is plain random + final String[] parts = soundingId.split(";"); + + final BedHeightsArtifact artifact = (BedHeightsArtifact) RiverUtils.getArtifact(parts[0], this.context); + + final Integer bedheightId = artifact.getDataAsInteger("height_id"); + // FIXME: this only works with type 'single'; unclear on how to distinguish from epoch data (or whatever the other type means) + // Luckily, the requirement is to only access 'single' data here. + // final String bedheightType = artifact.getDataAsString("type"); + + // FIXME: BedDifferences uses this, but we also need the metadata of the BedHeight + // FIXME: second absolutely awful thing: BedHeight is a hibernate binding class, accessing the database via hibernate stuff + // BedHeightFactory uses its own (direct) way of accessing the data, with its own implemented data classes. + //return BedHeightFactory.getHeight(bedheightType, bedheightId, from, to); + + return BedHeight.getBedHeightById(bedheightId); + } } \ No newline at end of file