r373 - in trunk/coser-business/src: main/java/fr/ifremer/coser/services test/java/fr/ifremer/coser/services
Author: chatellier Date: 2010-12-07 13:13:56 +0000 (Tue, 07 Dec 2010) New Revision: 373 Log: Ajout du calcul de la structure en taille. Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.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-06 15:13:09 UTC (rev 372) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-12-07 13:13:56 UTC (rev 373) @@ -2185,6 +2185,135 @@ } /** + * Présentation du graphique : histogramme de distribution en tailles par + * espèce, par strate et par année (une planche par espèce et par année) + * pour toute la série. Avec la possibilité de voir regroupé l'ensemble des + * années. + * + * Données. TAILLES$Nombres et TAILLES$Longueur + * Calcul. Sommer TAILLES$Nombres par classe de longueur (TAILLES$Longueur) + * sur tous les traits d'une année (ou tous les années si regroupé) + * + * @param project project + * @param selection data container + * @return matrix 4 dimension + */ + public MatrixND getLengthStructure(Project project, Selection selection) { + + // load map traitname > stratename + Map<String, String> haulAndStratas = new HashMap<String, String>(); + Iterator<String[]> itHaul = selection.getHaul().iterator(); + itHaul.next(); // skip header + while (itHaul.hasNext()) { + String[] tuple = itHaul.next(); + String haul = tuple[Haul.INDEX_HAUL]; + String strataName = tuple[Haul.INDEX_STRATUM]; + haulAndStratas.put(haul, strataName); + } + + // 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> yearSet = new HashSet<String>(); + + Iterator<String[]> itData = selection.getLength().iterator(); + itData.next(); // skip header + + while (itData.hasNext()) { + String[] tuple = itData.next(); + + String year = tuple[Length.INDEX_YEAR]; + String haul = tuple[Length.INDEX_HAUL]; + String species = tuple[Length.INDEX_SPECIES]; + String lengthAsString = tuple[Length.INDEX_LENGTH]; + String numberAsString = tuple[Length.INDEX_NUMBER]; + String strata = haulAndStratas.get(haul); + + // remember for matrix spemantics + speciesSet.add(species); + strataSet.add(strata); + yearSet.add(year); + + // get correct length step + // plain or half centimeters + try { + double length = Double.parseDouble(lengthAsString); + lengthSet.add(length); + + try { + double number = Double.parseDouble(numberAsString); + + // fill map + Map<String, Map<String, Map<String, Double>>> lengthCountForSpeciesStrataYear = countForLengthSpeciesStrataYear.get(length); + if (lengthCountForSpeciesStrataYear == null) { + lengthCountForSpeciesStrataYear = new HashMap<String, Map<String,Map<String,Double>>>(); + countForLengthSpeciesStrataYear.put(length, lengthCountForSpeciesStrataYear); + } + + Map<String, Map<String, Double>> speciesCountForStrataYear = lengthCountForSpeciesStrataYear.get(species); + if (speciesCountForStrataYear == null) { + speciesCountForStrataYear = new HashMap<String, Map<String,Double>>(); + lengthCountForSpeciesStrataYear.put(species, speciesCountForStrataYear); + } + + Map<String, Double> strataCountForYear = speciesCountForStrataYear.get(strata); + if (strataCountForYear == null) { + strataCountForYear = new HashMap<String, Double>(); + speciesCountForStrataYear.put(strata, strataCountForYear); + } + + Double countForYear = strataCountForYear.get(year); + if (countForYear == null) { + strataCountForYear.put(year, number); + } + else { + double newCount = countForYear + number; + strataCountForYear.put(year, newCount); + } + } + catch (NumberFormatException ex) { + if (log.isWarnEnabled()) { + log.warn("Can't parse number as double : " + numberAsString); + } + } + } + catch (NumberFormatException ex) { + if (log.isWarnEnabled()) { + log.warn("Can't parse length as double : " + lengthAsString); + } + } + } + + // convert map to matrixND + List<Double> lengthSem = new ArrayList<Double>(lengthSet); + List<String> speciesSem = new ArrayList<String>(speciesSet); + List<String> strataSem = new ArrayList<String>(strataSet); + List<String> yearSem = new ArrayList<String>(yearSet); + + MatrixND matrix = MatrixFactory.getInstance().create("density", new List<?>[] { + lengthSem , speciesSem, strataSem, yearSem}); + + 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(); + for (Map.Entry<String, Map<String, Double>> strataTuple : speciesTuple.getValue().entrySet()) { + String strata = strataTuple.getKey(); + for (Map.Entry<String, Double> yearTuple : strataTuple.getValue().entrySet()) { + String year = yearTuple.getKey(); + matrix.setValue(new Object[]{length, species, strata, year}, yearTuple.getValue()); + } + } + } + } + + return matrix; + } + + /** * Extrait les données de la selection * * @param project project Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2010-12-06 15:13:09 UTC (rev 372) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2010-12-07 13:13:56 UTC (rev 373) @@ -438,4 +438,18 @@ MatrixND matrix = projectService.getDensity(project, selection); Assert.assertNotNull(matrix); } + + /** + * Test de la méthode de structure en taille. + * + * @throws CoserBusinessException + */ + @Test + public void getLengthStructure() throws CoserBusinessException { + Project project = createTestProject(projectService, true); + Selection selection = projectService.initProjectSelection(project); + selection.setName("test"); + MatrixND matrix = projectService.getLengthStructure(project, selection); + Assert.assertNotNull(matrix); + } }
participants (1)
-
chatellier@users.labs.libre-entreprise.org