This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository echobase. See https://gitlab.nuiton.org/codelutin/echobase.git commit 5b96a582c38d4be65d7b3cbbd2dac297ab5d7a65 Author: jcouteau <couteau@codelutin.com> Date: Thu Jan 30 13:56:46 2020 +0100 #refs 10217 : fix numbersAtLength --- .../service/atlantos/xml/XmlBioticExport.java | 199 +++++++++++---------- 1 file changed, 103 insertions(+), 96 deletions(-) diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java index 58a7e26e..d61b010e 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java @@ -68,7 +68,7 @@ public class XmlBioticExport implements EchoBaseService { for (Operation operation : operations) { Collection<Sample> samples = operation.getSample(); - Boolean exportHaul=false; + boolean exportHaul=false; //Export Haul only if it contains samples for (Sample sample : samples) { @@ -121,107 +121,114 @@ public class XmlBioticExport implements EchoBaseService { } String codeCatKey = code + "#" + categoryName; - if ("Total".equals(name)) { - //Add sample to totals list if no subsamples (yet) - if (subsamples.get(codeCatKey) == null) { - totals.put(codeCatKey, sample); + switch (name) { + case "Total": { + //Add sample to totals list if no subsamples (yet) + if (subsamples.get(codeCatKey) == null) { + totals.put(codeCatKey, sample); + } + + //Add sample weight to speciesCategoryWeight + Float weight = speciesCategoryWeights.get(codeCatKey); + if (weight == null) { + weight = 0f; + } + + Float sampleWeight = sample.getSampleWeight(); + if (sampleWeight != null) { + weight += sampleWeight; + } + speciesCategoryWeights.put(codeCatKey, weight); + + //Add sample number to speciesCategoryNumber + Integer number = speciesCategoryNumbers.get(codeCatKey); + if (number == null) { + number = 0; + } + + Integer numberSampled = sample.getNumberSampled(); + if (numberSampled != null) { + number += numberSampled; + } + speciesCategoryNumbers.put(codeCatKey, number); + + break; } - - //Add sample weight to speciesCategoryWeight - Float weight = speciesCategoryWeights.get(codeCatKey); - if (weight == null) { - weight = 0f; - } - - Float sampleWeight = sample.getSampleWeight(); - if (sampleWeight != null) { - weight += sampleWeight; - } - speciesCategoryWeights.put(codeCatKey, weight); - - //Add sample number to speciesCategoryNumber - Integer number = speciesCategoryNumbers.get(codeCatKey); - if (number == null) { - number = 0; - } - - Integer numberSampled = sample.getNumberSampled(); - if (numberSampled != null) { - number += numberSampled; - } - speciesCategoryNumbers.put(codeCatKey, number); - - } else if ("Subsample".equals(name)) { - - //Get back sample datas - Map<String, String> sampleDataValues = getSampleDataValues(sample); - - // get back weight at length for this subsample - String weightAtLength = sampleDataValues.get(SampleDataTypeImpl.WEIGHT_AT_LENGTHKG); - Float sampleWeight = null; - if (weightAtLength != null) { - sampleWeight = Float.parseFloat(weightAtLength); - } - - //add weightAtLength to the sum for this category - Float weightBySize = subsampledWeights.get(codeCatKey); - if (weightBySize == null) { - weightBySize = 0f; - } - if (sampleWeight != null) { - weightBySize += sampleWeight; - } - subsampledWeights.put(codeCatKey, weightBySize); - - //get back number at length for this subsample - String numberAtLength = sampleDataValues.get(SampleDataTypeImpl.NUMBER_AT_LENGTH); - Float sampleNumber = null; - if (numberAtLength != null) { - sampleNumber = Float.parseFloat(numberAtLength); - } - - //add numberAtLength to the sum for this category - Integer sumNumberAtLength = subsampledNumbers.get(codeCatKey); - if (sumNumberAtLength == null) { - sumNumberAtLength = 0; + case "Subsample": { + + //Get back sample datas + Map<String, String> sampleDataValues = getSampleDataValues(sample); + + // get back weight at length for this subsample + String weightAtLength = sampleDataValues.get(SampleDataTypeImpl.WEIGHT_AT_LENGTHKG); + Float sampleWeight = null; + if (weightAtLength != null) { + sampleWeight = Float.parseFloat(weightAtLength); + } + + //add weightAtLength to the sum for this category + Float weightBySize = subsampledWeights.get(codeCatKey); + if (weightBySize == null) { + weightBySize = 0f; + } + if (sampleWeight != null) { + weightBySize += sampleWeight; + } + subsampledWeights.put(codeCatKey, weightBySize); + + //get back number at length for this subsample + String numberAtLength = sampleDataValues.get(SampleDataTypeImpl.NUMBER_AT_LENGTH); + Float sampleNumber = null; + if (numberAtLength != null) { + sampleNumber = Float.parseFloat(numberAtLength); + } + + //add numberAtLength to the sum for this category + Integer sumNumberAtLength = subsampledNumbers.get(codeCatKey); + if (sumNumberAtLength == null) { + sumNumberAtLength = 0; + } + if (sampleNumber != null) { + sumNumberAtLength += sampleNumber.intValue(); + } + subsampledNumbers.put(codeCatKey, sumNumberAtLength); + + //Add subsample to the list + List<Sample> speciesCategorySubsamples = subsamples.get(codeCatKey); + if (speciesCategorySubsamples == null) { + speciesCategorySubsamples = new ArrayList<>(); + } + speciesCategorySubsamples.add(sample); + subsamples.put(codeCatKey, speciesCategorySubsamples); + + //check if total present, if so, removes it + if (subsamples.get(codeCatKey) != null) { + totals.remove(codeCatKey); + } + + break; } - if (sampleNumber != null) { - sumNumberAtLength += sampleNumber.intValue(); - } - subsampledNumbers.put(codeCatKey, sumNumberAtLength); - - //Add subsample to the list - List<Sample> speciesCategorySubsamples = subsamples.get(codeCatKey); - if (speciesCategorySubsamples == null) { - speciesCategorySubsamples = new ArrayList<>(); - } - speciesCategorySubsamples.add(sample); - subsamples.put(codeCatKey, speciesCategorySubsamples); + case "Individual": { - //check if total present, if so, removes it - if (subsamples.get(codeCatKey) != null) { - totals.remove(codeCatKey); - } - - } else if ("Individual".equals(name)) { + //Get back sample datas + Map<String, String> sampleDataValues = getSampleDataValues(sample); - //Get back sample datas - Map<String, String> sampleDataValues = getSampleDataValues(sample); + //Get back lengthclass for individual, remove trailing .0 + String lengthClass = sampleDataValues.get("LTmm1"); + lengthClass = lengthClass.substring(0, lengthClass.indexOf(".")); - //Get back lengthclass for individual, remove trailing .0 - String lengthClass = sampleDataValues.get("LTmm1"); - lengthClass = lengthClass.substring(0, lengthClass.indexOf(".")); + String codeCatLCkey = codeCatKey + "#" + lengthClass; - String codeCatLCkey = codeCatKey + "#" + lengthClass; + //add individual to the list + List<Sample> lengthClassIndividuals = individuals.get(codeCatLCkey); + if (lengthClassIndividuals == null) { + lengthClassIndividuals = new ArrayList<>(); + individuals.put(codeCatLCkey, lengthClassIndividuals); + } + lengthClassIndividuals.add(sample); - //add individual to the list - List<Sample> lengthClassIndividuals = individuals.get(codeCatLCkey); - if (lengthClassIndividuals == null) { - lengthClassIndividuals = new ArrayList<>(); - individuals.put(codeCatLCkey, lengthClassIndividuals); + break; } - lengthClassIndividuals.add(sample); - } } } @@ -571,8 +578,8 @@ public class XmlBioticExport implements EchoBaseService { String label = data.getDataLabel(); if (SampleDataTypeImpl.NUMBER_AT_LENGTH.equals(dataName)) { - sampleDataValues.put(SampleDataTypeImpl.NUMBER_AT_LENGTH, String.valueOf(value)); - sampleDataValues.put(dataName, label); + //We always have floats instead of Atlantos expected ints (so rounding will strip the .0) + sampleDataValues.put(SampleDataTypeImpl.NUMBER_AT_LENGTH, String.valueOf(Math.round(value))); sampleDataValues.put("LengthClass", label); } else { sampleDataValues.put(dataName, String.valueOf(value)); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.