This is an automated email from the git hooks/post-receive script. New commit to branch feature/6392 in repository wao. See http://git.codelutin.com/wao.git commit ecc418794e1be1d1933434f9e1a0252781c554fd Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Feb 25 15:48:48 2015 +0100 Lors du calcul du plan ObsMer, on ne se repose plus sur les données dénormalisées en base mais on calcul les nombres d'observations par mois en même temps que le nombre de jours par mois. En même temps, on corrige le mode de calcul en affectant la marée au mois ayant le plus de jours (testable-cl #6392) --- .../service/ObsMerSamplingPlanBuilder.java | 133 ++++++++++++--------- 1 file changed, 79 insertions(+), 54 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java index d18837f..b7ae22c 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java @@ -22,6 +22,7 @@ package fr.ifremer.wao.services.service; */ import com.google.common.base.Function; +import com.google.common.base.MoreObjects; import com.google.common.base.Optional; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; @@ -34,6 +35,9 @@ import fr.ifremer.wao.entity.ObsProgram; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRows; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.util.PeriodDates; import java.util.ArrayList; @@ -57,6 +61,8 @@ import java.util.TreeMap; */ public class ObsMerSamplingPlanBuilder { + private static final Log log = LogFactory.getLog(ObsMerSamplingPlanBuilder.class); + /** * Incoming filter used. */ @@ -113,32 +119,12 @@ public class ObsMerSamplingPlanBuilder { // get sector context SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); - // calcul de l'effort en nombre d'observations puis en nombre jours - Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = getEffortInObservationsPerMonths(sampleRow); - Map<Date, SamplingPlan.Effort> effortInDaysPerMonths = getEffortInDaysPerMonths(sampleRow, doneObservations); - - // ajout dans les totaux par mois - totalObservationsForMonths.putAll(Multimaps.forMap(effortInObservationsPerMonths)); - totalDaysForMonths.putAll(Multimaps.forMap(effortInDaysPerMonths)); - - // add sample row - sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), - sampleRow, - effortInObservationsPerMonths, - effortInDaysPerMonths, - sampleRowContactCounts); - - sampleRowsFilterValues.addSampleRow(sampleRow); - - sampleRowIds.add(sampleRow.getTopiaId()); - - } - - protected Map<Date, SamplingPlan.Effort> getEffortInDaysPerMonths(SampleRow sampleRow, Collection<Contact> doneObservations) { - // Pour chaque observation réalisée, on ajoute dans ces multimaps, une ou plusieurs // entrées. Une observation a pu avoir lieu sur deux mois. Une entrée indique que pour // le mois en clé, la valeur est un nombre de jour passé en mer + Map<Date, MutableInt> estimatedObservationsByMonths = new TreeMap<>(); + Map<Date, MutableInt> realObservationsByMonths = new TreeMap<>(); + LinkedListMultimap<Date, Integer> estimatedObservationDaysByMonths = LinkedListMultimap.create(); LinkedListMultimap<Date, Integer> realObservationDaysByMonths = LinkedListMultimap.create(); @@ -150,44 +136,105 @@ public class ObsMerSamplingPlanBuilder { doneObservation.getObservationBeginDate(), doneObservation.getObservationEndDate()); + // on en déduit le mois sur lequel il faut compter l'observation + Date month = null; + int maxObservationDays = 0; + for (Map.Entry<Date, Integer> entry : observationDaysByMonthsForObservation.entrySet()) { + Date aMonth = entry.getKey(); + Integer aObservationDays = entry.getValue(); + if (aObservationDays > maxObservationDays) { + month = aMonth; + } + } + + if (log.isDebugEnabled()) { + log.debug("contact " + doneObservation + " will be added to month " + month); + } + + // si le contact doit être compté dans le réel if (BooleanUtils.isTrue(doneObservation.getValidationCompany())) { + + // on ajoute les jours realObservationDaysByMonths.putAll(Multimaps.forMap(observationDaysByMonthsForObservation)); + + // on compte 1 observation + MutableInt real = realObservationsByMonths.get(month); + if (real == null) { + real = new MutableInt(0); + realObservationsByMonths.put(month, real); + } + real.increment(); } + // le contact doit être ajouté dans l'estimée (car on ne parcourt pas les contacts refusés) + // on ajoute les jours dans l'estimé estimatedObservationDaysByMonths.putAll(Multimaps.forMap(observationDaysByMonthsForObservation)); + // on compte 1 observation dans l'estimé + MutableInt estimated = estimatedObservationsByMonths.get(month); + if (estimated == null) { + estimated = new MutableInt(0); + estimatedObservationsByMonths.put(month, estimated); + } + estimated.increment(); + } + // calcul de l'effort en nombre d'observations puis en nombre jours + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = new TreeMap<>(); Map<Date, SamplingPlan.Effort> effortInDaysPerMonths = new TreeMap<>(); for (Date month : months) { // calcul du plannifié - Integer expected = null; + Integer expectedDays = null; Integer expectedObservations = SampleRows.getExpectedTidesValue(sampleRow, month); if (expectedObservations != null) { - expected = expectedObservations * sampleRow.getAverageTideTime(); + expectedDays = expectedObservations * sampleRow.getAverageTideTime(); } // calcul de l'estimé et du réel Collection<Integer> estimatedDoneObservationDays = estimatedObservationDaysByMonths.asMap().get(month); - Integer estimated = 0; // car estimatedDoneObservationDays peut être null si aucune observation sur le mois + Integer estimatedDays = 0; // car estimatedDoneObservationDays peut être null si aucune observation sur le mois if (estimatedDoneObservationDays != null) { - estimated = WaoUtils.sum(estimatedDoneObservationDays); + estimatedDays = WaoUtils.sum(estimatedDoneObservationDays); } Collection<Integer> realDoneObservationDays = realObservationDaysByMonths.asMap().get(month); - Integer real = 0; // car realDoneObservationDays peut être null si aucune observation sur le mois + Integer realDays = 0; // car realDoneObservationDays peut être null si aucune observation sur le mois if (realDoneObservationDays != null) { - real = WaoUtils.sum(realDoneObservationDays); + realDays = WaoUtils.sum(realDoneObservationDays); } - SamplingPlan.Effort effortForMonth = new SamplingPlan.Effort(expected, real, estimated); - effortInDaysPerMonths.put(month, effortForMonth); + int estimatedObservations = MoreObjects.firstNonNull(estimatedObservationsByMonths.get(month), 0).intValue(); + int realObservations = MoreObjects.firstNonNull(realObservationsByMonths.get(month), 0).intValue(); + + // on a le planifier, l'estimé, le réel en jour et en nombre d'observations, on fait les totaux + + SamplingPlan.Effort effortForMonthInObservations = + new SamplingPlan.Effort(expectedObservations, realObservations, estimatedObservations); + SamplingPlan.Effort effortForMonthInDays = + new SamplingPlan.Effort(expectedDays, realDays, estimatedDays); + + effortInObservationsPerMonths.put(month, effortForMonthInObservations); + effortInDaysPerMonths.put(month, effortForMonthInDays); } - return effortInDaysPerMonths; + // ajout dans les totaux par mois + totalObservationsForMonths.putAll(Multimaps.forMap(effortInObservationsPerMonths)); + totalDaysForMonths.putAll(Multimaps.forMap(effortInDaysPerMonths)); + + // add sample row + sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), + sampleRow, + effortInObservationsPerMonths, + effortInDaysPerMonths, + sampleRowContactCounts); + + sampleRowsFilterValues.addSampleRow(sampleRow); + + sampleRowIds.add(sampleRow.getTopiaId()); } @@ -238,28 +285,6 @@ public class ObsMerSamplingPlanBuilder { return result; } - protected Map<Date, SamplingPlan.Effort> getEffortInObservationsPerMonths(SampleRow sampleRow) { - - Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = new TreeMap<>(); - - for (Date month : months) { - - Integer expectedTidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); - Integer estimatedTidesValue = SampleRows.getEstimatedTidesValue(sampleRow, month); - Integer realTidesValue = SampleRows.getRealTidesValue(sampleRow, month); - - SamplingPlan.Effort effortForMonth = - new SamplingPlan.Effort( - expectedTidesValue, - realTidesValue, - estimatedTidesValue); - effortInObservationsPerMonths.put(month, effortForMonth); - - } - - return effortInObservationsPerMonths; - } - protected static class FacadeContext { protected String facade; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.