This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 8de096c5589af53138cfecf4afde0169df650c91 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Dec 26 12:05:25 2014 +0100 Ajout des totaux en individus dans le plan --- .../ifremer/wao/services/service/SamplingPlan.java | 19 +-- .../service/SclerochronologySamplingPlan.java | 30 ++++- .../SclerochronologySamplingPlanBuilder.java | 145 +++++++-------------- .../SclerochronologySamplingPlanServiceTest.java | 12 ++ 4 files changed, 91 insertions(+), 115 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java index d2f7b41..50743a7 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java @@ -362,24 +362,7 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan this.sampleRowContactCounts = sampleRowContactCounts; // pour la ligne, on calcul le total en nombre d'observation - int totalTidesExpected = 0; - int totalTidesEstimated = 0; - int totalTidesReal = 0; - for (Effort effort : effortInObservationsPerMonths.values()) { - Integer totalExpected = effort.getExpected(); - if (totalExpected != null) { - totalTidesExpected += totalExpected; - } - Integer totalEstimated = effort.getEstimated(); - if (totalEstimated != null) { - totalTidesEstimated += totalEstimated; - } - Integer totalReal = effort.getReal(); - if (totalReal != null) { - totalTidesReal += totalReal; - } - } - totalObservations = new Effort(totalTidesExpected, totalTidesReal, totalTidesEstimated); + totalObservations = Effort.sum(effortInObservationsPerMonths.values()); facade = sampleRow.getFacade(); sectors = sampleRow.getSectors(); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java index 28dc7ec..cc13303 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java @@ -34,8 +34,29 @@ import java.util.Set; public class SclerochronologySamplingPlan extends SamplingPlan implements Iterable<SamplingPlan.SamplingPlanFacadePart> { - public SclerochronologySamplingPlan(List<Date> months, Collection<SamplingPlanFacadePart> facadeParts, Map<Date, Effort> totalEffortInObservationsPerMonths, Effort highTotalEffortInObservations, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { + protected Map<Date, Effort> totalEffortInIndividualsPerMonths; + + protected Effort highTotalEffortInIndividuals; + + public SclerochronologySamplingPlan(List<Date> months, + Collection<SamplingPlanFacadePart> facadeParts, + Map<Date, Effort> totalEffortInObservationsPerMonths, + Map<Date, Effort> totalEffortInIndividualsPerMonths, + Effort highTotalEffortInObservations, + Effort highTotalEffortInIndividuals, + SampleRowsFilterValues filterValues, + Set<String> sampleRowIds) { super(months, facadeParts, totalEffortInObservationsPerMonths, highTotalEffortInObservations, filterValues, sampleRowIds); + this.totalEffortInIndividualsPerMonths = totalEffortInIndividualsPerMonths; + this.highTotalEffortInIndividuals = highTotalEffortInIndividuals; + } + + public Map<Date, Effort> getTotalEffortInIndividualsPerMonths() { + return totalEffortInIndividualsPerMonths; + } + + public Effort getHighTotalEffortInIndividuals() { + return highTotalEffortInIndividuals; } public static class SclerochronologySamplingPlanSampleRowPart extends SamplingPlanSampleRowPart { @@ -52,6 +73,8 @@ public class SclerochronologySamplingPlan extends SamplingPlan implements Iterab protected Map<Date, Effort> effortInIndividualsPerMonths; + protected Effort totalIndividuals; + public SclerochronologySamplingPlanSampleRowPart(Locale locale, Map<Date, Effort> effortInObservationsPerMonths, Map<Date, Effort> effortInIndividualsPerMonths, SampleRow sampleRow, long sampleRowContactCounts) { super(locale, effortInObservationsPerMonths, sampleRow, sampleRowContactCounts); this.effortInIndividualsPerMonths = effortInIndividualsPerMonths; @@ -60,6 +83,7 @@ public class SclerochronologySamplingPlan extends SamplingPlan implements Iterab samplingContextInfo = sampleRow.getSclerochronologySamplingContextInfo(); individualMeasurementStrategy = WaoUtils.l(locale, sampleRow.getIndividualMeasurementStrategy()); organisationFullName = sampleRow.getOrganisation().getFullName(); + totalIndividuals = Effort.sum(effortInIndividualsPerMonths.values()); } public String getOrganisationFullName() { @@ -120,6 +144,10 @@ public class SclerochronologySamplingPlan extends SamplingPlan implements Iterab public String getCompanyName() { throw new UnsupportedOperationException("not in " + ObsProgram.SCLEROCHRONOLOGY); } + + public Effort getTotalIndividuals() { + return totalIndividuals; + } } } \ No newline at end of file diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java index 0c97760..cc99a98 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java @@ -24,6 +24,8 @@ package fr.ifremer.wao.services.service; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.collect.LinkedListMultimap; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.Multimaps; import com.google.common.collect.Ordering; import fr.ifremer.wao.SampleRowsFilter; import fr.ifremer.wao.WaoUtils; @@ -32,7 +34,6 @@ 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.lang3.time.DateUtils; import org.nuiton.util.PeriodDates; @@ -65,7 +66,7 @@ public class SclerochronologySamplingPlanBuilder { /** * Ids of all the sample rows included in this sampling plan. */ - protected Set<String> sampleRowIds; + protected Set<String> sampleRowIds = new HashSet<>(); /** * List of month computed from the filter. @@ -75,61 +76,17 @@ public class SclerochronologySamplingPlanBuilder { /** * Dictionnary of facades indexed by their facade name. */ - protected Map<String, FacadeContext> facadeMap; + protected Map<String, FacadeContext> facadeMap = new TreeMap<>(); - /** - * To compute the high total expected. - * - * @see fr.ifremer.wao.services.service.SclerochronologySamplingPlan#highTotalEffortInObservations - */ - protected int highTotalExpected; - - /** - * To compute the high total real. - * - * @see fr.ifremer.wao.services.service.SclerochronologySamplingPlan#highTotalEffortInObservations - */ - protected int highTotalReal; - - /** - * To compute the high total estimated. - * - * @see fr.ifremer.wao.services.service.SclerochronologySamplingPlan#highTotalEffortInObservations - */ - protected int highTotalEstimated; - - /** - * To compute by month the total of expected tides. - * - * @see fr.ifremer.wao.services.service.SamplingPlan.Effort#expected - */ - protected Map<Date, MutableInt> totalExpectedForMonths; + protected ListMultimap<Date, SamplingPlan.Effort> totalObservationsForMonths = LinkedListMultimap.create(); - /** - * To compute by month the total of expected tides. - * - * @see fr.ifremer.wao.services.service.SamplingPlan.Effort#estimated - */ - protected Map<Date, MutableInt> totalEstimatedForMonths; - - /** - * To compute by month the total of real tides. - * - * @see fr.ifremer.wao.services.service.SamplingPlan.Effort#real - */ - protected Map<Date, MutableInt> totalRealForMonths; + protected ListMultimap<Date, SamplingPlan.Effort> totalIndividualsForMonths = LinkedListMultimap.create(); public SclerochronologySamplingPlanBuilder(Locale locale, Optional<String> optionalCompanyId, SampleRowsFilter sampleRowsFilter) { this.sampleRowsFilter = sampleRowsFilter; this.sampleRowsFilterValues = new SampleRowsFilterValues(locale, ObsProgram.SCLEROCHRONOLOGY, optionalCompanyId); - this.sampleRowIds = new HashSet<>(); - this.facadeMap = new TreeMap<>(); - this.totalExpectedForMonths = new TreeMap<>(); - this.totalRealForMonths = new TreeMap<>(); - this.totalEstimatedForMonths = new TreeMap<>(); - PeriodDates periodDates = new PeriodDates(sampleRowsFilter.getPeriodFrom(), sampleRowsFilter.getPeriodTo()); this.months = periodDates.getMonths(); @@ -156,6 +113,10 @@ public class SclerochronologySamplingPlanBuilder { Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = getEffortInObservationsPerMonths(sampleRow); Map<Date, SamplingPlan.Effort> effortInIndividualsPerMonths = getEffortInIndividualsPerMonths(sampleRow, doneObservations); + // ajout dans les totaux par mois + totalObservationsForMonths.putAll(Multimaps.forMap(effortInObservationsPerMonths)); + totalIndividualsForMonths.putAll(Multimaps.forMap(effortInIndividualsPerMonths)); + // add sample row sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), sampleRow, @@ -186,68 +147,60 @@ public class SclerochronologySamplingPlanBuilder { } }).immutableSortedCopy(facadeParts); - // Get statistics - Map<Date, SamplingPlan.Effort> statisticsMap = new TreeMap<>(); + // On a accumulé les totaux en nombre d'observation / par mois, on fait les calculs finaux + Map<Date, SamplingPlan.Effort> totalEffortInObservationsPerMonths = new TreeMap<>(); + Map<Date, SamplingPlan.Effort> totalEffortInIndividualsPerMonths = new TreeMap<>(); + for (Date month : months) { - MutableInt totalExpected = totalExpectedForMonths.get(month); - MutableInt totalReal = totalRealForMonths.get(month); - MutableInt totalEstimated = totalEstimatedForMonths.get(month); - SamplingPlan.Effort planStatistics = - new SamplingPlan.Effort(totalExpected == null ? null : totalExpected.toInteger(), - totalReal == null ? null : totalReal.toInteger(), - totalEstimated == null ? null : totalEstimated.toInteger()); - statisticsMap.put(month, planStatistics); + Collection<SamplingPlan.Effort> totalObservationsForMonth = totalObservationsForMonths.asMap().get(month); + SamplingPlan.Effort totalEffortInObservationsForMonth = SamplingPlan.Effort.sum(totalObservationsForMonth); + totalEffortInObservationsPerMonths.put(month, totalEffortInObservationsForMonth); + + Collection<SamplingPlan.Effort> totalIndividualsForMonth = totalIndividualsForMonths.asMap().get(month); + SamplingPlan.Effort totalEffortInIndividualsForMonth = SamplingPlan.Effort.sum(totalIndividualsForMonth); + totalEffortInIndividualsPerMonths.put(month, totalEffortInIndividualsForMonth); + } - SamplingPlan.Effort highTotals = new SamplingPlan.Effort(highTotalExpected, highTotalReal, highTotalEstimated); + // on calcule le grand total en faisant la somme sur tous les mois + SamplingPlan.Effort highTotalEffortInObservations = SamplingPlan.Effort.sum(totalEffortInObservationsPerMonths.values()); + SamplingPlan.Effort highTotalEffortInIndividuals = SamplingPlan.Effort.sum(totalEffortInIndividualsPerMonths.values()); + + SclerochronologySamplingPlan result = new SclerochronologySamplingPlan( + months, + sortedFacades, + totalEffortInObservationsPerMonths, + totalEffortInIndividualsPerMonths, + highTotalEffortInObservations, + highTotalEffortInIndividuals, + sampleRowsFilterValues, + sampleRowIds); - SclerochronologySamplingPlan result = new SclerochronologySamplingPlan(months, - sortedFacades, - statisticsMap, - highTotals, - sampleRowsFilterValues, - sampleRowIds); return result; } protected Map<Date, SamplingPlan.Effort> getEffortInObservationsPerMonths(SampleRow sampleRow) { - Map<Date, SamplingPlan.Effort> result = new TreeMap<>(); + + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = new TreeMap<>(); + for (Date month : months) { + + // FIXME brendan 26/12/14 n'a aucun sens puisqu'on récupère des individus Integer expectedTidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); - if (expectedTidesValue != null) { - MutableInt mutableInt = totalExpectedForMonths.get(month); - if (mutableInt == null) { - totalExpectedForMonths.put(month, mutableInt = new MutableInt()); - } - mutableInt.add(expectedTidesValue); - highTotalExpected += expectedTidesValue; - } + Integer estimatedTidesValue = SampleRows.getEstimatedTidesValue(sampleRow, month); Integer realTidesValue = SampleRows.getRealTidesValue(sampleRow, month); - if (realTidesValue != null) { - MutableInt mutableInt = totalRealForMonths.get(month); - if (mutableInt == null) { - totalRealForMonths.put(month, mutableInt = new MutableInt()); - } - mutableInt.add(realTidesValue); - highTotalReal += realTidesValue; - } - Integer estimatedTidesValue = SampleRows.getEstimatedTidesValue(sampleRow, month); - if (estimatedTidesValue != null) { - MutableInt mutableInt = totalEstimatedForMonths.get(month); - if (mutableInt == null) { - totalEstimatedForMonths.put(month, mutableInt = new MutableInt()); - } - mutableInt.add(estimatedTidesValue); - highTotalEstimated += estimatedTidesValue; - } - result.put(month, new SamplingPlan.Effort(expectedTidesValue, - realTidesValue, - estimatedTidesValue)); + SamplingPlan.Effort effortForMonth = + new SamplingPlan.Effort( + expectedTidesValue, + realTidesValue, + estimatedTidesValue); + effortInObservationsPerMonths.put(month, effortForMonth); } - return result; + + return effortInObservationsPerMonths; } protected Map<Date, SamplingPlan.Effort> getEffortInIndividualsPerMonths(SampleRow sampleRow, Collection<Contact> doneObservations) { diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java index 5aa1aeb..5818302 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java @@ -147,9 +147,21 @@ public class SclerochronologySamplingPlanServiceTest extends AbstractWaoServiceT SamplingPlan.Effort effortInIndividualsForJanuary = Iterables.get(row.getEffortInIndividualsPerMonths().values(), 0); Assert.assertEquals(53, effortInIndividualsForJanuary.getEstimated().intValue()); Assert.assertEquals(53, effortInIndividualsForJanuary.getReal().intValue()); + + Assert.assertEquals(53, row.getTotalIndividuals().getEstimated().intValue()); + Assert.assertEquals(53, row.getTotalIndividuals().getReal().intValue()); } } } } + + SamplingPlan.Effort effortInIndividualsForJanuary = Iterables.get(samplingPlan.getTotalEffortInIndividualsPerMonths().values(), 0); + + Assert.assertEquals(53, effortInIndividualsForJanuary.getEstimated().intValue()); + Assert.assertEquals(53, effortInIndividualsForJanuary.getReal().intValue()); + + Assert.assertEquals(53, samplingPlan.getHighTotalEffortInIndividuals().getEstimated().intValue()); + Assert.assertEquals(53, samplingPlan.getHighTotalEffortInIndividuals().getReal().intValue()); + } } \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.