r379 - trunk/coser-business/src/main/java/fr/ifremer/coser/services
Author: chatellier Date: 2010-12-09 14:04:21 +0000 (Thu, 09 Dec 2010) New Revision: 379 Log: Generate zero filled intermediate value in matrix Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-12-08 16:55:58 UTC (rev 378) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-12-09 14:04:21 UTC (rev 379) @@ -2215,11 +2215,13 @@ // map lengthstep, species , strata , year > count Map<Double, Map<String, Map<String, Map<String, Double>>>> countForLengthSpeciesStrataYear = new HashMap<Double, Map<String, Map<String, Map<String, Double>>>>(); - Set<Double> lengthSet = new HashSet<Double>(); Set<String> speciesSet = new HashSet<String>(); Set<String> strataSet = new HashSet<String>(); Set<String> yearsSet = new HashSet<String>(); - + double minLength = Double.MAX_VALUE; + double maxLength = Double.MIN_VALUE; + boolean halfStep = false; + Iterator<String[]> itData = dataContainer.getLength().iterator(); itData.next(); // skip header while (itData.hasNext()) { @@ -2232,6 +2234,13 @@ String numberAsString = tuple[Length.INDEX_NUMBER]; String strata = haulAndStratas.get(haul); + if (strata == null) { + if (log.isWarnEnabled()) { + log.warn("No strata for haul " + haul); + } + continue; + } + // remember for matrix spemantics speciesSet.add(species); strataSet.add(strata); @@ -2241,8 +2250,30 @@ // plain or half centimeters try { double length = Double.parseDouble(lengthAsString); - lengthSet.add(length); + // get length step to use + double ceil = Math.ceil(length); + double floor = Math.floor(length); + double round = Math.round(length); + + // on prend le pas ou demi pas le plus proche + if (ceil == round) { + length = floor + 0.5; + } + else { + length = floor; + } + + if (length < minLength) { + minLength = length; + } + if (length > maxLength) { + maxLength = length; + } + if (length - Math.floor(length) != 0.0) { + halfStep = true; + } + try { double number = Double.parseDouble(numberAsString); @@ -2287,6 +2318,11 @@ } } + Set<Double> lengthSet = new HashSet<Double>(); + for (double length = minLength ; length <= maxLength ; length += (halfStep) ? 0.5 : 1) { + lengthSet.add(length); + } + // convert map to matrixND List<Double> lengthSem = new ArrayList<Double>(lengthSet); Collections.sort(lengthSem); @@ -2304,7 +2340,7 @@ matrix.setDimensionName(2, n_("coser.business.common.strata")); matrix.setDimensionName(3, n_("coser.business.common.years")); - for (Map.Entry<Double, Map<String, Map<String, Map<String, Double>>>> lengthTuple : countForLengthSpeciesStrataYear.entrySet()) { + /*for (Map.Entry<Double, Map<String, Map<String, Map<String, Double>>>> lengthTuple : countForLengthSpeciesStrataYear.entrySet()) { Double length = lengthTuple.getKey(); for (Map.Entry<String, Map<String, Map<String, Double>>> speciesTuple : lengthTuple.getValue().entrySet()) { String species = speciesTuple.getKey(); @@ -2316,6 +2352,31 @@ } } } + }*/ + + for (double length = minLength ; length <= maxLength ; length += (halfStep) ? 0.5 : 1) { + for (String species : speciesSem) { + for (String strata : strataSem) { + for (String year : yearsSem) { + + double value = 0.0; + Map<String, Map<String, Map<String, Double>>> lengthTuple = countForLengthSpeciesStrataYear.get(length); + if (lengthTuple != null) { + Map<String, Map<String, Double>> speciesTuple = lengthTuple.get(species); + if (speciesTuple != null) { + Map<String, Double> strataTuple = speciesTuple.get(strata); + if (strataTuple != null) { + Double number = strataTuple.get(year); + if (number != null) { + value = number; + } + } + } + } + matrix.setValue(new Object[]{length, species, strata, year}, value); + } + } + } } return matrix;
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org