This is an automated email from the git hooks/post-receive script. New change to branch feature/7488 in repository observe. See http://git.codelutin.com/observe.git at 6d1a554 Mise en place de consolidation des données sur les marées Seine Reste à finaliser le contenu des résultats See #7488 This branch includes the following new commits: new 35d2b0d Ajout de méthodes utiles sur certaines entités + amélioration du code de recherche des RTP (See #7488) new 6d1a554 Mise en place de consolidation des données sur les marées Seine Reste à finaliser le contenu des résultats See #7488 The 2 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 6d1a5545f75bcf92b70e74ef01325570bbbaecd7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 28 12:27:59 2015 +0200 Mise en place de consolidation des données sur les marées Seine Reste à finaliser le contenu des résultats See #7488 commit 35d2b0d35315751140f28d775131cd0b08de0165 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 28 12:27:27 2015 +0200 Ajout de méthodes utiles sur certaines entités + amélioration du code de recherche des RTP (See #7488) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7488 in repository observe. See http://git.codelutin.com/observe.git commit 35d2b0d35315751140f28d775131cd0b08de0165 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 28 12:27:27 2015 +0200 Ajout de méthodes utiles sur certaines entités + amélioration du code de recherche des RTP (See #7488) --- .../DuplicateLengthWeightParameterException.java | 52 +++++ ...eterHelper.java => LengthWeightParameters.java} | 229 +++++++++++++++------ .../referentiel/LengthWeightParemeterHelper.java | 23 +-- .../observe/entities/seine/NonTargetCatches.java | 16 ++ .../fr/ird/observe/entities/seine/SetSeines.java | 33 +++ 5 files changed, 272 insertions(+), 81 deletions(-) diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/DuplicateLengthWeightParameterException.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/DuplicateLengthWeightParameterException.java new file mode 100644 index 0000000..5e3d987 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/DuplicateLengthWeightParameterException.java @@ -0,0 +1,52 @@ +package fr.ird.observe.entities.referentiel; + +import java.util.Date; +import java.util.List; + +/** + * Created on 28/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class DuplicateLengthWeightParameterException extends RuntimeException { + + private static final long serialVersionUID = 203463423006930783L; + + protected final Species species; + + protected final Ocean ocean; + + protected final Sex sex; + + protected final Date date; + + protected final List<LengthWeightParameter> foundLengthWeightParameters; + + public DuplicateLengthWeightParameterException(Species species, Ocean ocean, Sex sex, Date date, List<LengthWeightParameter> foundLengthWeightParameters) { + this.species = species; + this.ocean = ocean; + this.sex = sex; + this.date = date; + this.foundLengthWeightParameters = foundLengthWeightParameters; + } + + public Species getSpecies() { + return species; + } + + public Ocean getOcean() { + return ocean; + } + + public Sex getSex() { + return sex; + } + + public Date getDate() { + return date; + } + + public List<LengthWeightParameter> getFoundLengthWeightParameters() { + return foundLengthWeightParameters; + } +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameters.java similarity index 58% copy from observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java copy to observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameters.java index e0e9c44..6466934 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameters.java @@ -1,32 +1,11 @@ -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ package fr.ird.observe.entities.referentiel; -import fr.ird.observe.ObserveTopiaPersistenceContext; +import fr.ird.observe.ObserveTopiaDaoSupplier; import fr.ird.observe.util.Numbers; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.TopiaDao; import javax.script.Bindings; import javax.script.ScriptContext; @@ -43,20 +22,16 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Classe utilitaire pour les traitements communs des implantations de - * {@link LengthWeightParameter}. + * Created on 28/08/15. * * @author Tony Chemit - chemit@codelutin.com - * @since 1.5 */ -public class LengthWeightParemeterHelper { +public class LengthWeightParameters { - private static final Pattern COEFFICIENTS_PATTERN = - Pattern.compile("(.+)=(.+)"); + /** Logger. */ + private static final Log log = LogFactory.getLog(LengthWeightParameters.class); - /** Logger */ - private static final Log log = - LogFactory.getLog(LengthWeightParemeterHelper.class); + private static final Pattern COEFFICIENTS_PATTERN = Pattern.compile("(.+)=(.+)"); /** moteur d'évaluation d'expression */ protected static ScriptEngine scriptEngine; @@ -80,6 +55,139 @@ public class LengthWeightParemeterHelper { return scriptEngine; } + /** + * Recherche d'un {@link LengthWeightParameter} à partir des paramètres donnés. + * + * La recherche peut ne peut être aussi exacte que les paramètres donnés : + * + * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son + * speciesGroup d'espèce. + * + * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on + * recherche avec un ocean vide. + * + * Si non trouvé sur le gender (et que le sexe n'est pas indéterminé) , alors + * on recherche avec le gender indéterminé (sexe=0). + * + * @param daoSupplier la transaction en cours d'utilisation + * @param species l'espèce sur lequel on recherche le paramétrage + * @param ocean l'ocean recherché (peut être null) + * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) + * @param date le jour recherché + * @return le paramétrage adéquate + * @since 1.5 + */ + public static LengthWeightParameter findLengthWeightParameter(ObserveTopiaDaoSupplier daoSupplier, + Species species, + Ocean ocean, + Sex sex, + Date date) { + + List<LengthWeightParameter> list = findBySpecies(daoSupplier, species); + + if (CollectionUtils.isEmpty(list)) { + + // aucun parametrage pour le type donne + return null; + } + + // filtrage par ocean + List<LengthWeightParameter> filterByOcean = filterByOcean(list, ocean); + + if (CollectionUtils.isEmpty(filterByOcean) && ocean != null) { + + // filtre par ocean null + filterByOcean = filterByOcean(list, null); + } + list = filterByOcean; + + if (CollectionUtils.isEmpty(list)) { + + // pas d'ocean adequate + return null; + } + + // filtrage par sexe + List<LengthWeightParameter> filterBySexe = filterBySexe(list, sex); + + if (CollectionUtils.isEmpty(filterBySexe)) { + + Sex unkwonSex = getUnknownSex(daoSupplier); + + if (sex == null || unkwonSex.equals(sex)) { + + // filtrage par sexe indetermine + filterBySexe = filterBySexe(list, unkwonSex); + } + + list = filterBySexe; + + } + + if (CollectionUtils.isEmpty(list)) { + + // pas de sexe adequate + return null; + } + + // filtrage par startDate de validite + list = filterByDateDebutValidite(list, date); + + if (CollectionUtils.isEmpty(list)) { + + // pas de date de debut adequate + return null; + } + + // filtrage par endDate de validite + list = filterByDateFinValidite(list, date); + + if (CollectionUtils.isEmpty(list)) { + + // pas de date de fin adequate + return null; + } + + // au final il ne devrait en rester qu'un + + if (list.size() > 1) { +// StringBuilder sb = new StringBuilder("Il existe plusieurs paramétrages possibles pour les données suivantes :"); +// sb.append("\nEspece : "); +// sb.append(getDecoratorService().decorate(species)); +// sb.append("\nOcean : "); +// sb.append(getDecoratorService().decorate(ocean)); +// sb.append("\nSex : "); +// sb.append(getDecoratorService().decorate(sex)); +// sb.append("\nDate : ").append(date); +// sb.append("\nParamétrages trouvés : "); +// for (P p : list) { +// sb.append("\n - ").append(getDecoratorService().decorate(p)); +// } + throw new DuplicateLengthWeightParameterException(species, ocean, sex, date, list); + } + + LengthWeightParameter result = list.get(0); +// if (log.isDebugEnabled()) { +// StringBuilder sb = new StringBuilder("Paramétrage trouvé pour les données suivantes :"); +// sb.append("\nEspece : "); +// sb.append(getDecoratorService().decorate(species)); +// sb.append("\nOcean : "); +// sb.append(getDecoratorService().decorate(ocean)); +// sb.append("\nSex : "); +// sb.append(getDecoratorService().decorate(sex)); +// sb.append("\nDate : ").append(date); +// sb.append("\nParamétrage: ").append(getDecoratorService().decorate(result)); +// log.debug(sb.toString()); +// } + return result; + + + } + + protected static Sex getUnknownSex(ObserveTopiaDaoSupplier daoSupplier) { + return daoSupplier.getSexDao().forCodeEquals("0").findUnique(); + } + public static Map<String, Double> getCoefficientValues(LengthWeightParameter parametrage) { Map<String, Double> result = new TreeMap<String, Double>(); @@ -164,20 +272,17 @@ public class LengthWeightParemeterHelper { } @SuppressWarnings({"unchecked"}) - public static <P extends LengthWeightParameter> List<P> findBySpecies(ObserveTopiaPersistenceContext tx, - Species taillePoidsAble) { + public static List<LengthWeightParameter> findBySpecies(ObserveTopiaDaoSupplier daoSupplier, + Species species) { - // le type de resultat recherche - Class<P> entityClass = (Class<P>) LengthWeightParameter.class; + LengthWeightParameterTopiaDao dao = daoSupplier.getLengthWeightParameterDao(); - TopiaDao<P> dao = tx.getDao(entityClass); - - List<P> list = dao.forProperties(LengthWeightParameter.PROPERTY_SPECIES, taillePoidsAble).findAll(); + List<LengthWeightParameter> list = dao.forSpeciesEquals(species).findAll(); // on supprime les paramétrages qui ont a=0 ou a=null ou b=0 ou b = null - Iterator<P> itr = list.iterator(); + Iterator<LengthWeightParameter> itr = list.iterator(); while (itr.hasNext()) { - P p = itr.next(); + LengthWeightParameter p = itr.next(); Double a = p.getCoefficientValue(COEFFICIENT_A); if (a == null || a == 0) { itr.remove(); @@ -195,19 +300,18 @@ public class LengthWeightParemeterHelper { } - public static <P extends LengthWeightParameter> List<P> filterByOcean(List<P> list, - Ocean ocean) { - List<P> result = new ArrayList<P>(); + public static List<LengthWeightParameter> filterByOcean(List<LengthWeightParameter> list, Ocean ocean) { + List<LengthWeightParameter> result = new ArrayList<>(); if (ocean == null) { // on n'accepte que les parametrage sans ocean - for (P parametrageLengthWeight : list) { + for (LengthWeightParameter parametrageLengthWeight : list) { if (parametrageLengthWeight.getOcean() == null) { result.add(parametrageLengthWeight); } } } else { - for (P parametrageLengthWeight : list) { + for (LengthWeightParameter parametrageLengthWeight : list) { if (ocean.equals(parametrageLengthWeight.getOcean())) { result.add(parametrageLengthWeight); } @@ -216,11 +320,10 @@ public class LengthWeightParemeterHelper { return result; } - public static <P extends LengthWeightParameter> List<P> filterBySexe(List<P> list, - Sex sex) { - List<P> result = new ArrayList<P>(); + public static List<LengthWeightParameter> filterBySexe(List<LengthWeightParameter> list, Sex sex) { + List<LengthWeightParameter> result = new ArrayList<>(); - for (P parametrageLengthWeight : list) { + for (LengthWeightParameter parametrageLengthWeight : list) { if (parametrageLengthWeight.getSex() == sex) { result.add(parametrageLengthWeight); } @@ -228,11 +331,10 @@ public class LengthWeightParemeterHelper { return result; } - public static <P extends LengthWeightParameter> List<P> filterByDateDebutValidite(List<P> list, - Date startDate) { - List<P> result = new ArrayList<P>(); + public static List<LengthWeightParameter> filterByDateDebutValidite(List<LengthWeightParameter> list, Date startDate) { + List<LengthWeightParameter> result = new ArrayList<>(); - for (P parametrageLengthWeight : list) { + for (LengthWeightParameter parametrageLengthWeight : list) { if (parametrageLengthWeight.getStartDate().before(startDate) || parametrageLengthWeight.getStartDate().equals(startDate)) { @@ -242,14 +344,13 @@ public class LengthWeightParemeterHelper { return result; } - public static <P extends LengthWeightParameter> List<P> filterByDateFinValidite(List<P> list, - Date endDate) { - List<P> result = new ArrayList<P>(); + public static List<LengthWeightParameter> filterByDateFinValidite(List<LengthWeightParameter> list, Date endDate) { + List<LengthWeightParameter> result = new ArrayList<>(); if (endDate == null) { // on n'accepte que les parametrages selon les critères suivants : // - sans date de fin (i.e en cours de validite) - for (P parametrageLengthWeight : list) { + for (LengthWeightParameter parametrageLengthWeight : list) { Date date = parametrageLengthWeight.getEndDate(); if (date == null) { @@ -260,7 +361,7 @@ public class LengthWeightParemeterHelper { // on n'accepte que les parametrages selon les critères suivants : // - sans date de fin (i.e en cours de validite) // - ceux dont la date de fin est avant la date de fin donnée - for (P parametrageLengthWeight : list) { + for (LengthWeightParameter parametrageLengthWeight : list) { Date date = parametrageLengthWeight.getEndDate(); if (date == null || @@ -273,9 +374,7 @@ public class LengthWeightParemeterHelper { return result; } - protected static boolean validateRelation(LengthWeightParameter parametrage, - String relation, - String variable) { + protected static boolean validateRelation(LengthWeightParameter parametrage, String relation, String variable) { boolean result = false; if (!StringUtils.isEmpty(relation)) { @@ -310,10 +409,7 @@ public class LengthWeightParemeterHelper { return result; } - public static Float computeValue(LengthWeightParameter parametrage, - String relation, - String variable, - float taille) { + public static Float computeValue(LengthWeightParameter parametrage, String relation, String variable, float taille) { Map<String, Double> coeffs = parametrage.getCoefficientValues(); ScriptEngine engine = getScriptEngine(); Bindings bindings = engine.createBindings(); @@ -338,4 +434,5 @@ public class LengthWeightParemeterHelper { } return o == null ? null : o.floatValue(); } + } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java index e0e9c44..2680601 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java @@ -48,7 +48,9 @@ import java.util.regex.Pattern; * * @author Tony Chemit - chemit@codelutin.com * @since 1.5 + * @deprecated Utiliser à la place LengthWeightParemeters */ +@Deprecated public class LengthWeightParemeterHelper { private static final Pattern COEFFICIENTS_PATTERN = @@ -195,8 +197,7 @@ public class LengthWeightParemeterHelper { } - public static <P extends LengthWeightParameter> List<P> filterByOcean(List<P> list, - Ocean ocean) { + public static <P extends LengthWeightParameter> List<P> filterByOcean(List<P> list, Ocean ocean) { List<P> result = new ArrayList<P>(); if (ocean == null) { @@ -216,8 +217,7 @@ public class LengthWeightParemeterHelper { return result; } - public static <P extends LengthWeightParameter> List<P> filterBySexe(List<P> list, - Sex sex) { + public static <P extends LengthWeightParameter> List<P> filterBySexe(List<P> list, Sex sex) { List<P> result = new ArrayList<P>(); for (P parametrageLengthWeight : list) { @@ -228,8 +228,7 @@ public class LengthWeightParemeterHelper { return result; } - public static <P extends LengthWeightParameter> List<P> filterByDateDebutValidite(List<P> list, - Date startDate) { + public static <P extends LengthWeightParameter> List<P> filterByDateDebutValidite(List<P> list, Date startDate) { List<P> result = new ArrayList<P>(); for (P parametrageLengthWeight : list) { @@ -242,8 +241,7 @@ public class LengthWeightParemeterHelper { return result; } - public static <P extends LengthWeightParameter> List<P> filterByDateFinValidite(List<P> list, - Date endDate) { + public static <P extends LengthWeightParameter> List<P> filterByDateFinValidite(List<P> list, Date endDate) { List<P> result = new ArrayList<P>(); if (endDate == null) { @@ -273,9 +271,7 @@ public class LengthWeightParemeterHelper { return result; } - protected static boolean validateRelation(LengthWeightParameter parametrage, - String relation, - String variable) { + protected static boolean validateRelation(LengthWeightParameter parametrage, String relation, String variable) { boolean result = false; if (!StringUtils.isEmpty(relation)) { @@ -310,10 +306,7 @@ public class LengthWeightParemeterHelper { return result; } - public static Float computeValue(LengthWeightParameter parametrage, - String relation, - String variable, - float taille) { + public static Float computeValue(LengthWeightParameter parametrage, String relation, String variable, float taille) { Map<String, Double> coeffs = parametrage.getCoefficientValues(); ScriptEngine engine = getScriptEngine(); Bindings bindings = engine.createBindings(); diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/NonTargetCatches.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/NonTargetCatches.java new file mode 100644 index 0000000..f03c3fd --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/NonTargetCatches.java @@ -0,0 +1,16 @@ +package fr.ird.observe.entities.seine; + +/** + * Created on 28/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class NonTargetCatches { + + public static boolean allNonTargetCatchDataFilled(NonTargetCatch nonTargetCatch) { + return !(nonTargetCatch.getCatchWeight() == null + || nonTargetCatch.getTotalCount() == null + || nonTargetCatch.getMeanWeight() == null + || nonTargetCatch.getMeanLength() == null); + } +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/SetSeines.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/SetSeines.java new file mode 100644 index 0000000..4ddfded --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/SetSeines.java @@ -0,0 +1,33 @@ +package fr.ird.observe.entities.seine; + +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; +import fr.ird.observe.entities.referentiel.Species; + +import java.util.Collection; + +/** + * Created on 28/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class SetSeines { + + public static Collection<NonTargetLength> getNonTargetLengths(SetSeine setSeine, final Species species) { + + Collection<NonTargetLength> nonTargetLengths = null; + + if (!setSeine.isNonTargetSampleEmpty()) { + nonTargetLengths = Collections2.filter(setSeine.getNonTargetSample().iterator().next().getNonTargetLength(), new Predicate<NonTargetLength>() { + + @Override + public boolean apply(NonTargetLength input) { + return species.equals(input.getSpecies()); + } + }); + } + + return nonTargetLengths; + + } +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7488 in repository observe. See http://git.codelutin.com/observe.git commit 6d1a5545f75bcf92b70e74ef01325570bbbaecd7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 28 12:27:59 2015 +0200 Mise en place de consolidation des données sur les marées Seine Reste à finaliser le contenu des résultats See #7488 --- .../ConsolidateActivitySeineDataResult.java | 59 ++ .../ConsolidateTripSeineDataRequest.java | 25 + .../ConsolidateTripSeineDataResult.java | 45 ++ .../consolidate/ConsolidationDataService.java | 21 + .../service/ConsolidationDataServiceTopia.java | 788 +++++++++++++++++++++ 5 files changed, 938 insertions(+) diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateActivitySeineDataResult.java b/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateActivitySeineDataResult.java new file mode 100644 index 0000000..0298edd --- /dev/null +++ b/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateActivitySeineDataResult.java @@ -0,0 +1,59 @@ +package fr.ird.observe.services.service.actions.consolidate; + +import java.util.Date; + +/** + * Pour retourner le résultat de la consolidation d'une activité de type seine. + * + * Created on 28/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class ConsolidateActivitySeineDataResult { + + protected String schoolTypeChanged; + + public void registerLengthWeightParameterNotFound(String speciesId, String oceanId, String sexId, Date routeDate) { + + } + + public void registerTargetLengthLengthWasComputed(String targetLengthId, Float length) { + + } + + public void registerTargetLengthWeightWasComputed(String targetLengthId, Float weight) { + + } + + public void registerNonTargetLengthLengthWasComputed(String nonTargetLengthId, Float length) { + + } + + public void registerNonTargetLengthWeightWasComputed(String nonTargetLengthId, Float weight) { + + } + + public void registerNonTargetCatchMeanLengthWasComputed(String nonTargetCatchId, Float meanLength, String computeValueSource) { + + } + + public void registerNonTargetCatchMeanWeightWasComputed(String nonTargetCatchId, Float meanWeight, String computeValueSource) { + + } + + public void registerNonTargetCatchCatchWeightWasComputed(String nonTargetCatchId, Float catchWeight, String computeValueSource) { + + } + + public void registerNonTargetCatchTotalCountWasComputed(String nonTargetCatchId, Integer totalCount, String computeValueSource) { + + } + + public void setSchoolTypeChanged(String schoolTypeChanged) { + this.schoolTypeChanged = schoolTypeChanged; + } + + public String getSchoolTypeChanged() { + return schoolTypeChanged; + } +} diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateTripSeineDataRequest.java b/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateTripSeineDataRequest.java new file mode 100644 index 0000000..5205e33 --- /dev/null +++ b/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateTripSeineDataRequest.java @@ -0,0 +1,25 @@ +package fr.ird.observe.services.service.actions.consolidate; + +import com.google.common.collect.ImmutableSet; + +/** + * Pour configurer l'opération de consolidation. + * + * Created on 28/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @see ConsolidationDataService#consolidateTripSeine(String) + */ +public class ConsolidateTripSeineDataRequest { + + protected ImmutableSet<String> tripSeineIds; + + public ImmutableSet<String> getTripSeineIds() { + return tripSeineIds; + } + + public void setTripSeineIds(ImmutableSet<String> tripSeineIds) { + this.tripSeineIds = tripSeineIds; + } + +} diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateTripSeineDataResult.java b/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateTripSeineDataResult.java new file mode 100644 index 0000000..ff9c6a1 --- /dev/null +++ b/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateTripSeineDataResult.java @@ -0,0 +1,45 @@ +package fr.ird.observe.services.service.actions.consolidate; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Pour retourner le résultat de la consolidation d'une marée de type seine. + * + * Created on 28/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @see ConsolidationDataService#consolidateTripSeine(String) + */ +public class ConsolidateTripSeineDataResult { + + protected boolean noActivityFound; + + protected boolean tripWasModified; + + protected final Set<ConsolidateActivitySeineDataResult> activitySeineDataResults = new LinkedHashSet<>(); + + public boolean isNoActivityFound() { + return noActivityFound; + } + + public void setNoActivityFound(boolean noActivityFound) { + this.noActivityFound = noActivityFound; + } + + public boolean isTripWasModified() { + return tripWasModified; + } + + public void setTripWasModified(boolean tripWasModified) { + this.tripWasModified = tripWasModified; + } + + public void addActivityResult(ConsolidateActivitySeineDataResult activitySeineDataResult) { + activitySeineDataResults.add(activitySeineDataResult); + } + + public Set<ConsolidateActivitySeineDataResult> getActivitySeineDataResults() { + return activitySeineDataResults; + } +} diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidationDataService.java b/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidationDataService.java new file mode 100644 index 0000000..b76ead7 --- /dev/null +++ b/observe-services-api/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidationDataService.java @@ -0,0 +1,21 @@ +package fr.ird.observe.services.service.actions.consolidate; + +import com.google.common.collect.ImmutableSet; + +/** + * Le service pour effectuer les consolidations de données, i.e + * de pouvoir effectuer remplir certains champs à partir de champs observés. + * + * Created on 28/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public interface ConsolidationDataService { + + /** + * @param consolidateTripSeineDataRequest la demande de consolidation + * @return le résultat de la consolidation de données pour chaque marée. + */ + ImmutableSet<ConsolidateTripSeineDataResult> consolidateTripSeines(ConsolidateTripSeineDataRequest consolidateTripSeineDataRequest); + +} diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/service/ConsolidationDataServiceTopia.java b/observe-services-topia/src/main/java/fr/ird/observe/services/service/ConsolidationDataServiceTopia.java new file mode 100644 index 0000000..13ef1a9 --- /dev/null +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/service/ConsolidationDataServiceTopia.java @@ -0,0 +1,788 @@ +package fr.ird.observe.services.service; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import fr.ird.observe.entities.LengthWeightComputable; +import fr.ird.observe.entities.constants.seine.NonTargetCatchComputedValueSource; +import fr.ird.observe.entities.constants.seine.SchoolType; +import fr.ird.observe.entities.referentiel.LengthWeightParameter; +import fr.ird.observe.entities.referentiel.LengthWeightParameterTopiaDao; +import fr.ird.observe.entities.referentiel.LengthWeightParameters; +import fr.ird.observe.entities.referentiel.Ocean; +import fr.ird.observe.entities.referentiel.Sex; +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.NonTargetCatch; +import fr.ird.observe.entities.seine.NonTargetCatches; +import fr.ird.observe.entities.seine.NonTargetLength; +import fr.ird.observe.entities.seine.NonTargetSample; +import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.SetSeines; +import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceTopia; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.services.service.actions.consolidate.ConsolidateActivitySeineDataResult; +import fr.ird.observe.services.service.actions.consolidate.ConsolidateTripSeineDataRequest; +import fr.ird.observe.services.service.actions.consolidate.ConsolidateTripSeineDataResult; +import fr.ird.observe.services.service.actions.consolidate.ConsolidationDataService; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.beans.BeanMonitor; + +import java.util.Collection; +import java.util.Date; +import java.util.Set; + +/** + * Created on 28/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class ConsolidationDataServiceTopia extends ObserveServiceTopia implements ConsolidationDataService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ConsolidationDataServiceTopia.class); + +// private static final String MESSAGE_FORMAT_3 = "[%1$s] %2$s calculé : %3$s (%4$s:%5$s, %6$s:%7$s)"; + + class ConsolidationActivitySeineDataContext { + + protected TripSeine tripSeine; + + protected Route route; + + protected ActivitySeine activity; + + protected LengthWeightParameterTopiaDao lengthWeightParameterTopiaDao; + + protected ConsolidateActivitySeineDataResult consolidateActivitySeineDataResult; + + BeanMonitor targetLengthMonitor; + + BeanMonitor nonTargetLengthMonitor; + + BeanMonitor nonTargetCatchMonitor; + + public Ocean getOcean() { + return tripSeine.getOcean(); + } + + public Date getRouteDate() { + return route.getDate(); + } + + public SetSeine getSetSeine() { + return activity.getSetSeine(); + } + + public LengthWeightParameter findLengthWeightParameter(Species species, Sex sex) { + Ocean ocean = getOcean(); + Date routeDate = getRouteDate(); + LengthWeightParameter lengthWeightParameter = LengthWeightParameters.findLengthWeightParameter(getTopiaPersistenceContext(), species, ocean, sex, routeDate); + if (lengthWeightParameter == null) { + + //FIXME On devrait retourner une erreur plutôt + consolidateActivitySeineDataResult.registerLengthWeightParameterNotFound(species.getTopiaId(), ocean.getTopiaId(), sex == null ? null : sex.getTopiaId(), routeDate); + + } + return lengthWeightParameter; + } + + public void setSchoolTypeChanged(SchoolType schoolTypeChanged) { + consolidateActivitySeineDataResult.setSchoolTypeChanged(schoolTypeChanged.name()); + } + + public void watchTargetLength(TargetLength targetLength) { + targetLengthMonitor.setBean(targetLength); + } + + public void watchNonTargetLenght(NonTargetLength nonTargetLength) { + nonTargetLengthMonitor.setBean(nonTargetLength); + } + + public void flushTargetLength() { + if (targetLengthMonitor.wasModified()) { + TargetLength targetLength = (TargetLength) targetLengthMonitor.getBean(); + Set<String> modifiedProperties = Sets.newHashSet(targetLengthMonitor.getModifiedProperties()); + if (modifiedProperties.contains(TargetLength.PROPERTY_LENGTH)) { + consolidateActivitySeineDataResult.registerTargetLengthLengthWasComputed(targetLength.getTopiaId(), targetLength.getLength()); + } + if (modifiedProperties.contains(TargetLength.PROPERTY_WEIGHT)) { + consolidateActivitySeineDataResult.registerTargetLengthWeightWasComputed(targetLength.getTopiaId(), targetLength.getWeight()); + } + } + targetLengthMonitor.setBean(null); + } + + public void flushNonTargetLength() { + if (nonTargetLengthMonitor.wasModified()) { + NonTargetLength nonTargetLength = (NonTargetLength) nonTargetLengthMonitor.getBean(); + Set<String> modifiedProperties = Sets.newHashSet(nonTargetLengthMonitor.getModifiedProperties()); + if (modifiedProperties.contains(NonTargetLength.PROPERTY_LENGTH)) { + consolidateActivitySeineDataResult.registerNonTargetLengthLengthWasComputed(nonTargetLength.getTopiaId(), nonTargetLength.getLength()); + } + if (modifiedProperties.contains(NonTargetLength.PROPERTY_WEIGHT)) { + consolidateActivitySeineDataResult.registerNonTargetLengthWeightWasComputed(nonTargetLength.getTopiaId(), nonTargetLength.getWeight()); + } + } + nonTargetLengthMonitor.setBean(null); + } + + public void watchNonTargetCatch(NonTargetCatch nonTargetCatch) { + nonTargetCatchMonitor.setBean(nonTargetCatch); + } + + public void flushNonTargetCatch() { + if (nonTargetCatchMonitor.wasModified()) { + NonTargetCatch nonTargetCatch = (NonTargetCatch) nonTargetCatchMonitor.getBean(); + Set<String> modifiedProperties = Sets.newHashSet(nonTargetCatchMonitor.getModifiedProperties()); + if (modifiedProperties.contains(NonTargetCatch.PROPERTY_MEAN_LENGTH)) { + consolidateActivitySeineDataResult.registerNonTargetCatchMeanLengthWasComputed(nonTargetCatch.getTopiaId(), nonTargetCatch.getMeanLength(), nonTargetCatch.getMeanLengthComputedSource().name()); + } + if (modifiedProperties.contains(NonTargetCatch.PROPERTY_MEAN_WEIGHT)) { + consolidateActivitySeineDataResult.registerNonTargetCatchMeanWeightWasComputed(nonTargetCatch.getTopiaId(), nonTargetCatch.getMeanWeight(), nonTargetCatch.getMeanWeightComputedSource().name()); + } + if (modifiedProperties.contains(NonTargetCatch.PROPERTY_CATCH_WEIGHT)) { + consolidateActivitySeineDataResult.registerNonTargetCatchCatchWeightWasComputed(nonTargetCatch.getTopiaId(), nonTargetCatch.getCatchWeight(), nonTargetCatch.getCatchWeightComputedSource().name()); + } + if (modifiedProperties.contains(NonTargetCatch.PROPERTY_TOTAL_COUNT)) { + consolidateActivitySeineDataResult.registerNonTargetCatchTotalCountWasComputed(nonTargetCatch.getTopiaId(), nonTargetCatch.getTotalCount(), nonTargetCatch.getTotalCountComputedSource().name()); + } + } + nonTargetCatchMonitor.setBean(null); + } + } + + @Override + public ImmutableSet<ConsolidateTripSeineDataResult> consolidateTripSeines(ConsolidateTripSeineDataRequest consolidateTripSeineDataRequest) { + + ImmutableSet.Builder<ConsolidateTripSeineDataResult> resultBuilder = new ImmutableSet.Builder<>(); + for (String tripSeineId : consolidateTripSeineDataRequest.getTripSeineIds()) { + ConsolidateTripSeineDataResult consolidateTripSeineDataResult = consolidateTripSeine(tripSeineId); + resultBuilder.add(consolidateTripSeineDataResult); + } + return resultBuilder.build(); + + } + + protected ConsolidateTripSeineDataResult consolidateTripSeine(String tripSeineId) { + + TripSeine tripSeine = loadEntity(TripSeineDto.class, TripSeine.class, tripSeineId); + + ConsolidateTripSeineDataResult computationResult = new ConsolidateTripSeineDataResult(); + + BeanMonitor targetLengthMonitor = new BeanMonitor( + TargetLength.PROPERTY_LENGTH, + TargetLength.PROPERTY_LENGTH_SOURCE, + TargetLength.PROPERTY_WEIGHT, + TargetLength.PROPERTY_WEIGHT_SOURCE); + + BeanMonitor nonTargetSampleMonitor = new BeanMonitor( + NonTargetLength.PROPERTY_LENGTH, + NonTargetLength.PROPERTY_LENGTH_SOURCE, + NonTargetLength.PROPERTY_WEIGHT, + NonTargetLength.PROPERTY_WEIGHT_SOURCE); + + BeanMonitor nonTargetCatchMonitor = new BeanMonitor( + NonTargetCatch.PROPERTY_MEAN_LENGTH, + NonTargetCatch.PROPERTY_MEAN_LENGTH_COMPUTED_SOURCE, + NonTargetCatch.PROPERTY_MEAN_WEIGHT, + NonTargetCatch.PROPERTY_MEAN_WEIGHT_COMPUTED_SOURCE, + NonTargetCatch.PROPERTY_CATCH_WEIGHT, + NonTargetCatch.PROPERTY_CATCH_WEIGHT_COMPUTED_SOURCE, + NonTargetCatch.PROPERTY_TOTAL_COUNT, + NonTargetCatch.PROPERTY_TOTAL_COUNT_COMPUTED_SOURCE + ); + + LengthWeightParameterTopiaDao lengthWeightParameterDao = getTopiaPersistenceContext().getLengthWeightParameterDao(); + + for (Route route : tripSeine.getRoute()) { + + for (ActivitySeine activitySeine : route.getActivitySeine()) { + + ConsolidateActivitySeineDataResult consolidateActivitySeineDataResult = new ConsolidateActivitySeineDataResult(); + ConsolidationActivitySeineDataContext activityContext = new ConsolidationActivitySeineDataContext(); + activityContext.tripSeine = tripSeine; + activityContext.route = route; + activityContext.activity = activitySeine; + activityContext.lengthWeightParameterTopiaDao = lengthWeightParameterDao; + activityContext.consolidateActivitySeineDataResult = consolidateActivitySeineDataResult; + activityContext.targetLengthMonitor = targetLengthMonitor; + activityContext.nonTargetLengthMonitor = nonTargetSampleMonitor; + activityContext.nonTargetCatchMonitor = nonTargetCatchMonitor; + computationResult.addActivityResult(consolidateActivitySeineDataResult); + + consolidateActivitySeine(activityContext); + + } + + } + + // on devra mettre a jour en base la maree +// messager1.sendMessage(t("observe.message.consolidate.maree.need.update", +// mareeStr)); + + return computationResult; + } + + + protected void consolidateActivitySeine(ConsolidationActivitySeineDataContext activityContext) { + + ActivitySeine activity = activityContext.activity; + + if (log.isInfoEnabled()) { + log.info("Start consolidate activity: " + activity.getTopiaId()); + } + + SetSeine setSeine = activity.getSetSeine(); + SchoolType oldTypeBanc = setSeine.getSchoolType(); + SchoolType newTypeBanc = activity.getSchoolType(); + if (oldTypeBanc == null || oldTypeBanc != newTypeBanc) { + + // le type de banc a changé, on doit sauver l'activité + setSeine.setSchoolType(newTypeBanc); + activityContext.setSchoolTypeChanged(newTypeBanc); + + } + + if (!setSeine.isTargetSampleEmpty()) { + + // des echantillons thons trouves + for (TargetSample targetSample : setSeine.getTargetSample()) { + if (!targetSample.isTargetLengthEmpty()) { + for (TargetLength targetLength : targetSample.getTargetLength()) { + + activityContext.watchTargetLength(targetLength); + + updateLengthWeightAble(activityContext, + targetLength.getSpecies(), + null, /* pas de sexe precise */ + targetLength); + + activityContext.flushTargetLength(); + + } + } + } + } + + if (!setSeine.isNonTargetSampleEmpty()) { + + // des echantillons faunes trouves + for (NonTargetSample nonTargetSample : setSeine.getNonTargetSample()) { + + if (!nonTargetSample.isNonTargetLengthEmpty()) { + for (NonTargetLength nonTargetLength : nonTargetSample.getNonTargetLength()) { + + activityContext.watchNonTargetLenght(nonTargetLength); + + updateLengthWeightAble(activityContext, + nonTargetLength.getSpecies(), + nonTargetLength.getSex(), + nonTargetLength); + + activityContext.flushNonTargetLength(); + + } + } + } + } + + if (!setSeine.isNonTargetCatchEmpty()) { + + // des captures (ou rejets) faunes trouves + for (NonTargetCatch nonTargetCatch : setSeine.getNonTargetCatch()) { + + activityContext.watchNonTargetCatch(nonTargetCatch); + + // suppression de tous les champs précédemment calculés + + if (nonTargetCatch.isCatchWeightComputed()) { + nonTargetCatch.setCatchWeight(null); + nonTargetCatch.setCatchWeightComputedSource(null); + } + + if (nonTargetCatch.isTotalCountComputed()) { + nonTargetCatch.setTotalCount(null); + nonTargetCatch.setTotalCountComputedSource(null); + } + + if (nonTargetCatch.isMeanWeightComputed()) { + nonTargetCatch.setMeanWeight(null); + nonTargetCatch.setMeanWeightComputedSource(null); + } + + if (nonTargetCatch.isMeanLengthComputed()) { + nonTargetCatch.setMeanLength(null); + nonTargetCatch.setMeanLengthComputedSource(null); + } + + updateNonTargetCatch(activityContext, nonTargetCatch); + + activityContext.flushNonTargetCatch(); + + } + } + + } + + protected void updateNonTargetCatch(ConsolidationActivitySeineDataContext activityContext, NonTargetCatch nonTargetCatch) { + + Species species = nonTargetCatch.getSpecies(); + + // récupération du référentiel + LengthWeightParameter lengthWeightParameter = activityContext.findLengthWeightParameter(species, null /* pas de sexe spécifié*/); + + // -- Cas n°1 (calcul uniquement à partir des relations taille - poids) + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, lengthWeightParameter); + + if (NonTargetCatches.allNonTargetCatchDataFilled(nonTargetCatch)) { + + // tout est rempli, plus rien à faire + return; + } + + // répération des échantillon de cette espèce sur les calée + + Collection<NonTargetLength> nonTargetLengths = SetSeines.getNonTargetLengths(activityContext.getSetSeine(), species); + +// SetSeine setSeine = activityContext.getSetSeine(); +// +// if (!setSeine.isNonTargetSampleEmpty()) { +// nonTargetLengths = Collections2.filter(setSeine.getNonTargetSample().iterator().next().getNonTargetLength(), new Predicate<NonTargetLength>() { +// +// @Override +// public boolean apply(NonTargetLength input) { +// return species.equals(input.getSpecies()); +// } +// }); +// } + + if (nonTargetCatch.getCatchWeight() != null || nonTargetCatch.getTotalCount() != null) { + + // -- Cas n°2 (pas de taille / poids moyen mais au moins un des deux taille / poids) + computeNonTargetCatchMeanLength(nonTargetCatch, nonTargetLengths, lengthWeightParameter); + } + + if (NonTargetCatches.allNonTargetCatchDataFilled(nonTargetCatch)) { + + // tout est rempli, plus rien à faire + return; + } + + // -- Cas n°3 (pas de nombre estimé) + + if (nonTargetCatch.getTotalCount() == null) { + + computeNonTargetCatchNombreEstime(nonTargetCatch, nonTargetLengths, lengthWeightParameter); + + } + + if (NonTargetCatches.allNonTargetCatchDataFilled(nonTargetCatch)) { + + // tout est rempli, plus rien à faire + return; + } + + // -- Cas n°4 (pas de poids moyen, taille moyenne) + + computeNonTargetCatchMeanValues(nonTargetCatch, lengthWeightParameter); + } + + protected void updateNonTargetCatchByLengthWeightRelation(NonTargetCatch nonTargetCatch, + LengthWeightParameter lengthWeightParameter) { + + // calcul via le paramétrage taille - poids + updateLengthWeightAble(nonTargetCatch, lengthWeightParameter); + + // calcule l'un des trois champs poids estimé - nbEstime - poids moyen + updateNonTargetCatchPoidsEstimeNbEstimePoidsMoyen(nonTargetCatch); + + // on ressaye d'appliquer la relation taille - poids au cas où une des + // trois valeurs précédentes a été calculée, on pourrait peut-être + // ainsi en déduire via le paramétrage la taille moyenne + updateLengthWeightAble(nonTargetCatch, lengthWeightParameter); + + } + + protected void computeNonTargetCatchMeanLength(NonTargetCatch nonTargetCatch, + Collection<NonTargetLength> samples, + LengthWeightParameter lengthWeightParameter) { + + Float meanLength = nonTargetCatch.getMeanLength(); + + if (meanLength == null) { + + // on essaye de calculer la taille moyenne à partir des échantillons + + NonTargetCatchComputedValueSource computedSource = null; + + if (CollectionUtils.isNotEmpty(samples)) { + + // on calcul la taille moyenne à partir des échantillons + float totalLength = 0f; + int totalCount = 0; + for (NonTargetLength sample : samples) { + + Integer count = sample.getCount(); + Float length = sample.getLength(); + + if (count != null && length != null) { + totalCount += count; + totalLength += length * count; + } + } + + if (totalCount != 0) { + + meanLength = totalLength / totalCount; + + computedSource = NonTargetCatchComputedValueSource.FROM_SAMPLE; + } + } + + if (meanLength == null && lengthWeightParameter != null) { + + // on prend directement la valeur fournie par le référentiel + + meanLength = lengthWeightParameter.getMeanLength(); + computedSource = NonTargetCatchComputedValueSource.FROM_REFERENTIEL; + } + + if (meanLength != null) { + + // la taille moyenne a pu etre calculee, on la pousse alors + nonTargetCatch.setMeanLength(meanLength); + nonTargetCatch.setMeanLengthComputedSource(computedSource); + + } + + } + + if (meanLength != null) { + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, lengthWeightParameter); + + } + + } + + protected void computeNonTargetCatchNombreEstime(NonTargetCatch nonTargetCatch, + Collection<NonTargetLength> samples, + LengthWeightParameter lengthWeightParameter) { + + + Integer totalCount = nonTargetCatch.getTotalCount(); + + if (totalCount == null) { + + if (CollectionUtils.isNotEmpty(samples)) { + + // on calcul la nombre d'individus à partir des échantillons + totalCount = 0; + for (NonTargetLength sample : samples) { + + Integer count = sample.getCount(); + + if (count != null) { + totalCount += count; + } + } + + if (totalCount != 0) { + + nonTargetCatch.setTotalCount(totalCount); + nonTargetCatch.setTotalCountComputedSource(NonTargetCatchComputedValueSource.FROM_SAMPLE); + + + } + } + + } + + if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, lengthWeightParameter); + } + + } + + protected void computeNonTargetCatchMeanValues(NonTargetCatch nonTargetCatch, LengthWeightParameter lengthWeightParameter) { + + if (lengthWeightParameter != null) { + + if (nonTargetCatch.getMeanLength() == null) { + nonTargetCatch.setMeanLength(lengthWeightParameter.getMeanLength()); + nonTargetCatch.setMeanLengthComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); + } + + if (nonTargetCatch.getMeanWeight() == null) { + nonTargetCatch.setMeanWeight(lengthWeightParameter.getMeanWeight()); + nonTargetCatch.setMeanWeightComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); + } + + if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, lengthWeightParameter); + } + + } + } + + protected void updateNonTargetCatchPoidsEstimeNbEstimePoidsMoyen(NonTargetCatch nonTargetCatch) { + + Float meanWeight = nonTargetCatch.getMeanWeight(); + Float catchWeight = nonTargetCatch.getCatchWeight(); + Integer totalCount = nonTargetCatch.getTotalCount(); + +// String entityLabel = getNonTargetCatcheLabel(); + + if (catchWeight == null && totalCount != null && meanWeight != null) { + + // calcul le weight poids à partir de nb estime et du poids moyen + catchWeight = meanWeight * (float) totalCount / 1000; + nonTargetCatch.setCatchWeight(catchWeight); + nonTargetCatch.setCatchWeightComputedSource(NonTargetCatchComputedValueSource.FROM_DATA); +// String message = String.format(MESSAGE_FORMAT_3, +// entityLabel, +// t("observe.common.catchWeight"), +// catchWeight, +// t("observe.common.meanWeight"), +// meanWeight, +// t("observe.common.totalCount"), +// totalCount); +// if (log.isInfoEnabled()) { +// log.info(message); +// } + } + + if (totalCount == null && catchWeight != null && meanWeight != null) { + + // calcul le nb estime à partir du poids estime et du poids moyen + totalCount = (int) ((float) 1000 * catchWeight / meanWeight); + nonTargetCatch.setTotalCount(totalCount); + nonTargetCatch.setTotalCountComputedSource(NonTargetCatchComputedValueSource.FROM_DATA); +// String message = String.format(MESSAGE_FORMAT_3, +// entityLabel, +// t("observe.common.totalCount"), +// totalCount, +// t("observe.common.meanWeight"), +// meanWeight, +// t("observe.common.catchWeight"), +// catchWeight); +// if (log.isInfoEnabled()) { +// log.info(message); +// } + } + + if (meanWeight == null && totalCount != null && totalCount != 0 && catchWeight != null && + !NonTargetCatchComputedValueSource.FROM_SAMPLE.equals(nonTargetCatch.getTotalCountComputedSource())) { + + // calcul le poids moyen à partir de nb estime et du poids estime + // uniquement si le nombre estimé ne vient pas des échantillons (voir http://forge.codelutin.com/issues/4670) + + meanWeight = catchWeight * (float) 1000 / (float) totalCount; + nonTargetCatch.setMeanWeight(meanWeight); + nonTargetCatch.setMeanWeightComputedSource(NonTargetCatchComputedValueSource.FROM_DATA); +// String message = String.format(MESSAGE_FORMAT_3, +// entityLabel, +// t("observe.common.meanWeight"), +// meanWeight, +// t("observe.common.totalCount"), +// totalCount, +// t("observe.common.catchWeight"), +// catchWeight); +// if (log.isInfoEnabled()) { +// log.info(message); +// } + } + } + + protected void updateLengthWeightAble(ConsolidationActivitySeineDataContext activityContext, + Species species, + Sex sex, + LengthWeightComputable lengthWeightComputable) { + +// String entityLabel = getSpeciesLabel(); + + Float weight = lengthWeightComputable.getWeight(); + Float length = lengthWeightComputable.getLength(); + + boolean computeWeight = false; + boolean computeLength = false; + + if (weight == null && length != null) { + + // on essaye de calculer le poids + computeWeight = true; + } + + if (length == null && weight != null) { + + // on essaye de calcule la taille + computeLength = true; + } + + if (!computeLength && !computeWeight) { + + // rien a calculer + return; + } + + // recherche du parametrage adequate + LengthWeightParameter lengthWeightParameter = activityContext.findLengthWeightParameter(species, sex); + + if (lengthWeightParameter == null) { + + // aucun parametrage connu + +// String message = t("observe.message.consolidate.no.parametrage.found", +// t(entityLabel), +// decorate(species) +// ); +// if (log.isWarnEnabled()) { +// log.warn(message); +// } + return; + } + + if (computeLength) { + Float newLength = lengthWeightParameter.computeLength(weight); + if (newLength != null) { + +// // la taille a ete calculee +// String message = +// "[" + t(entityLabel) + "] " + +// t("observe.message.consolidate.computed.taille", +// newLength, +// weight, +// lengthWeightParameter.getWeightLengthFormula(), +// lengthWeightParameter.getCoefficients() +// ); +// if (log.isInfoEnabled()) { +// log.info(message); +// } + lengthWeightComputable.setLength(newLength); + lengthWeightComputable.setLengthSource(true); + return; + } + + // la taille n'a pas ete changee, on peut quitter car il est impossible + // de calculer et la taille et le poids... + return; + } + + // on cherche obligatoirement a calculer le poids + Float newWeight = lengthWeightParameter.computeWeight(length); + if (newWeight != null) { + + // le poids a ete calcule +// String message = "[" + t(entityLabel) + "] " + +// t("observe.message.consolidate.computed.weight", +// newWeight, +// length, +// lengthWeightParameter.getLengthWeightFormula(), +// lengthWeightParameter.getCoefficients()); +// if (log.isInfoEnabled()) { +// log.info(message); +// } + lengthWeightComputable.setWeight(newWeight); + lengthWeightComputable.setWeightSource(true); + } + } + + protected void updateLengthWeightAble(LengthWeightComputable lengthWeightComputable, + LengthWeightParameter lengthWeightParameter) { + +// String entityLabel = getSpeciesLabel(); + + Float weight = lengthWeightComputable.getWeight(); + boolean computeWeight = false; + boolean computeLength = false; + Float length = lengthWeightComputable.getLength(); + + if (weight == null && length != null) { + + // on essaye de calculer le poids + computeWeight = true; + } + + if (length == null && weight != null) { + + // on essaye de calcule la taille + computeLength = true; + } + + if (!computeLength && !computeWeight) { + + // rien a calculer + return; + } + + if (lengthWeightParameter == null) { + + // aucun parametrage connu + +// String message = t("observe.message.consolidate.no.parametrage.found", +// t(entityLabel), +// decorate(species) +// ); +// if (log.isWarnEnabled()) { +// log.warn(message); +// } + return; + } + + if (computeLength) { + Float newLength = lengthWeightParameter.computeLength(weight); + if (newLength != null) { + + // la taille a ete calculee +// String message = +// "[" + t(entityLabel) + "] " + +// t("observe.message.consolidate.computed.taille", +// newLength, +// weight, +// lengthWeightParameter.getWeightLengthFormula(), +// lengthWeightParameter.getCoefficients() +// ); +// if (log.isInfoEnabled()) { +// log.info(message); +// } + lengthWeightComputable.setLength(newLength); + lengthWeightComputable.setLengthSource(true); + return; + } + + // la taille n'a pas ete changee, on peut quitter car il est impossible + // de calculer et la taille et le poids... + return; + } + + // on cherche obligatoirement a calculer le poids + Float newWeight = lengthWeightParameter.computeWeight(length); + if (newWeight != null) { + + // le poids a ete calcule +// String message = "[" + t(entityLabel) + "] " + +// t("observe.message.consolidate.computed.weight", +// newWeight, +// length, +// lengthWeightParameter.getLengthWeightFormula(), +// lengthWeightParameter.getCoefficients()); +// if (log.isInfoEnabled()) { +// log.info(message); +// } + lengthWeightComputable.setWeight(newWeight); + lengthWeightComputable.setWeightSource(true); + } + } + +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm