branch feature/8278 updated (efa8f8c -> d1f4877)
This is an automated email from the git hooks/post-receive script. New change to branch feature/8278 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git from efa8f8c Nettoyage de code et début de mise ne place de la génération des mensurations lors d'un import multi-poste espèces - observation seulement (See #8278) new d1f4877 génération des mensurations quand on est en mode de recopie taille ou tout (refs #8278) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit d1f4877a3a289772d9ccf352b6c405a083cf18e6 Author: Kevin Morin <morin@codelutin.com> Date: Tue Apr 26 14:05:41 2016 +0200 génération des mensurations quand on est en mode de recopie taille ou tout (refs #8278) Summary of changes: .../catches/multipost/MultiPostImportService.java | 104 ++++++++++++++++----- 1 file changed, 83 insertions(+), 21 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/8278 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit d1f4877a3a289772d9ccf352b6c405a083cf18e6 Author: Kevin Morin <morin@codelutin.com> Date: Tue Apr 26 14:05:41 2016 +0200 génération des mensurations quand on est en mode de recopie taille ou tout (refs #8278) --- .../catches/multipost/MultiPostImportService.java | 104 ++++++++++++++++----- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostImportService.java index 6f2f299..a195229 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostImportService.java @@ -80,8 +80,8 @@ import fr.ifremer.tutti.service.catches.multipost.csv.MarineLitterRowModel; import fr.ifremer.tutti.service.catches.multipost.csv.MarineLitterWeightRow; import fr.ifremer.tutti.service.catches.multipost.csv.MarineLitterWeightRowModel; import fr.ifremer.tutti.service.csv.CaracteristicValueParserFormatter; +import fr.ifremer.tutti.type.WeightUnit; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.mutable.MutableFloat; import org.apache.commons.lang3.tuple.Pair; import org.nuiton.csv.Import; import org.nuiton.jaxx.application.ApplicationBusinessException; @@ -292,7 +292,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult if (importIndividualObservations) { - importIndividualObservations(importContext, importFrequencies, batches, notImportedBatches, speciesSaveFrequencyMethod); + importIndividualObservations(importContext, importFrequencies, batches, notImportedBatches, speciesFrequencyHelper); } @@ -313,21 +313,33 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } - interface SaveFrequencyMethod { + interface FrequencyHelper { + SpeciesBatchFrequency newSpeciesBatchFrequency(); List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(Integer speciesBatchId, List<SpeciesBatchFrequency> frequencies); } - private final SaveFrequencyMethod speciesSaveFrequencyMethod = new SaveFrequencyMethod() { + private final FrequencyHelper speciesFrequencyHelper = new FrequencyHelper() { + + @Override + public SpeciesBatchFrequency newSpeciesBatchFrequency() { + return SpeciesBatchFrequencys.newSpeciesBatchFrequency(); + } + @Override public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(Integer speciesBatchId, List<SpeciesBatchFrequency> frequencies) { return persistenceService.saveSpeciesBatchFrequency(speciesBatchId, frequencies); } }; - private final SaveFrequencyMethod benthosSaveFrequencyMethod = new SaveFrequencyMethod() { + private final FrequencyHelper benthosFrequencyHelper = new FrequencyHelper() { + + @Override + public SpeciesBatchFrequency newSpeciesBatchFrequency() { + return SpeciesBatchFrequencys.newBenthosBatchFrequency(); + } @Override public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(Integer speciesBatchId, List<SpeciesBatchFrequency> frequencies) { return persistenceService.saveBenthosBatchFrequency(speciesBatchId, frequencies); @@ -537,7 +549,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult if (importIndividualObservations) { - importIndividualObservations(importContext, importFrequencies, batches, notImportedBatches, speciesSaveFrequencyMethod); + importIndividualObservations(importContext, importFrequencies, batches, notImportedBatches, benthosFrequencyHelper); } @@ -1297,7 +1309,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } - private void importIndividualObservations(MultiPostImportContext importContext, boolean importFrequencies, Map<String, SpeciesBatch> batches, Map<String, SpeciesBatch> notImportedBatches, SaveFrequencyMethod saveFrequencyMethod) throws IOException { + private void importIndividualObservations(MultiPostImportContext importContext, boolean importFrequencies, Map<String, SpeciesBatch> batches, Map<String, SpeciesBatch> notImportedBatches, FrequencyHelper frequencyHelper) throws IOException { // Import batches // map containing the batches by their persistence id @@ -1327,40 +1339,72 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult IndividualObservationBatch firstIndividualObservationBatch = allIndividualObservationBatchsForBatch.get(0); CopyIndividualObservationMode copyIndividualObservationMode = firstIndividualObservationBatch.getCopyIndividualObservationMode(); Caracteristic lengthStepCaracteristic = firstIndividualObservationBatch.getLengthStepCaracteristic(); - String unit = lengthStepCaracteristic.getUnit(); - boolean copySize = true; - boolean copyWeight = true; - - switch (copyIndividualObservationMode) { - case NOTHING: + boolean copySize = false; + final boolean copyWeight; - // nothing we said! - break; + switch (copyIndividualObservationMode) { case ALL: copySize = true; + copyWeight = true; break; case SIZE: copySize = true; - copyWeight = true; + copyWeight = false; break; + + case NOTHING:// nothing we said! + default: + copyWeight = false; + } if (copySize) { // this means first to delete any existing such frequencies - saveFrequencyMethod.saveSpeciesBatchFrequency(speciesBatchId, new ArrayList<>()); +// saveFrequencyMethod.saveSpeciesBatchFrequency(speciesBatchId, new ArrayList<>()); + + float step = getStep(lengthStepCaracteristic); + Map<Float, SpeciesBatchFrequency> frequencies = new TreeMap<>(); - Map<Float, MutableFloat> sizes = new TreeMap<>(); - Map<Float, MutableFloat> weights = new TreeMap<>(); - //FIXME Generate frequencies from individual observations allIndividualObservationBatchsForBatch .stream() .filter(individualObservationBatch -> individualObservationBatch.getSize() != null) .forEach(individualObservationBatch -> { - + + // compute the lengthstep according to the step of the lengthstep caracteristic + Float lengthStep = getLengthStep(individualObservationBatch.getSize(), step); + // get the existing frequency + SpeciesBatchFrequency frequency = frequencies.get(lengthStep); + + if (frequency == null) { + // or create a new one + frequency = frequencyHelper.newSpeciesBatchFrequency(); + frequency.setLengthStep(lengthStep); + frequency.setLengthStepCaracteristic(lengthStepCaracteristic); + frequency.setNumber(0); + frequency.setBatch(speciesBatch); + + // only set a weight if we copy the weights + frequency.setWeight(copyWeight ? 0f : null); + + frequencies.put(lengthStep, frequency); + } + + // increment the number of the frequency + frequency.setNumber(frequency.getNumber() + 1); + + if (copyWeight && individualObservationBatch.getWeight() != null) { + frequency.setWeight(frequency.getWeight() + individualObservationBatch.getWeight()); + } + }); + + if (copyWeight) { + frequencies.values().forEach(frequency -> frequency.setWeight(WeightUnit.KG.round(frequency.getWeight()))); + } + frequencyHelper.saveSpeciesBatchFrequency(speciesBatchId, new ArrayList<>(frequencies.values())); } } @@ -1369,6 +1413,24 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } + private float getStep(Caracteristic caracteristic) { + Float step = null; + if (caracteristic != null) { + step = caracteristic.getPrecision(); + } + if (step == null) { + step = 1f; + } + return step; + } + + private float getLengthStep(float lengthStep, float step) { + int intValue = (int) (lengthStep * 10); + int intStep = (int) (step * 10); + int correctIntStep = intValue - (intValue % intStep); + return correctIntStep / 10f; + } + private MultiPostImportResult importSpeciesOrBenthosBatch(File file, FishingOperation operation, SpeciesBatch speciesBatch, -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm