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 94561d50dc34c36a303601a7339c575bd69c7382 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 | 44 +++++++++++++++++++--- 2 files changed, 43 insertions(+), 6 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 93eb2ba..f8a83e7 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 @@ -49,6 +49,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) @@ -746,4 +747,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 96afef3..5a67639 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 @@ -52,13 +52,13 @@ class CruiseSamplingInternalCache implements Closeable { private static final String KEY_SEPARATOR = "#"; - public static String createSamplingKey(Species species, CaracteristicQualitativeValue gender, Boolean maturity, Float lengthStep) { + public static String createSamplingKey(Species species, CaracteristicQualitativeValue gender, Boolean maturity, float lengthStep) { Objects.requireNonNull(species); - Objects.requireNonNull(lengthStep); - 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) { @@ -174,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); @@ -209,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>.