Author: bleny Date: 2010-11-02 16:41:38 +0000 (Tue, 02 Nov 2010) New Revision: 723 Log: bugfix synthesis indicators when using complex filter Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorLevelImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java 2010-11-02 16:38:53 UTC (rev 722) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java 2010-11-02 16:41:38 UTC (rev 723) @@ -48,10 +48,13 @@ log.debug("in values : " + value.getKey() + " -> " + value.getValue()); } } + Double value = values.get(synthesisId); - - Indicator indicator = findIndicator(synthesisId); - IndicatorLevel result = indicator.getLevelForValue(value); + IndicatorLevel result = null; + if (value != null) { + Indicator indicator = findIndicator(synthesisId); + result = indicator.getLevelForValue(value); + } return result; } @@ -63,8 +66,15 @@ double totalCoefficients = 0.0; for (Indicator indicator : globalSynthesisParameters) { - double value = values.get(indicator.getSynthesisId()); - double level = indicator.getLevelForValue(value).getLevel(); + IndicatorLevel indicatorLevel = getLevelForIndicator(indicator.getSynthesisId()); + + if (indicatorLevel == null) { + // since we can't compute a level for this indicator, + // it's not possible to consider a coherent global level value + return null; + } + + double level = indicatorLevel.getLevel(); double coefficient = indicator.getCoefficient(); totalLevels += level * coefficient; Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorImpl.java 2010-11-02 16:38:53 UTC (rev 722) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorImpl.java 2010-11-02 16:41:38 UTC (rev 723) @@ -1,12 +1,17 @@ package fr.ifremer.wao.entity; import fr.ifremer.wao.bean.SynthesisId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * */ public class IndicatorImpl extends IndicatorAbstract { + private static final Logger log = + LoggerFactory.getLogger(IndicatorImpl.class); + @Override public SynthesisId getSynthesisId() { return SynthesisId.valueOf(getIndicatorId()); @@ -25,6 +30,9 @@ return level; } } + if (log.isWarnEnabled()) { + log.warn("no level found for value " + value); + } return null; } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorLevelImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorLevelImpl.java 2010-11-02 16:38:53 UTC (rev 722) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorLevelImpl.java 2010-11-02 16:41:38 UTC (rev 723) @@ -11,6 +11,8 @@ /** the upperBound of the lower level */ protected double lowerBound; + protected boolean upperBoundIncluded = false; + @Override public double getLowerBound() { return lowerBound; @@ -44,8 +46,11 @@ */ @Override public boolean containsValue(double value) { - boolean containsValue; - if (lowerEqualsUpperBounds()) { + boolean containsValue = false; + + if (upperBoundIncluded && value == upperBound) { + containsValue = true; + } else if (lowerEqualsUpperBounds()) { containsValue = value == getUpperBound(); } else { if (getLowerBound() < getUpperBound()) { @@ -65,4 +70,11 @@ return containsValue; } + public boolean isUpperBoundIncluded() { + return upperBoundIncluded; + } + + public void setUpperBoundIncluded(boolean upperBoundIncluded) { + this.upperBoundIncluded = upperBoundIncluded; + } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-11-02 16:38:53 UTC (rev 722) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-11-02 16:41:38 UTC (rev 723) @@ -254,6 +254,14 @@ Long maxValue = (Long)max.get(countAlias); result.setMaxBoardingValue(maxValue.intValue()); } + + if (log.isDebugEnabled()) { + log.debug("results in data from getBoardingBoat "); + for (Map.Entry<String, Integer> entry : result.getData().entrySet()) { + log.debug(entry.getKey() + " -> " + entry.getValue()); + } + } + return result; } @@ -369,6 +377,13 @@ Double compliance = 1.0 - nonCompliance.getValue(); compliances.put(nonCompliance.getKey(), compliance); } + + if (log.isDebugEnabled()) { + log.debug("getComplianceBoarding return values"); + for (Map.Entry<String, Double> compliance : compliances.entrySet()) { + log.debug(compliance.getKey() + " -> " + compliance.getValue()); + } + } return compliances; } @@ -624,6 +639,18 @@ } } + // + if (filter.getCompany() != null && ! results.containsKey(filter.getCompany().getName())) { + results.put(filter.getCompany().getName(), 1.0); + } + + + if (log.isDebugEnabled()) { + for (Map.Entry<String, Double> result : results.entrySet()) { + log.debug("result : " + result.getKey() + " -> " + result.getValue()); + } + } + return results; } @@ -722,6 +749,7 @@ return percentRealized; } + /** return null if 0 boarding */ protected Double getIndicatorValueForBoarding(SamplingFilter filter) { BoardingResult boardingResult = getBoardingBoats(filter); int numberOfBoatWithOneBoarding = boardingResult.getData().get("1"); @@ -729,8 +757,11 @@ for (Integer numberOfBoarding : boardingResult.getData().values()) { totalNumberOfBoarding += numberOfBoarding; } - double rate = ((double) numberOfBoatWithOneBoarding / - (double) totalNumberOfBoarding) * 100.0; + Double rate = null; + if (totalNumberOfBoarding > 0) { + rate = ((double) numberOfBoatWithOneBoarding / + (double) totalNumberOfBoarding) * 100.0; + } return rate; } @@ -741,7 +772,11 @@ for (Double compliance : complianceBoarding.values()) { total += compliance; } - double indicatorValue = 100 * (total / numberOfCompanies); + + Double indicatorValue = null; + if (numberOfCompanies > 0) { + indicatorValue = 100 * (total / numberOfCompanies); + } return indicatorValue; } @@ -766,7 +801,10 @@ for (Double reliabilityRate : dataReliability.values()) { total += reliabilityRate; } - double indicatorValue = 100 * (total / numberOfCompanies); + Double indicatorValue = null; + if (numberOfCompanies > 0) { + indicatorValue = 100 * (total / numberOfCompanies); + } return indicatorValue; } @@ -792,11 +830,13 @@ value = getIndicatorValueForDataReliability(filter); indicatorValues.put(SynthesisId.IND_DATA_RELIABILITY, value); + GlobalSynthesisResultImpl result = null; + + result = new GlobalSynthesisResultImpl(); List<Indicator> indicators = executeGetGlobalSynthesisParameters(transaction); - - GlobalSynthesisResultImpl result = new GlobalSynthesisResultImpl(); result.setIndicatorValues(indicatorValues); result.setGlobalSynthesisParameters(indicators); + return result; } @@ -827,11 +867,12 @@ } // Finally, adding a last level - IndicatorLevel lastIndicatorLevel = new IndicatorLevelImpl(); + IndicatorLevelImpl lastIndicatorLevel = new IndicatorLevelImpl(); int nextLevelNumber = levels.size() + 1; lastIndicatorLevel.setLevel(nextLevelNumber); lastIndicatorLevel.setLowerBound(lowerBound); lastIndicatorLevel.setUpperBound(lastUpperBound); + lastIndicatorLevel.setUpperBoundIncluded(true); indicator.getIndicatorLevel().add(lastIndicatorLevel); // we don't store nor commit anything, those modification are only @@ -948,3 +989,4 @@ } } +