Author: tchemit Date: 2013-07-12 18:07:22 +0200 (Fri, 12 Jul 2013) New Revision: 1135 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1135 Log: refs #2872: [EXPORT GENERIQUE] le calcul du coef ne marche pas : ex. trait 2 Alosa Alosa Vrac on obtient pas le m?\195?\170me poids dans la capture Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/CatchExportModel.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/TuttiExportService.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/CatchExportModel.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/CatchExportModel.java 2013-07-10 15:47:03 UTC (rev 1134) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/CatchExportModel.java 2013-07-12 16:07:22 UTC (rev 1135) @@ -135,9 +135,19 @@ row.addComment(speciesBatch.getComment()); if (TuttiEntities.isVracSpeciesBatch(speciesBatch)) { + + // compute species total weight in catch + + float sortedBatchWeight = TuttiExportService.getValueOrComputedValue( + speciesBatch.getSampleCategoryWeight(), + speciesBatch.getSampleCategoryComputedWeight()); + + float totalBatchWeight = speciesCatchRaisingFactor * + sortedBatchWeight; + prepareSortedRows(persistenceService, row, rows, speciesBatch, - speciesCatchRaisingFactor + totalBatchWeight ); } else { prepareUnsortedRows(row, rows, speciesBatch); @@ -151,9 +161,19 @@ row.setSpecies(benthosBatch.getSpecies()); row.addComment(benthosBatch.getComment()); if (TuttiEntities.isVracBenthosBatch(benthosBatch)) { + + // compute species total weight in catch + + float sortedBatchWeight = TuttiExportService.getValueOrComputedValue( + benthosBatch.getSampleCategoryWeight(), + benthosBatch.getSampleCategoryComputedWeight()); + + float totalBatchWeight = benthosCatchRaisingFactor * + sortedBatchWeight; + prepareSortedRows(persistenceService, row, rows, benthosBatch, - benthosCatchRaisingFactor); + totalBatchWeight); } else { prepareUnsortedRows(row, rows, benthosBatch); } @@ -164,7 +184,7 @@ CatchExportRow currentRow, List<CatchExportRow> rows, SpeciesBatch speciesBatch, - Float raisingFactor) { + final float totalBatchWeight) { prepareBatch(currentRow, speciesBatch.getSampleCategoryType(), @@ -185,27 +205,27 @@ // check if there is a sub sampling weight // if so then adapt raisingFactor - Float subWeight = TuttiExportService.getValueOrComputedValue( - speciesBatch.getWeight(), speciesBatch.getComputedWeight()); +// Float subWeight = TuttiExportService.getValueOrComputedValue( +// speciesBatch.getWeight(), speciesBatch.getComputedWeight()); +// +// if (subWeight != null) { +// +// float batchWeight = TuttiExportService.getValueOrComputedValue( +// speciesBatch.getSampleCategoryWeight(), +// speciesBatch.getSampleCategoryComputedWeight()); +// +// if (batchWeight - subWeight > 0.0001f) { +// // sub sample, adapt raising factor +// raisingFactor *= batchWeight / subWeight; +// +// if (log.isDebugEnabled()) { +// log.debug("Using a sub sample on leaf : " + +// subWeight + " out of " + batchWeight + +// ", new raising Factor= " + raisingFactor); +// } +// } +// } - if (subWeight != null) { - - float batchWeight = TuttiExportService.getValueOrComputedValue( - speciesBatch.getSampleCategoryWeight(), - speciesBatch.getSampleCategoryComputedWeight()); - - if (batchWeight - subWeight > 0.0001f) { - // sub sample, adapt raising factor - raisingFactor *= batchWeight / subWeight; - - if (log.isDebugEnabled()) { - log.debug("Using a sub sample on leaf : " + - subWeight + " out of " + batchWeight + - ", new raising Factor= " + raisingFactor); - } - } - } - if (CollectionUtils.isEmpty(speciesBatchFrequency)) { // no frequency @@ -224,9 +244,7 @@ speciesBatch.getSampleCategoryWeight(), speciesBatch.getSampleCategoryComputedWeight()); } - setRaisingFactor(row, - raisingFactor, - referenceWeight); + setRaisingFactor(row, totalBatchWeight, referenceWeight); rows.add(row); } else { @@ -263,9 +281,7 @@ referenceWeight = batchFrequency.getWeight(); } - setRaisingFactor(row, - raisingFactor, - referenceWeight); + setRaisingFactor(row, totalBatchWeight, referenceWeight); } } @@ -275,40 +291,40 @@ // Compute total child weights (to adapt raising factor if necessary) - float childTotalWeight = 0f; - for (SpeciesBatch childBatch : speciesBatch.getChildBatchs()) { - float childWeight = TuttiExportService.getValueOrComputedValue( - childBatch.getSampleCategoryWeight(), - childBatch.getSampleCategoryComputedWeight()); - childTotalWeight += childWeight; - } +// float childTotalWeight = 0f; +// for (SpeciesBatch childBatch : speciesBatch.getChildBatchs()) { +// float childWeight = TuttiExportService.getValueOrComputedValue( +// childBatch.getSampleCategoryWeight(), +// childBatch.getSampleCategoryComputedWeight()); +// childTotalWeight += childWeight; +// } - float currentWeight = TuttiExportService.getValueOrComputedValue( - speciesBatch.getSampleCategoryWeight(), - speciesBatch.getSampleCategoryComputedWeight()); +// float currentWeight = TuttiExportService.getValueOrComputedValue( +// speciesBatch.getSampleCategoryWeight(), +// speciesBatch.getSampleCategoryComputedWeight()); - if (currentWeight - childTotalWeight > 0.0001f) { +// if (currentWeight - childTotalWeight > 0.0001f) { +// +// // there is a sub sampling +// // adapt raising factor +// +// // sub sample, adapt raising factor +// raisingFactor *= currentWeight / childTotalWeight; +// +// if (log.isDebugEnabled()) { +// log.debug("Using a sub sample for childs of category " + +// speciesBatch + ": " + childTotalWeight + +// " out of " + currentWeight + +// ", new raising Factor= " + raisingFactor); +// } +// } - // there is a sub sampling - // adapt raising factor - - // sub sample, adapt raising factor - raisingFactor *= currentWeight / childTotalWeight; - - if (log.isDebugEnabled()) { - log.debug("Using a sub sample for childs of category " + - speciesBatch + ": " + childTotalWeight + - " out of " + currentWeight + - ", new raising Factor= " + raisingFactor); - } - } - for (SpeciesBatch childBatch : speciesBatch.getChildBatchs()) { prepareSortedRows(persistenceService, currentRow, rows, childBatch, - raisingFactor + totalBatchWeight ); } } @@ -331,8 +347,11 @@ float referenceWeight = TuttiExportService.getValueOrComputedValue( speciesBatch.getSampleCategoryWeight(), speciesBatch.getSampleCategoryComputedWeight()); - row.setReferenceWeight(referenceWeight); - row.setRaisingFactor(1.f); + + setRaisingFactor(row, referenceWeight, referenceWeight); + +// row.setReferenceWeight(referenceWeight); +// row.setRaisingFactor(1.f); rows.add(row); } @@ -340,7 +359,7 @@ CatchExportRow currentRow, List<CatchExportRow> rows, BenthosBatch benthosBatch, - Float raisingFactor) { + final float totalBatchWeight) { prepareBatch(currentRow, benthosBatch.getSampleCategoryType(), @@ -358,31 +377,31 @@ List<BenthosBatchFrequency> benthosBatchFrequency = persistenceService.getAllBenthosBatchFrequency(benthosBatch.getId()); - // check if there is a sub sampling weight - // if so then adapt raisingFactor +// // check if there is a sub sampling weight +// // if so then adapt raisingFactor +// +// Float subWeight = TuttiExportService.getValueOrComputedValue( +// benthosBatch.getWeight(), +// benthosBatch.getComputedWeight()); +// +// if (subWeight != null) { +// +// float batchWeight = TuttiExportService.getValueOrComputedValue( +// benthosBatch.getSampleCategoryWeight(), +// benthosBatch.getSampleCategoryComputedWeight()); +// +// if (batchWeight - subWeight > 0.0001f) { +// // sub sample, adapt raising factor +// raisingFactor *= batchWeight / subWeight; +// +// if (log.isDebugEnabled()) { +// log.debug("Using a sub sample on leaf : " + subWeight +// + " out of " + batchWeight + +// ", new raising Factor= " + raisingFactor); +// } +// } +// } - Float subWeight = TuttiExportService.getValueOrComputedValue( - benthosBatch.getWeight(), - benthosBatch.getComputedWeight()); - - if (subWeight != null) { - - float batchWeight = TuttiExportService.getValueOrComputedValue( - benthosBatch.getSampleCategoryWeight(), - benthosBatch.getSampleCategoryComputedWeight()); - - if (batchWeight - subWeight > 0.0001f) { - // sub sample, adapt raising factor - raisingFactor *= batchWeight / subWeight; - - if (log.isDebugEnabled()) { - log.debug("Using a sub sample on leaf : " + subWeight - + " out of " + batchWeight + - ", new raising Factor= " + raisingFactor); - } - } - } - if (CollectionUtils.isEmpty(benthosBatchFrequency)) { // no frequency @@ -401,9 +420,7 @@ benthosBatch.getSampleCategoryComputedWeight()); } - setRaisingFactor(row, - raisingFactor, - referenceWeight); + setRaisingFactor(row, totalBatchWeight, referenceWeight); rows.add(row); } else { @@ -440,7 +457,7 @@ referenceWeight = batchFrequency.getWeight(); } - setRaisingFactor(row, raisingFactor, referenceWeight); + setRaisingFactor(row, totalBatchWeight, referenceWeight); } } @@ -450,39 +467,40 @@ // Compute total child weights (to adapt raising factor if necessary) - float childTotalWeight = 0f; - for (BenthosBatch childBatch : benthosBatch.getChildBatchs()) { - float childWeight = TuttiExportService.getValueOrComputedValue( - childBatch.getSampleCategoryWeight(), - childBatch.getSampleCategoryComputedWeight()); - childTotalWeight += childWeight; - } +// float childTotalWeight = 0f; +// for (BenthosBatch childBatch : benthosBatch.getChildBatchs()) { +// float childWeight = TuttiExportService.getValueOrComputedValue( +// childBatch.getSampleCategoryWeight(), +// childBatch.getSampleCategoryComputedWeight()); +// childTotalWeight += childWeight; +// } - Float currentWeight = TuttiExportService.getValueOrComputedValue( - benthosBatch.getSampleCategoryWeight(), - benthosBatch.getSampleCategoryComputedWeight()); +// Float currentWeight = TuttiExportService.getValueOrComputedValue( +// benthosBatch.getSampleCategoryWeight(), +// benthosBatch.getSampleCategoryComputedWeight()); +// +// if (currentWeight - childTotalWeight > 0.0001f) { +// +// // there is a sub sampling +// // adapt raising factor +// +// // sub sample, adapt raising factor +// raisingFactor *= currentWeight / childTotalWeight; +// +// if (log.isDebugEnabled()) { +// log.debug("Using a sub sample for childs of category " + +// benthosBatch + ": " + childTotalWeight + +// " out of " + currentWeight + +// ", new raising Factor= " + raisingFactor); +// } +// } - if (currentWeight - childTotalWeight > 0.0001f) { - - // there is a sub sampling - // adapt raising factor - - // sub sample, adapt raising factor - raisingFactor *= currentWeight / childTotalWeight; - - if (log.isDebugEnabled()) { - log.debug("Using a sub sample for childs of category " + - benthosBatch + ": " + childTotalWeight + - " out of " + currentWeight + - ", new raising Factor= " + raisingFactor); - } - } for (BenthosBatch childBatch : benthosBatch.getChildBatchs()) { prepareSortedRows(persistenceService, currentRow, rows, childBatch, - raisingFactor); + totalBatchWeight); } } } @@ -505,16 +523,17 @@ float referenceWeight = TuttiExportService.getValueOrComputedValue( benthosBatch.getSampleCategoryWeight(), benthosBatch.getSampleCategoryComputedWeight()); - row.setReferenceWeight(referenceWeight); - row.setRaisingFactor(1.f); + + setRaisingFactor(row, referenceWeight, referenceWeight); + rows.add(row); } protected void setRaisingFactor(CatchExportRow row, - float raisingFactor, + float totalBatchWeight, float referenceWeight) { row.setReferenceWeight(referenceWeight); - row.setRaisingFactor(raisingFactor); + row.setRaisingFactor(totalBatchWeight / referenceWeight); } protected void prepareBatch(CatchExportRow currentRow, Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/TuttiExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/TuttiExportService.java 2013-07-10 15:47:03 UTC (rev 1134) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/TuttiExportService.java 2013-07-12 16:07:22 UTC (rev 1135) @@ -402,7 +402,7 @@ List<GearCaracteristicExportRow> rows = Lists.newArrayList(); - for (Gear gear : cruise.getGear() ) { + for (Gear gear : cruise.getGear()) { Gear gearWithCaracteristics = persistenceService.getGearWithCaracteristics(gear, cruise); exportContext.gearCaracteristicsModel.prepareRows(rows, cruise, gearWithCaracteristics); @@ -554,7 +554,7 @@ catchBatch.getCatchTotalWeight(), catchBatch.getCatchTotalComputedWeight()); - Float totalUnsortedWeight = + float totalUnsortedWeight = catchBatch.getCatchTotalUnsortedComputedWeight(); @@ -574,6 +574,7 @@ Float totalSortedWeight = catchBatch.getCatchTotalSortedComputedWeight(); + //FIXME tchemit 2013-07-12 J'utilise en fait la formule (Poids de la capture totale - poids du HV dans la capture totale) / (poids total capture triée) // (Poids de la capture totale - poids du HV dans la capture totale) / (poids total capture triée - poids du HV dans la capture totale) Float catchRaisingFactor = (totalWeight - totalUnsortedWeight) / totalSortedWeight; @@ -591,7 +592,7 @@ "\nspeciesCatchRaisingFactor : " + speciesCatchRaisingFactor + "\nbenthosCatchRaisingFactor : " + benthosCatchRaisingFactor; - log.debug(message); + log.info(message); } List<CatchExportRow> rows = Lists.newArrayList(); Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java 2013-07-10 15:47:03 UTC (rev 1134) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java 2013-07-12 16:07:22 UTC (rev 1135) @@ -76,13 +76,13 @@ public static final String CATCH_CONTENT = "Annee;Serie;Serie_Partielle;Engin;Id_Operation;NumOrdre_Station;Poche;Navire;Taxon;Nom scientifique;Commentaire;VracHorsVrac;Num_Ordre_VracHorsVrac_H2;Tot_VracHorsVrac;Ech_VracHorsVrac;Type_Volume_Poids_VracHorsVrac;Unite_Volume_Poids_VracHorsVrac;Cat_Tri;Num_Ordre_Cat_Tri_H2;Tot_Cat_Tri;Ech_Cat_Tri;Type_Volume_Poids_Cat_Tri;Unite_Volume_Poids_Cat_Tri;Sexe;Num_Ordre_Sexe_H2;Tot_Sexe;Ech_Sexe;Type_Volume_Poids_Sexe;Unite_Volume_Poids_Sexe;Maturite;Num_Ordre_Maturite_H2;Tot_Maturite;Ech_Maturite;Type_Volume_Poids_Maturite;Unite_Volume_Poids_Maturite;Age;Num_Ordre_Age_H2;Tot_Age;Ech_Age;Type_Volume_Poids_Age;Unite_Volume_Poids_Age;Code_Longueur;Libelle_Longueur;Taille;NumOrdre_Taille_H2;Poids_Classe_Taille;Unite_Taille;Precision_Mesure;Nbr;Poids_Reference;Coef_Final_Elevation\n" + "2013;test elevation;1;OTB 20/28.10;A;1;1;278970;1938;Agonus cataphractus;;Vrac;1;80.0;;Poids;;NA;;;;;;NA;;;;;;NA;;;;;;NA;;;;;;;;;;;;;;80.0;5.4444447;\n" + - "2013;test elevation;1;OTB 20/28.10;A;1;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Mâle;1;60.0;;Poids;;NA;;;;;;NA;;;;;;;;;;;;;;60.0;5.4444447;\n" + - "2013;test elevation;1;OTB 20/28.10;A;1;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Femelle;2;40.0;;Poids;;NA;;;;;;NA;;;;;;306;Longueur totale (LT) - individu - totale - Mesure au cm par un observateur;5.0;1;0.6;cm;1.0;4;0.6;217.77779;\n" + - "2013;test elevation;1;OTB 20/28.10;A;1;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Femelle;2;40.0;;Poids;;NA;;;;;;NA;;;;;;306;Longueur totale (LT) - individu - totale - Mesure au cm par un observateur;6.0;2;0.4;cm;1.0;10;0.4;217.77779;\n" + + "2013;test elevation;1;OTB 20/28.10;A;1;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Mâle;1;60.0;;Poids;;NA;;;;;;NA;;;;;;;;;;;;;;60.0;9.074075;\n" + + "2013;test elevation;1;OTB 20/28.10;A;1;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Femelle;2;40.0;;Poids;;NA;;;;;;NA;;;;;;306;Longueur totale (LT) - individu - totale - Mesure au cm par un observateur;5.0;1;0.6;cm;1.0;4;0.6;907.4074;\n" + + "2013;test elevation;1;OTB 20/28.10;A;1;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Femelle;2;40.0;;Poids;;NA;;;;;;NA;;;;;;306;Longueur totale (LT) - individu - totale - Mesure au cm par un observateur;6.0;2;0.4;cm;1.0;10;0.4;1361.1111;\n" + "2013;test elevation;1;OTB 20/28.10;A;1;1;278970;1938;Agonus cataphractus;;Hors Vrac;1;20.0;;Poids;;NA;;;;;;NA;;;;;;NA;;;;;;NA;;;;;;;;;;;;;;20.0;1.0;\n" + "2013;test elevation;1;OTB 20/28.10;B;2;1;278970;1938;Agonus cataphractus;;Vrac;1;80.0;;Poids;;NA;;;;;;NA;;;;;;NA;;;;;;NA;;;;;;;;;;;;;;80.0;3.5;\n" + - "2013;test elevation;1;OTB 20/28.10;B;2;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Mâle;1;60.0;;Poids;;NA;;;;;;NA;;;;;;;;;;;;;;60.0;3.5;\n" + - "2013;test elevation;1;OTB 20/28.10;B;2;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Femelle;2;40.0;;Poids;;NA;;;;;;NA;;;;;;;;;;;;;;40.0;3.5;\n" + + "2013;test elevation;1;OTB 20/28.10;B;2;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Mâle;1;60.0;;Poids;;NA;;;;;;NA;;;;;;;;;;;;;;60.0;5.8333335;\n" + + "2013;test elevation;1;OTB 20/28.10;B;2;1;278970;1358;Alosa alosa;;Vrac;2;;;Poids;;NA;;;;;;Femelle;2;40.0;;Poids;;NA;;;;;;NA;;;;;;;;;;;;;;40.0;8.75;\n" + "2013;test elevation;1;OTB 20/28.10;B;2;1;278970;1938;Agonus cataphractus;;Hors Vrac;1;20.0;;Poids;;NA;;;;;;NA;;;;;;NA;;;;;;NA;;;;;;;;;;;;;;20.0;1.0;\n" + "2013;test elevation;1;OTB 20/28.10;B;2;1;278970;4622;Abietinaria abietina;;Vrac;1;30.0;;Poids;;NA;;;;;;NA;;;;;;NA;;;;;;NA;;;;;;;;;;;;;;30.0;7.0;\n" + "2013;test elevation;1;OTB 20/28.10;B;2;1;278970;380;Acanthocardia echinata;;Vrac;2;18.0;;Poids;;NA;;;;;;NA;;;;;;NA;;;;;;NA;;;;;;;;;;;;;;18.0;7.0;";