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 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>.