[wao] branch feature/5651 updated (92dc9de -> 85357f1)
This is an automated email from the git hooks/post-receive script. New change to branch feature/5651 in repository wao. See http://git.codelutin.com/wao.git from 92dc9de Dans ObsMerSamplingPlanService, on sépare les préoccupations entre calcul de la clé du cache, lecture du cache et calcul du plan new 91b7f09 On renomme une variable du plan pour parler d'observation et non de marée new 4f0e637 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 new 85357f1 Suite de remaniement de la génération du plan ObsMer The 3 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 85357f14867187bb2d99a6a829eb8307e47d4830 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Oct 14 15:50:09 2014 +0200 Suite de remaniement de la génération du plan ObsMer On reste isofonctionel par rapport au début de la branche. Le grand total est désormais calculé à partir des totaux pour chaque mois ; on utilise des multimaps pour stocker tous les Effort rencontrés plutôt que trois maps pour stocké le plannifié, le réel et l'estimé ; on a tous les calculs en jours de mers pour toutes les cellules du plan mais ce n'est pas affiché ; on utilise le template td-effort pour les jours de mers. 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 commit 91b7f0912d2d250e259afe2f2764f059d38189b3 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Oct 14 11:15:16 2014 +0200 On renomme une variable du plan pour parler d'observation et non de marée Summary of changes: .../src/main/java/fr/ifremer/wao/WaoUtils.java | 7 + .../wao/services/service/ObsMerSamplingPlan.java | 153 +++-------- .../service/ObsMerSamplingPlanBuilder.java | 282 +++++++++------------ .../service/ObsMerSamplingPlanService.java | 93 +------ .../wao/services/service/ObsVenteSamplingPlan.java | 8 +- .../service/ObsVenteSamplingPlanBuilder.java | 10 +- .../ifremer/wao/services/service/SamplingPlan.java | 53 ++-- .../WEB-INF/content/obsmer/sampling-plan.jsp | 62 +---- 8 files changed, 242 insertions(+), 426 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/5651 in repository wao. See http://git.codelutin.com/wao.git commit 91b7f0912d2d250e259afe2f2764f059d38189b3 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Oct 14 11:15:16 2014 +0200 On renomme une variable du plan pour parler d'observation et non de marée --- .../wao/services/service/ObsMerSamplingPlan.java | 4 ++-- .../services/service/ObsMerSamplingPlanBuilder.java | 14 +++++++------- .../wao/services/service/ObsVenteSamplingPlan.java | 4 ++-- .../service/ObsVenteSamplingPlanBuilder.java | 10 +++++----- .../ifremer/wao/services/service/SamplingPlan.java | 20 +++++--------------- 5 files changed, 21 insertions(+), 31 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 9ca7366..ede800e 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 @@ -144,13 +144,13 @@ public class ObsMerSamplingPlan extends SamplingPlan { protected Double appliedCoverageRate; public ObsMerSamplingPlanSampleRowPart(Locale locale, - Map<Date, Effort> nbTidesPerMonth, + Map<Date, Effort> effortInObservationsPerMonths, SampleRow sampleRow, Integer observationTimesInDaysExpected, Long observationTimesInDaysReal, Long observationTimesInDaysEstimated, long sampleRowContactCounts) { - super(locale, nbTidesPerMonth, sampleRow, sampleRowContactCounts); + super(locale, effortInObservationsPerMonths, sampleRow, sampleRowContactCounts); this.observationTimesInDaysExpected = observationTimesInDaysExpected; this.observationTimesInDaysReal = observationTimesInDaysReal; this.observationTimesInDaysEstimated = observationTimesInDaysEstimated; 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 f213674..8a368d1 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 @@ -183,12 +183,12 @@ public class ObsMerSamplingPlanBuilder { SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); // compute nb tides per month - Map<Date, SamplingPlan.Effort> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = getEffortInObservationsPerMonths(sampleRow); // add sample row sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), sampleRow, - nbTidesPerMonth, + effortInObservationsPerMonths, observationTimesInDaysExpected, observationTimesInDaysReal, observationTimesInDaysEstimated, @@ -250,7 +250,7 @@ public class ObsMerSamplingPlanBuilder { return result; } - protected Map<Date, SamplingPlan.Effort> computeNbTidesPerMonth(SampleRow sampleRow) { + protected Map<Date, SamplingPlan.Effort> getEffortInObservationsPerMonths(SampleRow sampleRow) { Map<Date, SamplingPlan.Effort> result = new TreeMap<>(); for (Date month : months) { Integer expectedTidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); @@ -282,8 +282,8 @@ public class ObsMerSamplingPlanBuilder { highTotalEstimated += estimatedTidesValue; } result.put(month, new SamplingPlan.Effort(expectedTidesValue, - realTidesValue, - estimatedTidesValue)); + realTidesValue, + estimatedTidesValue)); } return result; @@ -344,7 +344,7 @@ public class ObsMerSamplingPlanBuilder { protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, SampleRow row, - Map<Date, SamplingPlan.Effort> nbTidesPerMonth, + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths, Integer observationTimesInDaysExpected, Long observationTimesInDaysReal, Long observationTimesInDaysEstimated, @@ -352,7 +352,7 @@ public class ObsMerSamplingPlanBuilder { ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart rowPart = new ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart(locale, - nbTidesPerMonth, + effortInObservationsPerMonths, row, observationTimesInDaysExpected, observationTimesInDaysReal, 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 dbe8e56..eb3cd7a 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 @@ -50,8 +50,8 @@ public class ObsVenteSamplingPlan extends SamplingPlan implements Iterable<Sampl protected String samplingStrategy; - public ObsVenteSamplingPlanSampleRowPart(Locale locale, Map<Date, Effort> nbTidesPerMonth, SampleRow sampleRow, long sampleRowContactCounts) { - super(locale, nbTidesPerMonth, sampleRow, sampleRowContactCounts); + public ObsVenteSamplingPlanSampleRowPart(Locale locale, Map<Date, Effort> effortInObservationsPerMonths, SampleRow sampleRow, long sampleRowContactCounts) { + super(locale, effortInObservationsPerMonths, sampleRow, sampleRowContactCounts); terrestrialLocationInfos = sampleRow.getTerrestrialLocationInfos(); terrestrialLocationNamesAndDescriptions = new LinkedHashMap<>(); if (CollectionUtils.isNotEmpty(sampleRow.getTerrestrialLocations())) { diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java index 5285c75..165ea51 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java @@ -147,12 +147,12 @@ public class ObsVenteSamplingPlanBuilder { SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); // compute nb tides per month - Map<Date, SamplingPlan.Effort> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = getEffortInObservationsPerMonths(sampleRow); // add sample row sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), sampleRow, - nbTidesPerMonth, + effortInObservationsPerMonths, sampleRowContactCounts); sampleRowsFilterValues.addSampleRow(sampleRow); @@ -203,7 +203,7 @@ public class ObsVenteSamplingPlanBuilder { return result; } - protected Map<Date, SamplingPlan.Effort> computeNbTidesPerMonth(SampleRow sampleRow) { + protected Map<Date, SamplingPlan.Effort> getEffortInObservationsPerMonths(SampleRow sampleRow) { Map<Date, SamplingPlan.Effort> result = new TreeMap<>(); for (Date month : months) { Integer expectedTidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); @@ -297,13 +297,13 @@ public class ObsVenteSamplingPlanBuilder { protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, SampleRow row, - Map<Date, SamplingPlan.Effort> nbTidesPerMonth, + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths, long sampleRowContactCounts) { ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart rowPart = new ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart( locale, - nbTidesPerMonth, + effortInObservationsPerMonths, row, sampleRowContactCounts); rows.add(rowPart); 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 7def4aa..2f35f41 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 @@ -263,7 +263,7 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan /** * Nb tides by month. */ - protected Map<Date, Effort> nbTidesPerMonth; + protected Map<Date, Effort> effortInObservationsPerMonths; protected long sampleRowContactCounts; @@ -331,16 +331,16 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan protected boolean elligibleBoatsProvided; public SamplingPlanSampleRowPart(Locale locale, - Map<Date, Effort> nbTidesPerMonth, + Map<Date, Effort> effortInObservationsPerMonths, SampleRow sampleRow, long sampleRowContactCounts) { - this.nbTidesPerMonth = nbTidesPerMonth; + this.effortInObservationsPerMonths = effortInObservationsPerMonths; this.sampleRowContactCounts = sampleRowContactCounts; // compute total tides int totalTidesExpected = 0; int totalTidesEstimated = 0; int totalTidesReal = 0; - for (Effort effort : nbTidesPerMonth.values()) { + for (Effort effort : effortInObservationsPerMonths.values()) { Integer totalExpected = effort.getExpected(); if (totalExpected != null) { totalTidesExpected += totalExpected; @@ -489,17 +489,7 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan } public Effort getEffortInObservationsForMonth(Date month) { - return nbTidesPerMonth.get(month); - } - - public String getTotalRealPercentage() { - String result = totalObservations.getRealPercentage(); - return result; - } - - public String getTotalEstimatedPercentage() { - String result = totalObservations.getEstimatedPercentage(); - return result; + return effortInObservationsPerMonths.get(month); } public String getFishingZones() { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/5651 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>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/5651 in repository wao. See http://git.codelutin.com/wao.git commit 85357f14867187bb2d99a6a829eb8307e47d4830 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Oct 14 15:50:09 2014 +0200 Suite de remaniement de la génération du plan ObsMer On reste isofonctionel par rapport au début de la branche. Le grand total est désormais calculé à partir des totaux pour chaque mois ; on utilise des multimaps pour stocker tous les Effort rencontrés plutôt que trois maps pour stocké le plannifié, le réel et l'estimé ; on a tous les calculs en jours de mers pour toutes les cellules du plan mais ce n'est pas affiché ; on utilise le template td-effort pour les jours de mers. --- .../src/main/java/fr/ifremer/wao/WaoUtils.java | 7 + .../wao/services/service/ObsMerSamplingPlan.java | 145 ++++-------- .../service/ObsMerSamplingPlanBuilder.java | 243 +++++++++------------ .../service/ObsMerSamplingPlanService.java | 93 +------- .../ifremer/wao/services/service/SamplingPlan.java | 33 ++- .../WEB-INF/content/obsmer/sampling-plan.jsp | 62 ++---- 6 files changed, 200 insertions(+), 383 deletions(-) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java b/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java index be5c664..fc25e7e 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java @@ -236,4 +236,11 @@ public class WaoUtils { return result; } + public static int sum(Collection<Integer> integers) { + int sum = 0; + for (Integer integer : integers) { + sum += integer; + } + return sum; + } } 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 5af91cb..5a1a0e3 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 @@ -34,72 +34,29 @@ public class ObsMerSamplingPlan extends SamplingPlan { private static final long serialVersionUID = 1L; - /** - * Total of observation times in days expected. - * <p/> - * <strong>Note:</strong> can be null. - */ - protected Double observationTimesInDaysTotalExpected; - - /** - * Total of observation times in days real. - * <p/> - * <strong>Note:</strong> can be null. - */ - protected Long observationTimesInDaysTotalReal; - - /** - * Total of observation times in days estimated. - * <p/> - * <strong>Note:</strong> can be null. - */ - protected Long observationTimesInDaysTotalEstimated; - - protected Double observationTimesInDaysTotalRealRatio; + protected Map<Date, Effort> totalEffortInDaysPerMonths; - protected Double observationTimesInDaysTotalEstimatedRatio; + protected Effort highTotalEffortInDays; public ObsMerSamplingPlan(List<Date> months, Collection<SamplingPlanFacadePart> facadeParts, Map<Date, Effort> totalEffortInObservationsPerMonths, + Map<Date, Effort> totalEffortInDaysPerMonths, Effort highTotalEffortInObservations, - Double observationTimesInDaysTotalExpected, - Long observationTimesInDaysTotalReal, - Long observationTimesInDaysTotalEstimated, + Effort highTotalEffortInDays, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { super(months, facadeParts, totalEffortInObservationsPerMonths, highTotalEffortInObservations, filterValues, sampleRowIds); - this.observationTimesInDaysTotalExpected = observationTimesInDaysTotalExpected; - this.observationTimesInDaysTotalReal = observationTimesInDaysTotalReal; - this.observationTimesInDaysTotalEstimated = observationTimesInDaysTotalEstimated; - if (observationTimesInDaysTotalExpected != null) { - if (observationTimesInDaysTotalReal != null) { - this.observationTimesInDaysTotalRealRatio = (double) observationTimesInDaysTotalReal / observationTimesInDaysTotalExpected; - } - if (observationTimesInDaysTotalEstimated != null) { - this.observationTimesInDaysTotalEstimatedRatio = (double) observationTimesInDaysTotalEstimated / observationTimesInDaysTotalExpected; - } - } - } - - public Double getObservationTimesInDaysTotalRealRatio() { - return observationTimesInDaysTotalRealRatio; - } - - public Double getObservationTimesInDaysTotalEstimatedRatio() { - return observationTimesInDaysTotalEstimatedRatio; - } - - public Double getObservationTimesInDaysTotalExpected() { - return observationTimesInDaysTotalExpected; + this.totalEffortInDaysPerMonths = totalEffortInDaysPerMonths; + this.highTotalEffortInDays = highTotalEffortInDays; } - public Long getObservationTimesInDaysTotalReal() { - return observationTimesInDaysTotalReal; + public Map<Date, Effort> getTotalEffortInDaysPerMonths() { + return totalEffortInDaysPerMonths; } - public Long getObservationTimesInDaysTotalEstimated() { - return observationTimesInDaysTotalEstimated; + public Effort getHighTotalEffortInDays() { + return highTotalEffortInDays; } /** @@ -112,30 +69,9 @@ public class ObsMerSamplingPlan extends SamplingPlan { private static final long serialVersionUID = 1L; - /** - * Expected Times of observation days. - * <p/> - * <strong>Note:</strong> can be null. - */ - protected Integer observationTimesInDaysExpected; + protected Map<Date, Effort> effortInDaysPerMonths; - /** - * Real times of observation in days. - * <p/> - * <strong>Note:</strong> can be null. - */ - protected Long observationTimesInDaysReal; - - /** - * Estimated times of observation in days. - * <p/> - * <strong>Note:</strong> can be null. - */ - protected Long observationTimesInDaysEstimated; - - protected Integer observationTimesInDaysEstimatedPercentage; - - protected Integer observationTimesInDaysRealPercentage; + protected Effort totalDays; protected int nbObservants; @@ -144,52 +80,45 @@ public class ObsMerSamplingPlan extends SamplingPlan { protected Double appliedCoverageRate; public ObsMerSamplingPlanSampleRowPart(Locale locale, - Map<Date, Effort> effortInObservationsPerMonths, SampleRow sampleRow, - Integer observationTimesInDaysExpected, - Long observationTimesInDaysReal, - Long observationTimesInDaysEstimated, + Map<Date, Effort> effortInObservationsPerMonths, + Map<Date, SamplingPlan.Effort> effortInDaysPerMonths, long sampleRowContactCounts) { super(locale, effortInObservationsPerMonths, sampleRow, sampleRowContactCounts); - this.observationTimesInDaysExpected = observationTimesInDaysExpected; - this.observationTimesInDaysReal = observationTimesInDaysReal; - this.observationTimesInDaysEstimated = observationTimesInDaysEstimated; - - - if (observationTimesInDaysExpected != null && observationTimesInDaysExpected > 0) { - if (observationTimesInDaysEstimated != null) { - observationTimesInDaysEstimatedPercentage = (int) Math.round((observationTimesInDaysEstimated / observationTimesInDaysExpected) * 100); + this.effortInDaysPerMonths = effortInDaysPerMonths; + + // pour la ligne, on calcule le total en nombre de jour de mers + int totalDaysExpected = 0; + int totalDaysEstimated = 0; + int totalDaysReal = 0; + for (Effort effort : effortInDaysPerMonths.values()) { + Integer totalExpected = effort.getExpected(); + if (totalExpected != null) { + totalDaysExpected += totalExpected; } - if (observationTimesInDaysReal != null) { - observationTimesInDaysRealPercentage = (int) Math.round((observationTimesInDaysReal / observationTimesInDaysExpected) * 100); + Integer totalEstimated = effort.getEstimated(); + if (totalEstimated != null) { + totalDaysEstimated += totalEstimated; + } + Integer totalReal = effort.getReal(); + if (totalReal != null) { + totalDaysReal += totalReal; } } + totalDays = new Effort(totalDaysExpected, totalDaysReal, totalDaysEstimated); nbObservants = sampleRow.getNbObservants(); averageTideTime = sampleRow.getAverageTideTime(); - appliedCoverageRate = sampleRow.getAppliedCoverageRate(); } - public Integer getObservationTimesInDaysExpected() { - return observationTimesInDaysExpected; + public Map<Date, Effort> getEffortInDaysPerMonths() { + return effortInDaysPerMonths; } - public Long getObservationTimesInDaysReal() { - return observationTimesInDaysReal; - } - - public Long getObservationTimesInDaysEstimated() { - return observationTimesInDaysEstimated; - } - - public Integer getObservationTimesInDaysRealPercentage() { - return observationTimesInDaysRealPercentage; - } - - public Integer getObservationTimesInDaysEstimatedPercentage() { - return observationTimesInDaysEstimatedPercentage; + public Effort getTotalDays() { + return totalDays; } public Double getAppliedCoverageRate() { @@ -203,5 +132,7 @@ public class ObsMerSamplingPlan extends SamplingPlan { public int getAverageTideTime() { return averageTideTime; } + } + } 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 c467b23..261a65d 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 @@ -23,14 +23,17 @@ 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; +import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ObsProgram; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRows; -import org.apache.commons.lang3.mutable.MutableDouble; -import org.apache.commons.lang3.mutable.MutableInt; -import org.apache.commons.lang3.mutable.MutableLong; +import org.apache.commons.lang3.BooleanUtils; import org.nuiton.util.PeriodDates; import java.util.ArrayList; @@ -67,7 +70,7 @@ public class ObsMerSamplingPlanBuilder { /** * 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. @@ -77,74 +80,23 @@ public class ObsMerSamplingPlanBuilder { /** * Dictionnary of facades indexed by their facade name. */ - protected Map<String, FacadeContext> facadeMap; + protected Map<String, FacadeContext> facadeMap = new TreeMap<>(); - /** - * To compute the total of expected observation times in days. - * - * @see ObsMerSamplingPlan#observationTimesInDaysTotalExpected - */ - protected MutableDouble observationTimesInDaysTotalExpected; - - /** - * To compute the total of estimated observation times in days. - * - * @see ObsMerSamplingPlan#observationTimesInDaysTotalEstimated - */ - protected MutableLong observationTimesInDaysTotalEstimated; - - /** - * To compute the total of actual observation times in days. - * - * @see ObsMerSamplingPlan#observationTimesInDaysTotalReal - */ - protected MutableLong observationTimesInDaysTotalReal; - - /** - * To compute by month the total of expected tides. - * - * @see fr.ifremer.wao.services.service.SamplingPlan.Effort#expected - */ - protected Map<Date, MutableInt> totalExpectedForMonths; - - /** - * 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> totalObservationsForMonths = LinkedListMultimap.create(); + protected ListMultimap<Date, SamplingPlan.Effort> totalDaysForMonths = LinkedListMultimap.create(); + public ObsMerSamplingPlanBuilder(Locale locale, Optional<String> optionalCompanyId, SampleRowsFilter sampleRowsFilter) { this.sampleRowsFilter = sampleRowsFilter; this.sampleRowsFilterValues = new SampleRowsFilterValues(locale, ObsProgram.OBSMER, optionalCompanyId); - this.sampleRowIds = new HashSet<>(); - this.facadeMap = new TreeMap<>(); - this.observationTimesInDaysTotalExpected = new MutableDouble(); - this.observationTimesInDaysTotalReal = new MutableLong(); - this.observationTimesInDaysTotalEstimated = new MutableLong(); - this.totalExpectedForMonths = new TreeMap<>(); - this.totalRealForMonths = new TreeMap<>(); - this.totalEstimatedForMonths = new TreeMap<>(); - PeriodDates periodDates = new PeriodDates(sampleRowsFilter.getPeriodFrom(), sampleRowsFilter.getPeriodTo()); this.months = periodDates.getMonths(); } - public ObsMerSamplingPlanBuilder addSampleRow(SampleRow sampleRow, - Integer observationTimesInDaysExpected, - Long observationTimesInDaysReal, - Long observationTimesInDaysEstimated, - long sampleRowContactCounts) { + public void addSampleRow(SampleRow sampleRow, Collection<Contact> doneObservations, long sampleRowContactCounts) { String facade = sampleRow.getFacade(); FacadeContext facadeContext = facadeMap.get(facade); @@ -161,59 +113,82 @@ public class ObsMerSamplingPlanBuilder { // get sector context SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); - // compute nb tides per month + // 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); - // mise à jour des totaux mensuels - for (Map.Entry<Date, SamplingPlan.Effort> entry : effortInObservationsPerMonths.entrySet()) { + // 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); - Date month = entry.getKey(); - Integer expectedObservationsForMonth = entry.getValue().getExpected(); - Integer estimatedObservationsForMonth = entry.getValue().getEstimated(); - Integer realObservationsForMonth = entry.getValue().getReal(); + sampleRowsFilterValues.addSampleRow(sampleRow); - if (expectedObservationsForMonth != null) { - MutableInt mutableInt = totalExpectedForMonths.get(month); - if (mutableInt == null) { - totalExpectedForMonths.put(month, mutableInt = new MutableInt()); - } - mutableInt.add(expectedObservationsForMonth); + 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 + LinkedListMultimap<Date, Integer> estimatedObservationDaysByMonths = LinkedListMultimap.create(); + LinkedListMultimap<Date, Integer> realObservationDaysByMonths = LinkedListMultimap.create(); + + for (Contact doneObservation : doneObservations) { + + // on prend l'observation, on regarde combien de jour ça ajoute à chaque mois + Map<Date, Integer> observationDaysByMonthsForObservation = + WaoUtils.getObservationDaysByMonths( + doneObservation.getObservationBeginDate(), + doneObservation.getObservationEndDate()); + + if (BooleanUtils.isTrue(doneObservation.getValidationCompany())) { + realObservationDaysByMonths.putAll(Multimaps.forMap(observationDaysByMonthsForObservation)); } - if (estimatedObservationsForMonth != null) { - MutableInt mutableInt = totalEstimatedForMonths.get(month); - if (mutableInt == null) { - totalEstimatedForMonths.put(month, mutableInt = new MutableInt()); - } - mutableInt.add(estimatedObservationsForMonth); + + estimatedObservationDaysByMonths.putAll(Multimaps.forMap(observationDaysByMonthsForObservation)); + + } + + Map<Date, SamplingPlan.Effort> effortInDaysPerMonths = new TreeMap<>(); + + for (Date month : months) { + + // calcul du plannifié + Integer expected = null; + Integer expectedObservations = SampleRows.getExpectedTidesValue(sampleRow, month); + if (expectedObservations != null) { + expected = expectedObservations * sampleRow.getAverageTideTime(); } - if (realObservationsForMonth != null) { - MutableInt mutableInt = totalRealForMonths.get(month); - if (mutableInt == null) { - totalRealForMonths.put(month, mutableInt = new MutableInt()); - } - mutableInt.add(realObservationsForMonth); + + // 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 + if (estimatedDoneObservationDays != null) { + estimated = WaoUtils.sum(estimatedDoneObservationDays); } - } - // add sample row - sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), - sampleRow, - effortInObservationsPerMonths, - observationTimesInDaysExpected, - observationTimesInDaysReal, - observationTimesInDaysEstimated, - sampleRowContactCounts); - - // Sum total observation times in days - observationTimesInDaysTotalExpected.add(observationTimesInDaysExpected); - observationTimesInDaysTotalReal.add(observationTimesInDaysReal); - observationTimesInDaysTotalEstimated.add(observationTimesInDaysEstimated); + Collection<Integer> realDoneObservationDays = estimatedObservationDaysByMonths.asMap().get(month); + Integer real = 0; // car realDoneObservationDays peut être null si aucune observation sur le mois + if (realDoneObservationDays != null) { + real = WaoUtils.sum(realDoneObservationDays); + } - sampleRowsFilterValues.addSampleRow(sampleRow); + SamplingPlan.Effort effortForMonth = new SamplingPlan.Effort(expected, real, estimated); + effortInDaysPerMonths.put(month, effortForMonth); - sampleRowIds.add(sampleRow.getTopiaId()); + } + + return effortInDaysPerMonths; - return this; } public ObsMerSamplingPlan toPlan() { @@ -234,43 +209,30 @@ public class ObsMerSamplingPlanBuilder { // 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; + Map<Date, SamplingPlan.Effort> totalEffortInDaysPerMonths = new TreeMap<>(); for (Date month : months) { - 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); + Collection<SamplingPlan.Effort> totalObservationsForMonth = totalObservationsForMonths.asMap().get(month); + SamplingPlan.Effort totalEffortInObservationsForMonth = SamplingPlan.Effort.sum(totalObservationsForMonth); + totalEffortInObservationsPerMonths.put(month, totalEffortInObservationsForMonth); - if (totalExpectedForMonth != null) { - highTotalExpected += totalExpectedForMonth.toInteger(); - } - if (totalEstimatedForMonth != null) { - highTotalEstimated += totalEstimatedForMonth.toInteger(); - } - if (totalRealForMonth != null) { - highTotalReal += totalRealForMonth.toInteger(); - } + Collection<SamplingPlan.Effort> totalDaysForMonth = totalDaysForMonths.asMap().get(month); + SamplingPlan.Effort totalEffortInDaysForMonth = SamplingPlan.Effort.sum(totalDaysForMonth); + totalEffortInDaysPerMonths.put(month, totalEffortInDaysForMonth); } - SamplingPlan.Effort highTotalEffortInObservations = 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 highTotalEffortInDays = SamplingPlan.Effort.sum(totalEffortInDaysPerMonths.values()); ObsMerSamplingPlan result = new ObsMerSamplingPlan(months, sortedFacades, totalEffortInObservationsPerMonths, + totalEffortInDaysPerMonths, highTotalEffortInObservations, - observationTimesInDaysTotalExpected.toDouble(), - observationTimesInDaysTotalReal.toLong(), - observationTimesInDaysTotalEstimated.toLong(), + highTotalEffortInDays, sampleRowsFilterValues, sampleRowIds); return result; @@ -351,25 +313,22 @@ public class ObsMerSamplingPlanBuilder { this.rows = new ArrayList<>(); } - protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, - SampleRow row, - Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths, - Integer observationTimesInDaysExpected, - Long observationTimesInDaysReal, - Long observationTimesInDaysEstimated, - long sampleRowContactCounts) { + protected void addSampleRow( + Locale locale, + SampleRow row, + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths, + Map<Date, SamplingPlan.Effort> effortInDaysPerMonths, + long sampleRowContactCounts) { ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart rowPart = - new ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart(locale, - effortInObservationsPerMonths, - row, - observationTimesInDaysExpected, - observationTimesInDaysReal, - observationTimesInDaysEstimated, - sampleRowContactCounts); + new ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart( + locale, + row, + effortInObservationsPerMonths, + effortInDaysPerMonths, + sampleRowContactCounts); rows.add(rowPart); - return rowPart; } protected SamplingPlan.SamplingPlanSectorPart toBean() { diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java index 2bd85ab..7884a16 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java @@ -25,7 +25,6 @@ import com.google.common.base.Charsets; import com.google.common.base.Optional; import com.google.common.cache.Cache; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Range; import com.google.common.collect.Sets; import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.SampleRowsFilter; @@ -34,14 +33,11 @@ import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactState; import fr.ifremer.wao.entity.ContactTopiaDao; -import fr.ifremer.wao.entity.SampleMonth; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowTopiaDao; import fr.ifremer.wao.services.AuthenticatedWaoUser; import fr.ifremer.wao.services.service.csv.ObsMerSamplingPlanExportModel; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Export; @@ -121,27 +117,17 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { Date periodTo = WaoUtils.getEndOfMonth(sampleRowsFilter.getPeriodTo()); ContactTopiaDao contactDao = getContactDao(); - for (SampleRow sampleRow : sampleRows) { - // calcul effort plannifie - Integer observationTimesInDaysExpected = - getObservationTimesInDayExpected(periodFrom, - periodTo, - sampleRow); + for (SampleRow sampleRow : sampleRows) { - Pair<Long, Long> realAndEstimated = - getSampleRowObservationTimesInDayRealAndEstimated( - sampleRow.getTopiaId(), periodFrom, periodTo); - Long observationTimesInDaysReal = realAndEstimated.getLeft(); - Long observationTimesInDaysEstimated = realAndEstimated.getRight(); + Collection<Contact> doneObservations = getDoneObservations(sampleRow, periodFrom, periodTo); long sampleRowContactCounts = contactDao.forSampleRowEquals(sampleRow).count(); // ajout de la ligne au build de plan - builder.addSampleRow(sampleRow, - observationTimesInDaysExpected, - observationTimesInDaysReal, - observationTimesInDaysEstimated, + builder.addSampleRow( + sampleRow, + doneObservations, sampleRowContactCounts); } @@ -149,59 +135,18 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { ObsMerSamplingPlan result = builder.toPlan(); return result; - } - - /** - * Récupérer l'effort d'observation en nombre de jours plannifié poru - * le sample row donné pendant la période donnée. - * - * @param periodFrom début de période où rechercher les contacts - * @param periodTo fin de période où rechercher les contacts - * @param sampleRow la ligne à filtrer - * @return l'effort plannifié calculé - */ - protected int getObservationTimesInDayExpected(Date periodFrom, - Date periodTo, - SampleRow sampleRow) { - - Range<Date> period = Range.closed(periodFrom, periodTo); - - int expected; - - // On prend le nombre d'observation prévue pour cette ligne du plan - // c'est à dire la somme des nombres d'observations prévues pour - // chaque mois. - int expectedObservationCount = 0; - for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - Date periodDate = sampleMonth.getPeriodDate(); - if (period.contains(periodDate)) { - expectedObservationCount += sampleMonth.getExpectedTidesValue(); - } - } - // le prévisionnel est égal au nombre d'observations attendues × - // le nombre de jours moyen d'une observation - expected = expectedObservationCount * sampleRow.getAverageTideTime(); - return expected; } /** - * Récupérer l'effort d'observation en nombre de jours réalisé (partie gauche) et estimé (partie droite) - * pour le filtre d'échantillonnage donné. - * - * @param sampleRowId la sample row pour laquelle il faut calculer l'effor réalisé - * @param periodFrom la date à partir de laquelle on compte les contacts - * @param periodTo la date jusqu'à laquelle on compte les contacts - * @return la paire (effort réalisé - effort estimé) calculée + * Permet d'obtenir pour une période donnée toutes les observations réalisées. Cela forme + * une base de travail pour calculer le réalisé en jours de mers */ - protected Pair<Long, Long> getSampleRowObservationTimesInDayRealAndEstimated(String sampleRowId, Date periodFrom, Date periodTo) { - - // D'abord, on a besoin de récupérer toutes les observations réalisées - // pour cette ligne du plan + protected Collection<Contact> getDoneObservations(SampleRow sampleRow, Date periodFrom, Date periodTo) { ContactsFilter contactFilter = new ContactsFilter(); - contactFilter.getSampleRowFilter().setSampleRowIds(ImmutableSet.of(sampleRowId)); + contactFilter.getSampleRowFilter().setSampleRowIds(ImmutableSet.of(sampleRow.getTopiaId())); contactFilter.setFilterOnObservationBeginDate(true); contactFilter.setPeriodFrom(periodFrom); @@ -213,26 +158,10 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { // on exclue les contacts invalidés par la société contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); - Collection<Contact> contacts = getContactDao().forFilter(contactFilter, false).findAll(); - - long real = 0; - long estimated = 0; - - for (Contact contact : contacts) { + List<Contact> contacts = getContactDao().forFilter(contactFilter, false).findAll(); - Integer observationTimeInDays = contact.getObservationTimeInDays(); - - if (observationTimeInDays != null) { - if (BooleanUtils.isTrue(contact.getValidationCompany())) { - // real observation - real += observationTimeInDays; - } - // estimated observation - estimated += observationTimeInDays; - } - } + return contacts; - return Pair.of(real, estimated); } 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 2f35f41..68195b0 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 @@ -126,6 +126,27 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan this.estimated = estimated; } + /** + * Créer un effort calculé à partir de la somme d'autre efforts + */ + public static Effort sum(Iterable<Effort> efforts) { + int expected = 0; + int real = 0; + int estimated = 0; + for (Effort effort : efforts) { + if (effort.getExpected() != null) { + expected += effort.getExpected(); + } + if (effort.getEstimated() != null) { + estimated += effort.getEstimated(); + } + if (effort.getReal() != null) { + real += effort.getReal(); + } + } + return new Effort(expected, real, estimated); + } + public Integer getExpected() { return expected; } @@ -230,8 +251,8 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan } } - public Effort getTotalEffortInObservationsForMonth(Date month) { - return totalEffortInObservationsPerMonths.get(month); + public Map<Date, Effort> getTotalEffortInObservationsPerMonths() { + return totalEffortInObservationsPerMonths; } public Effort getHighTotalEffortInObservations() { @@ -336,7 +357,8 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan long sampleRowContactCounts) { this.effortInObservationsPerMonths = effortInObservationsPerMonths; this.sampleRowContactCounts = sampleRowContactCounts; - // compute total tides + + // pour la ligne, on calcul le total en nombre d'observation int totalTidesExpected = 0; int totalTidesEstimated = 0; int totalTidesReal = 0; @@ -355,6 +377,7 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan } } totalObservations = new Effort(totalTidesExpected, totalTidesReal, totalTidesEstimated); + facade = sampleRow.getFacade(); sectors = sampleRow.getSectors(); fishingZones = ""; @@ -408,6 +431,10 @@ public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlan elligibleBoatsProvided = sampleRow.isElligibleBoatNotEmpty(); } + public Map<Date, Effort> getEffortInObservationsPerMonths() { + return effortInObservationsPerMonths; + } + public String getSampleRowId() { return sampleRowId; } diff --git a/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp b/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp index 4befaa8..61e536c 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp @@ -365,7 +365,7 @@ </td> <!-- Months columns --> <s:iterator value="samplingPlan.months" var="month"> - <s:set var="effort" value="%{getEffortInObservationsForMonth(#month)}"/> + <s:set var="effort" value="#samplingPlanRow.effortInObservationsPerMonths.get(#month)"/> <s:set var="now" value="%{isCurrentMonth(#month)}"/> <s:set var="showPercentage" value="false"/> <%@include file="../templates/td-effort.jsp" %> @@ -376,30 +376,11 @@ <s:set var="showPercentage" value="true"/> <%@include file="../templates/td-effort.jsp" %> - <td class="effort"> - - <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> - <span class="estimated<s:if test="observationTimesInDaysEstimated < observationTimesInDaysExpected"> lower-than-expected</s:if><s:if test="observationTimesInDaysEstimated > observationTimesInDaysExpected"> higher-than-expected</s:if>"> - <s:property value="observationTimesInDaysEstimated" /> <s:text name="wao.ui.misc.day"/> - </span> - <span class="real<s:if test="observationTimesInDaysReal < observationTimesInDaysExpected"> lower-than-expected</s:if><s:if test="observationTimesInDaysReal > observationTimesInDaysExpected"> higher-than-expected</s:if>"> - <s:property value="observationTimesInDaysReal" /> <s:text name="wao.ui.misc.day"/> - </span> - / - </s:if> - - <s:property value="observationTimesInDaysExpected" /> <s:text name="wao.ui.misc.day"/> - - <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> - <span class="estimated<s:if test="observationTimesInDaysEstimated < observationTimesInDaysExpected"> lower-than-expected</s:if><s:if test="observationTimesInDaysEstimated > observationTimesInDaysExpected"> higher-than-expected</s:if>"> - <s:property value="observationTimesInDaysEstimatedPercentage" /> % - </span> - <span class="real<s:if test="observationTimesInDaysReal < observationTimesInDaysExpected"> lower-than-expected</s:if><s:if test="observationTimesInDaysReal > observationTimesInDaysExpected"> higher-than-expected</s:if>"> - <s:property value="observationTimesInDaysRealPercentage" /> % - </span> - </s:if> + <s:set var="effort" value="#samplingPlanRow.totalDays"/> + <s:set var="now" value="false"/> + <s:set var="showPercentage" value="true"/> + <%@include file="../templates/td-effort.jsp" %> - </td> <td class="align-center"><s:property value="averageTideTime" /></td> <td class="align-center"><s:property value="nbObservants" /></td> <td class="align-center"> @@ -507,9 +488,10 @@ <th colspan="<s:property value="#nbColumnsForProfessionInCompactView" />" class="only-in-compact-view"> <s:text name="wao.ui.misc.totals" /> </th> + <!-- Months columns --> <s:iterator value="samplingPlan.months" var="month"> - <s:set var="effort" value="samplingPlan.getTotalEffortInObservationsForMonth(#month)"/> + <s:set var="effort" value="samplingPlan.totalEffortInObservationsPerMonths.get(#month)"/> <s:set var="now" value="%{isCurrentMonth(#month)}"/> <s:set var="showPercentage" value="true"/> <%@include file="../templates/td-effort.jsp" %> @@ -520,31 +502,13 @@ <s:set var="showPercentage" value="true"/> <%@include file="../templates/td-effort.jsp" %> - <td class="effort"> - <s:set var="expected" value="%{samplingPlan.observationTimesInDaysTotalExpected}"/> - <s:set var="estimated" value="%{samplingPlan.observationTimesInDaysTotalEstimated}"/> - <s:set var="real" value="%{samplingPlan.observationTimesInDaysTotalReal}"/> - <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> - <span class="estimated<s:if test="#estimated < #expected"> lower-than-expected</s:if><s:if test="#estimated > #expected"> higher-than-expected</s:if>"> - <s:property value="#estimated"/> <s:text name="wao.ui.misc.day"/> - </span> - <span class="real<s:if test="#real < #expected"> lower-than-expected</s:if><s:if test="#real > #expected"> higher-than-expected</s:if>"> - <s:property value="#real"/> <s:text name="wao.ui.misc.day"/> - </span> - / - </s:if> - <s:property value="#expected"/> <s:text name="wao.ui.misc.day"/> - - <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> - <span class="estimated<s:if test="#estimated < #expected"> lower-than-expected</s:if><s:if test="#estimated > #expected"> higher-than-expected</s:if>"> - <s:property value="samplingPlan.observationTimesInDaysTotalEstimatedRatio * 100" /> % - </span> - <span class="real<s:if test="#real < #expected"> lower-than-expected</s:if><s:if test="#real > #expected"> higher-than-expected</s:if>"> - <s:property value="samplingPlan.observationTimesInDaysTotalRealRatio * 100" /> % - </span> - </s:if> - </td> + <s:set var="effort" value="samplingPlan.highTotalEffortInDays"/> + <s:set var="now" value="false"/> + <s:set var="showPercentage" value="true"/> + <%@include file="../templates/td-effort.jsp" %> + <th colspan="${nbColumnsForOther}"></th> + </tfoot> </table> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm