This is an automated email from the git hooks/post-receive script. New commit to branch feature/8157 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 946cdbee506fd82f8f4f41702972592a3a4e33e1 Author: Kevin Morin <morin@codelutin.com> Date: Fri Apr 1 15:43:17 2016 +0200 récup du nombre de prélèvement par classe de taille pour une espece/maturité/sexe (refs #8157) --- .../service/sampling/CruiseSamplingCache.java | 5 +++ .../sampling/CruiseSamplingInternalCache.java | 41 +++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingCache.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingCache.java index 3fc5dea..5b9d06c 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingCache.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingCache.java @@ -50,6 +50,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.TreeMap; /** * @author Kevin Morin (Code Lutin) @@ -750,4 +751,8 @@ public class CruiseSamplingCache implements Closeable { (key, highestSamplingCode) -> code.equals(highestSamplingCode) ? code - 1 : highestSamplingCode); } + public TreeMap<Integer, Integer> getSamplingNbByLengthStepForCruise(int speciesId, CaracteristicQualitativeValue gender, Boolean maturity, int minSize, Integer maxSize) { + return totalCruiseCache.getSamplingNbByLengthStep(speciesId, gender, maturity, minSize, maxSize); + } + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingInternalCache.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingInternalCache.java index bb4ff26..2c11465 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingInternalCache.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingInternalCache.java @@ -54,10 +54,11 @@ class CruiseSamplingInternalCache implements Closeable { public static String createSamplingKey(Species species, CaracteristicQualitativeValue gender, Boolean maturity, int lengthStep) { Objects.requireNonNull(species); - return species.getReferenceTaxonId() - + KEY_SEPARATOR + (gender == null ? null : gender.getId()) - + KEY_SEPARATOR + maturity - + KEY_SEPARATOR + lengthStep; + return createSamplingKey(species.getReferenceTaxonId(), gender, maturity) + lengthStep; + } + + public static String createSamplingKey(int speciesId, CaracteristicQualitativeValue gender, Boolean maturity) { + return speciesId + KEY_SEPARATOR + (gender == null ? null : gender.getId()) + KEY_SEPARATOR + maturity + KEY_SEPARATOR; } public static String addPrefixKey(Serializable prefix, String key) { @@ -173,6 +174,37 @@ class CruiseSamplingInternalCache implements Closeable { return result; } + /** + * Get the number of samplings by lengthstep for a species, maturity and gender, for the lengthsteps between min size and max size + * @param speciesId + * @param gender + * @param maturity + * @param minSize + * @param maxSize + * @return a map of the number of samplings for each lengthstep in millimeters + */ + public TreeMap<Integer, Integer> getSamplingNbByLengthStep(int speciesId, CaracteristicQualitativeValue gender, Boolean maturity, int minSize, Integer maxSize) { + String keyPrefix = createSamplingKey(speciesId, gender, maturity); + + TreeMap<Integer, Integer> result = new TreeMap<>(); + + Iterator<Map.Entry<String, SamplingData>> iterator = data.entrySet().iterator(); + + int keyPrefixLength = keyPrefix.length(); + while (iterator.hasNext()) { + Map.Entry<String, SamplingData> entry = iterator.next(); + String key = entry.getKey(); + + if (key.startsWith(keyPrefix)) { + int lengthStep = Integer.parseInt(key.substring(keyPrefixLength)); + if (lengthStep >= minSize && (maxSize == null || lengthStep <= maxSize)) { + result.put(lengthStep, entry.getValue().getSamplingNb()); + } + } + } + return result; + } + private class SamplingData { private MutableInt observationNb = new MutableInt(0); @@ -208,4 +240,5 @@ class CruiseSamplingInternalCache implements Closeable { } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.