This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository wao. See http://git.codelutin.com/wao.git commit 4f0e637a78d21f0f31b9f473fa4b6233c578ac13 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Oct 14 11:57:44 2014 +0200 On déplace le calcul des totaux par mois et du grand total en nombre d'observations à la fin du calcul du plan plutôt que pendant --- .../wao/services/service/ObsMerSamplingPlan.java | 6 +- .../service/ObsMerSamplingPlanBuilder.java | 137 +++++++++++---------- .../wao/services/service/ObsVenteSamplingPlan.java | 4 +- 3 files changed, 78 insertions(+), 69 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java index ede800e..5af91cb 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java @@ -61,14 +61,14 @@ public class ObsMerSamplingPlan extends SamplingPlan { public ObsMerSamplingPlan(List<Date> months, Collection<SamplingPlanFacadePart> facadeParts, - Map<Date, Effort> totalsPerMonth, - Effort highTotals, + Map<Date, Effort> totalEffortInObservationsPerMonths, + Effort highTotalEffortInObservations, Double observationTimesInDaysTotalExpected, Long observationTimesInDaysTotalReal, Long observationTimesInDaysTotalEstimated, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { - super(months, facadeParts, totalsPerMonth, highTotals, filterValues, sampleRowIds); + super(months, facadeParts, totalEffortInObservationsPerMonths, highTotalEffortInObservations, filterValues, sampleRowIds); this.observationTimesInDaysTotalExpected = observationTimesInDaysTotalExpected; this.observationTimesInDaysTotalReal = observationTimesInDaysTotalReal; this.observationTimesInDaysTotalEstimated = observationTimesInDaysTotalEstimated; 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 8a368d1..c467b23 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 @@ -80,27 +80,6 @@ public class ObsMerSamplingPlanBuilder { protected Map<String, FacadeContext> facadeMap; /** - * To compute the high total expected. - * - * @see ObsMerSamplingPlan#highTotalEffortInObservations - */ - protected int highTotalExpected; - - /** - * To compute the high total real. - * - * @see ObsMerSamplingPlan#highTotalEffortInObservations - */ - protected int highTotalReal; - - /** - * To compute the high total estimated. - * - * @see ObsMerSamplingPlan#highTotalEffortInObservations - */ - protected int highTotalEstimated; - - /** * To compute the total of expected observation times in days. * * @see ObsMerSamplingPlan#observationTimesInDaysTotalExpected @@ -185,6 +164,37 @@ public class ObsMerSamplingPlanBuilder { // compute nb tides per month Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = getEffortInObservationsPerMonths(sampleRow); + // mise à jour des totaux mensuels + for (Map.Entry<Date, SamplingPlan.Effort> entry : effortInObservationsPerMonths.entrySet()) { + + Date month = entry.getKey(); + Integer expectedObservationsForMonth = entry.getValue().getExpected(); + Integer estimatedObservationsForMonth = entry.getValue().getEstimated(); + Integer realObservationsForMonth = entry.getValue().getReal(); + + if (expectedObservationsForMonth != null) { + MutableInt mutableInt = totalExpectedForMonths.get(month); + if (mutableInt == null) { + totalExpectedForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(expectedObservationsForMonth); + } + if (estimatedObservationsForMonth != null) { + MutableInt mutableInt = totalEstimatedForMonths.get(month); + if (mutableInt == null) { + totalEstimatedForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(estimatedObservationsForMonth); + } + if (realObservationsForMonth != null) { + MutableInt mutableInt = totalRealForMonths.get(month); + if (mutableInt == null) { + totalRealForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(realObservationsForMonth); + } + } + // add sample row sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), sampleRow, @@ -222,26 +232,42 @@ public class ObsMerSamplingPlanBuilder { } }).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<>(); + int highTotalExpected = 0; + int highTotalReal = 0; + int highTotalEstimated = 0; + 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); + MutableInt totalExpectedForMonth = totalExpectedForMonths.get(month); + MutableInt totalEstimatedForMonth = totalEstimatedForMonths.get(month); + MutableInt totalRealForMonth = totalRealForMonths.get(month); + + SamplingPlan.Effort monthEffort = + new SamplingPlan.Effort(totalExpectedForMonth == null ? null : totalExpectedForMonth.toInteger(), + totalRealForMonth == null ? null : totalRealForMonth.toInteger(), + totalEstimatedForMonth == null ? null : totalEstimatedForMonth.toInteger()); + totalEffortInObservationsPerMonths.put(month, monthEffort); + + if (totalExpectedForMonth != null) { + highTotalExpected += totalExpectedForMonth.toInteger(); + } + if (totalEstimatedForMonth != null) { + highTotalEstimated += totalEstimatedForMonth.toInteger(); + } + if (totalRealForMonth != null) { + highTotalReal += totalRealForMonth.toInteger(); + } + } - SamplingPlan.Effort highTotals = new SamplingPlan.Effort(highTotalExpected, highTotalReal, highTotalEstimated); + SamplingPlan.Effort highTotalEffortInObservations = new SamplingPlan.Effort(highTotalExpected, highTotalReal, highTotalEstimated); ObsMerSamplingPlan result = new ObsMerSamplingPlan(months, sortedFacades, - statisticsMap, - highTotals, + totalEffortInObservationsPerMonths, + highTotalEffortInObservations, observationTimesInDaysTotalExpected.toDouble(), observationTimesInDaysTotalReal.toLong(), observationTimesInDaysTotalEstimated.toLong(), @@ -251,42 +277,25 @@ public class ObsMerSamplingPlanBuilder { } 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) { + 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 static class FacadeContext { diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java index eb3cd7a..6637e3e 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java @@ -36,8 +36,8 @@ import java.util.Set; public class ObsVenteSamplingPlan extends SamplingPlan implements Iterable<SamplingPlan.SamplingPlanFacadePart> { - public ObsVenteSamplingPlan(List<Date> months, Collection<SamplingPlanFacadePart> facadeParts, Map<Date, Effort> totalsPerMonth, Effort highTotals, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { - super(months, facadeParts, totalsPerMonth, highTotals, filterValues, sampleRowIds); + public ObsVenteSamplingPlan(List<Date> months, Collection<SamplingPlanFacadePart> facadeParts, Map<Date, Effort> totalEffortInObservationsPerMonths, Effort highTotalEffortInObservations, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { + super(months, facadeParts, totalEffortInObservationsPerMonths, highTotalEffortInObservations, filterValues, sampleRowIds); } public static class ObsVenteSamplingPlanSampleRowPart extends SamplingPlanSampleRowPart { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.