r579 - trunk/coser-business/src/main/java/fr/ifremer/coser/services
Author: chatellier Date: 2011-01-25 22:43:11 +0000 (Tue, 25 Jan 2011) New Revision: 579 Log: Ajout du nouveau calcul de fichier meta des indicateurs de communaut?\195?\169s Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-25 21:45:27 UTC (rev 578) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-25 22:43:11 UTC (rev 579) @@ -1589,7 +1589,7 @@ // extraction des especes pour le résultat demandé if (rsufiResult.getZone() != null && rsufiResult.getZone().equals(zone)) { - result = getChartDataFile(resultFile, rsufiResult, species, indicator); + result = getChartDataFile(projectsDirectory, projectFile, selectionFile, resultFile, rsufiResult, species, indicator, locale); break; } } @@ -1608,14 +1608,19 @@ /** * Generate chart data (as csv for population and as zip for community). * + * @param projectsDirectory projects storage directory + * @param projectDirectory current project directory + * @param selectionDirectory selection directory * @param resultDirectory rsufi result directory * @param rSufiResult rsufi result * @param string species species (can be null for community) * @param indicator indicator + * @param locale locale (fr/en) * @return generated file (auto delete when jvm shutdown) * @throws CoserBusinessException */ - protected File getChartDataFile(File resultDirectory, RSufiResult rSufiResult, String species, String indicator) throws CoserBusinessException { + protected File getChartDataFile(File projectsDirectory, File projectDirectory, File selectionDirectory, + File resultDirectory, RSufiResult rSufiResult, String species, String indicator, String locale) throws CoserBusinessException { File result = null; @@ -1632,11 +1637,13 @@ FileUtils.copyFileToDirectory(csvFile, baseDir); // ajout du fichier d'information sur les espèces incluses dans - //les calculs des indicateurs de communautés + // les calculs des indicateurs de communautés // load project (without data to get reftax data) - //Project project = projectService.openProject(projectFile.getName(), projectsDirectory); - //File metaFile = generateMetaFilePDF(project, resultFile, rsufiResult, indicator, locale); - + Project project = projectService.openProject(projectDirectory.getName(), projectsDirectory); + Selection selection = project.getSelections().get(selectionDirectory.getName()); + File metaFile = generateMetaFilePDF(project, selection, resultDirectory, rSufiResult, indicator, locale); + FileUtils.copyFileToDirectory(metaFile, baseDir); + // make zip result = File.createTempFile("coserchartdatazip-", ".zip"); result.deleteOnExit(); @@ -1962,6 +1969,7 @@ * calculs des indicateurs de communautés, à jointe à chaque téléchargement. * * @param project project + * @param selection selection * @param resultDirectory result directory * @param rsufiResult rsufi result * @param indicator indicator @@ -1969,50 +1977,115 @@ * @return generated pdf file * @throws CoserBusinessException */ - protected File generateMetaFilePDF(Project project, File resultDirectory, + protected File generateMetaFilePDF(Project project, Selection selection, File resultDirectory, RSufiResult rsufiResult, String indicator, String locale) throws CoserBusinessException { File result = null; + // chargement du reftax et des code types especes pour connaitre + // le type des especes de poissons + // parcourt du fichier des types de données + Map<String, Integer> refTaxSpecies = new HashMap<String, Integer>(); + Iterator<String[]> itReftax = project.getRefTaxSpecies().iterator(true); + while (itReftax.hasNext() ) { + String[] tuple = itReftax.next(); + // "C_Perm","NumSys","NivSys","C_VALIDE","L_VALIDE","AA_VALIDE","C_TxP\u00E8re","Taxa" + String specyName = tuple[3]; + Integer iNumSys = Integer.valueOf(tuple[1]); + refTaxSpecies.put(specyName, iNumSys); + } + + Map<String, Integer[]> specyTypes = new HashMap<String, Integer[]>(); + Iterator<String[]> itTypeSpecies = project.getTypeEspeces().iterator(true); + while (itTypeSpecies.hasNext()) { + // "Types";"Commentaire";"NumSys min";"NumSys max","Code" + String[] tuple = itTypeSpecies.next(); + String specyTypeCode = tuple[4]; + + Integer iMinNumSys = Integer.valueOf(tuple[2]); + Integer iMaxNumSys = Integer.valueOf(tuple[3]); + specyTypes.put(specyTypeCode, new Integer[]{iMinNumSys, iMaxNumSys}); + } + // le fichier estpopind - File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName()); + File estComIndFile = new File(resultDirectory, rsufiResult.getEstComIndName()); // donnees intermediare (map liste id > liste des indicateurs) Map<String, SortedSet<String>> indicatorMap = new HashMap<String, SortedSet<String>>(); // le resutat sera une map complexe - // list des indicateurs (nom complet) > liste des especes (nom complet) + // map liste id > liste des especes (nom complet) Map<String, SortedSet<String>> speciesMap = new HashMap<String, SortedSet<String>>(); - // Campagne Indicateur Liste Species Strate Annee Estimation EcartType CV - DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + DataStorage dataStorage = importService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); Iterator<String[]> estPopIndIterator = dataStorage.iterator(true); while (estPopIndIterator.hasNext()) { String[] tuple = estPopIndIterator.next(); String indicatorCode = tuple[1]; - String listIdCode = tuple[2]; - String speciesCode = tuple[3]; + String listIdCode = tuple[2]; // c1, p2, T3 ... + String listNumber = listIdCode.substring(1); // 1, 2, 3 + // get indicator list SortedSet<String> indicatorList = indicatorMap.get(listIdCode); if (indicatorList == null) { indicatorList = new TreeSet<String>(); - indicatorMap.put(listIdCode, indicatorList); + indicatorMap.put(listNumber, indicatorList); } // get indicator full name String indicatorName = (String)getIndicatorsMap().get(indicatorCode, locale); indicatorList.add(indicatorName); + } + + // seconde pass, remplit la map speciesMap avec les listes configurées + // dans la selection + for (String listNumber : indicatorMap.keySet()) { + List<String> selectionSpeciesList = null; + if ("1".equals(listNumber)) { + selectionSpeciesList = selection.getSelectedSpecies(); + } + else if ("2".equals(listNumber)) { + selectionSpeciesList = selection.getSelectedSpeciesOccDens(); + } + else if ("3".equals(listNumber)) { + selectionSpeciesList = selection.getSelectedSpeciesSizeAllYear(); + } + else if ("4".equals(listNumber)) { + selectionSpeciesList = selection.getSelectedSpeciesMaturity(); + } - // get species full name - String speciesName = projectService.getSpeciesDisplayName(project, speciesCode); - SortedSet<String> speciesList = speciesMap.get(listIdCode); - if (speciesList == null) { - speciesList = new TreeSet<String>(); - speciesMap.put(listIdCode, speciesList); + if (selectionSpeciesList != null) { + SortedSet<String> speciesList = new TreeSet<String>(); + + for (String speciesCode : selectionSpeciesList) { + // get species full name + String speciesName = projectService.getSpeciesDisplayName(project, speciesCode); + + // recupere le code type de l'espece, "m", "c", "p" ... + Integer speciesNumSys = refTaxSpecies.get(speciesCode); + for (Map.Entry<String, Integer[]> speciesTypeEntry : specyTypes.entrySet()) { + String speciesTypeCode = speciesTypeEntry.getKey(); + Integer[] bound = speciesTypeEntry.getValue(); + + if (speciesNumSys >= bound[0] && speciesNumSys <= bound[1]) { + speciesName = speciesTypeCode + " : " + speciesName; + break; + } + } + // end code type espece + + speciesList.add(speciesName); + } + speciesMap.put(listNumber, speciesList); } - speciesList.add(speciesName); + else { + if (log.isWarnEnabled()) { + log.warn("Can't get species list for list id " + listNumber); + } + } } try {
participants (1)
-
chatellier@users.labs.libre-entreprise.org