branch develop updated (a4b5b34 -> 4bf3b56)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository wao. See http://git.codelutin.com/wao.git from a4b5b34 Merge branch 'feature/6452' into develop new 5be88b9 Mise à jour des dépendances new 4bf3b56 On remanie la génération du plan ObsVente pour ne plus lire en base l'estimé et le réalisé. Du coup, tous les programmes n'utilisent plus les champs dénormalisés de la base. The 2 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 4bf3b56fbaf10645699145a8b4c68f0d6d7038fc Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Feb 26 18:02:54 2015 +0100 On remanie la génération du plan ObsVente pour ne plus lire en base l'estimé et le réalisé. Du coup, tous les programmes n'utilisent plus les champs dénormalisés de la base. commit 5be88b9c80d3c5c7d509be80c8cd461540a44aca Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Feb 26 17:01:58 2015 +0100 Mise à jour des dépendances Summary of changes: pom.xml | 12 +- .../java/fr/ifremer/wao/entity/SampleMonths.java | 70 -------- .../java/fr/ifremer/wao/entity/SampleRows.java | 19 --- .../service/ObsVenteSamplingPlanBuilder.java | 178 +++++++++------------ .../service/ObsVenteSamplingPlanService.java | 7 +- 5 files changed, 86 insertions(+), 200 deletions(-) delete mode 100644 wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java -- 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 develop in repository wao. See http://git.codelutin.com/wao.git commit 5be88b9c80d3c5c7d509be80c8cd461540a44aca Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Feb 26 17:01:58 2015 +0100 Mise à jour des dépendances --- pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 1112af8..537a06a 100644 --- a/pom.xml +++ b/pom.xml @@ -111,15 +111,15 @@ <commonsBeanutilsVersion>1.9.2</commonsBeanutilsVersion> <commonsIoVersion>2.4</commonsIoVersion> <h2Version>1.3.176</h2Version> - <struts2Version>2.3.16.3</struts2Version> + <struts2Version>2.3.20</struts2Version> <jqueryPluginVersion>3.7.1</jqueryPluginVersion> <bootstrapPluginVersion>1.7.0</bootstrapPluginVersion> - <slf4jVersion>1.7.9</slf4jVersion> - <hibernateVersion>4.3.7.Final</hibernateVersion> + <slf4jVersion>1.7.10</slf4jVersion> + <hibernateVersion>4.3.8.Final</hibernateVersion> <mockitoVersion>1.10.17</mockitoVersion> - <postgresqlDriverVersion>9.3-1102-jdbc41</postgresqlDriverVersion> + <postgresqlDriverVersion>9.4-1201-jdbc41</postgresqlDriverVersion> <commonsEmailVersion>1.3.3</commonsEmailVersion> - <mustacheVersion>1.9</mustacheVersion> + <mustacheVersion>1.10</mustacheVersion> <commonsCodecVersion>1.10</commonsCodecVersion> <ehCacheVersion>2.6.9</ehCacheVersion> <jFreeChartVersion>1.0.13</jFreeChartVersion> @@ -130,7 +130,7 @@ <nuitonI18nVersion>3.3</nuitonI18nVersion> <nuitonConfigVersion>3.0-rc-2</nuitonConfigVersion> <nuitonCsvVersion>3.0-rc-4</nuitonCsvVersion> - <nuitonValidatorVersion>3.0-rc-2</nuitonValidatorVersion> + <nuitonValidatorVersion>3.0</nuitonValidatorVersion> <nuitonUtilsVersion>3.0-rc-8</nuitonUtilsVersion> <eugeneVersion>2.13</eugeneVersion> <topiaVersion>3.0-beta-15</topiaVersion> -- 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 develop in repository wao. See http://git.codelutin.com/wao.git commit 4bf3b56fbaf10645699145a8b4c68f0d6d7038fc Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Feb 26 18:02:54 2015 +0100 On remanie la génération du plan ObsVente pour ne plus lire en base l'estimé et le réalisé. Du coup, tous les programmes n'utilisent plus les champs dénormalisés de la base. --- .../java/fr/ifremer/wao/entity/SampleMonths.java | 70 -------- .../java/fr/ifremer/wao/entity/SampleRows.java | 19 --- .../service/ObsVenteSamplingPlanBuilder.java | 178 +++++++++------------ .../service/ObsVenteSamplingPlanService.java | 7 +- 4 files changed, 80 insertions(+), 194 deletions(-) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java deleted file mode 100644 index 01fb2ea..0000000 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java +++ /dev/null @@ -1,70 +0,0 @@ -package fr.ifremer.wao.entity; - -/* - * #%L - * Wao :: Persistence - * %% - * Copyright (C) 2009 - 2014 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Created on 4/4/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class SampleMonths { - - - /** Logger. */ - private static final Log log = LogFactory.getLog(SampleMonths.class); - - /** - * Method could be use to add some time for realTidesValue or - * remove time with a negative nbDays. - * If nbDays is negative and superior to the current value, - * the real tides value will be set to 0. - * - * @param nbDays to add or remove (if negative) - */ - public static void addRealTideTime(SampleMonth sampleMonth, int nbDays) { - int result = sampleMonth.getRealTidesValue() + nbDays; - if (result < 0) { - result = 0; - } - if (log.isDebugEnabled()) { - log.debug("Change realTides : " + sampleMonth.getRealTidesValue() + - " -> " + result + " _ date = " + sampleMonth.getPeriodDate()); - } - sampleMonth.setRealTidesValue(result); - } - - public static void addEstimatedTideTime(SampleMonth sampleMonth, int nbDays) { - int result = sampleMonth.getEstimatedTidesValue() + nbDays; - if (result < 0) { - result = 0; - } - if (log.isDebugEnabled()) { - log.debug("Change estimatedTides : " + sampleMonth.getEstimatedTidesValue() + - " -> " + result + " _ date = " + sampleMonth.getPeriodDate()); - } - sampleMonth.setEstimatedTidesValue(result); - } -} diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRows.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRows.java index c7a6054..fdc5e19 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRows.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRows.java @@ -49,23 +49,4 @@ public class SampleRows { return result; } - public static Integer getRealTidesValue(SampleRow sampleRow, Date month) { - Integer result = null; - SampleMonth sampleMonth = sampleRow.getSampleMonth(month); - if (sampleMonth != null) { - int tidesValue = sampleMonth.getRealTidesValue(); - result = tidesValue; - } - return result; - } - - public static Integer getEstimatedTidesValue(SampleRow sampleRow, Date month) { - Integer result = null; - SampleMonth sampleMonth = sampleRow.getSampleMonth(month); - if (sampleMonth != null) { - int tidesValue = sampleMonth.getEstimatedTidesValue(); - result = tidesValue; - } - return result; - } } 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 165ea51..3172a75 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 @@ -22,12 +22,19 @@ package fr.ifremer.wao.services.service; */ import com.google.common.base.Function; +import com.google.common.base.MoreObjects; import com.google.common.base.Optional; +import com.google.common.collect.LinkedListMultimap; +import com.google.common.collect.ListMultimap; +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.BooleanUtils; import org.apache.commons.lang3.mutable.MutableInt; import org.nuiton.util.PeriodDates; @@ -59,7 +66,7 @@ public class ObsVenteSamplingPlanBuilder { /** * 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. @@ -69,67 +76,21 @@ public class ObsVenteSamplingPlanBuilder { /** * Dictionnary of facades indexed by their facade name. */ - protected Map<String, FacadeContext> facadeMap; + protected Map<String, FacadeContext> facadeMap = new TreeMap<>(); - /** - * To compute the high total expected. - * - * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotalEffortInObservations - */ - protected int highTotalExpected; - - /** - * To compute the high total real. - * - * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotalEffortInObservations - */ - protected int highTotalReal; - - /** - * To compute the high total estimated. - * - * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotalEffortInObservations - */ - protected int highTotalEstimated; - - /** - * To compute by month the total of expected tides. - * - * @see fr.ifremer.wao.services.service.SamplingPlan.Effort#expected - */ - protected Map<Date, MutableInt> totalExpectedForMonths; - - /** - * 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(); public ObsVenteSamplingPlanBuilder(Locale locale, Optional<String> optionalCompanyId, SampleRowsFilter sampleRowsFilter) { this.sampleRowsFilter = sampleRowsFilter; this.sampleRowsFilterValues = new SampleRowsFilterValues(locale, ObsProgram.OBSVENTE, optionalCompanyId); - this.sampleRowIds = new HashSet<>(); - this.facadeMap = new TreeMap<>(); - this.totalExpectedForMonths = new TreeMap<>(); - this.totalRealForMonths = new TreeMap<>(); - this.totalEstimatedForMonths = new TreeMap<>(); - PeriodDates periodDates = new PeriodDates(sampleRowsFilter.getPeriodFrom(), sampleRowsFilter.getPeriodTo()); this.months = periodDates.getMonths(); } - public ObsVenteSamplingPlanBuilder addSampleRow(SampleRow sampleRow, long sampleRowContactCounts) { + public ObsVenteSamplingPlanBuilder addSampleRow(SampleRow sampleRow, Collection<Contact> doneObservations, long sampleRowContactCounts) { String facade = sampleRow.getFacade(); FacadeContext facadeContext = facadeMap.get(facade); @@ -146,8 +107,59 @@ public class ObsVenteSamplingPlanBuilder { // get sector context SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); - // compute nb tides per month - Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = getEffortInObservationsPerMonths(sampleRow); + // Pour chaque mois, on indique le nombre de navire observés + Map<Date, MutableInt> estimatedObservationsByMonths = new TreeMap<>(); + Map<Date, MutableInt> realObservationsByMonths = new TreeMap<>(); + + for (Contact doneObservation : doneObservations) { + + Date month = WaoUtils.truncateToMonth(doneObservation.getObservationBeginDate()); + + // si le contact doit être compté dans le réel + if (BooleanUtils.isTrue(doneObservation.getValidationCompany())) { + + // on compte 1 observation + MutableInt real = realObservationsByMonths.get(month); + if (real == null) { + real = new MutableInt(0); + realObservationsByMonths.put(month, real); + } + real.increment(); + } + + // le contact doit être ajouté dans l'estimée (car on ne parcourt pas les contacts refusés) + // on compte 1 observation dans l'estimé + MutableInt estimated = estimatedObservationsByMonths.get(month); + if (estimated == null) { + estimated = new MutableInt(0); + estimatedObservationsByMonths.put(month, estimated); + } + estimated.increment(); + + } + + // calcul de l'effort en nombre d'observations + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = new TreeMap<>(); + + for (Date month : months) { + + // calcul du planifié + Integer expectedObservations = SampleRows.getExpectedTidesValue(sampleRow, month); + + int estimatedObservations = MoreObjects.firstNonNull(estimatedObservationsByMonths.get(month), 0).intValue(); + int realObservations = MoreObjects.firstNonNull(realObservationsByMonths.get(month), 0).intValue(); + + // on a le planifié, l'estimé, le réel en jour et en nombre d'observations, on fait les totaux + + SamplingPlan.Effort effortForMonthInObservations = + new SamplingPlan.Effort(expectedObservations, realObservations, estimatedObservations); + + effortInObservationsPerMonths.put(month, effortForMonthInObservations); + + } + + // ajout dans les totaux par mois + totalObservationsForMonths.putAll(Multimaps.forMap(effortInObservationsPerMonths)); // add sample row sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), @@ -178,70 +190,28 @@ public class ObsVenteSamplingPlanBuilder { } }).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<>(); + for (Date month : months) { - MutableInt totalExpected = totalExpectedForMonths.get(month); - MutableInt totalReal = totalRealForMonths.get(month); - MutableInt totalEstimated = totalEstimatedForMonths.get(month); - SamplingPlan.Effort planStatistics = - new SamplingPlan.Effort(totalExpected == null ? null : totalExpected.toInteger(), - totalReal == null ? null : totalReal.toInteger(), - totalEstimated == null ? null : totalEstimated.toInteger()); - statisticsMap.put(month, planStatistics); + Collection<SamplingPlan.Effort> totalObservationsForMonth = totalObservationsForMonths.asMap().get(month); + SamplingPlan.Effort totalEffortInObservationsForMonth = SamplingPlan.Effort.sum(totalObservationsForMonth); + totalEffortInObservationsPerMonths.put(month, totalEffortInObservationsForMonth); + } - SamplingPlan.Effort highTotals = new SamplingPlan.Effort(highTotalExpected, highTotalReal, highTotalEstimated); + SamplingPlan.Effort highTotalEffortInObservations = SamplingPlan.Effort.sum(totalEffortInObservationsPerMonths.values()); ObsVenteSamplingPlan result = new ObsVenteSamplingPlan(months, sortedFacades, - statisticsMap, - highTotals, + totalEffortInObservationsPerMonths, + highTotalEffortInObservations, sampleRowsFilterValues, sampleRowIds); return result; } - 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); - if (expectedTidesValue != null) { - MutableInt mutableInt = totalExpectedForMonths.get(month); - if (mutableInt == null) { - totalExpectedForMonths.put(month, mutableInt = new MutableInt()); - } - mutableInt.add(expectedTidesValue); - highTotalExpected += expectedTidesValue; - } - 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)); - - } - return result; - } - protected static class FacadeContext { protected String facade; diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java index 829d5cf..98b516b 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java @@ -24,11 +24,13 @@ package fr.ifremer.wao.services.service; import com.google.common.base.Optional; import com.google.common.cache.Cache; import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactTopiaDao; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowTopiaDao; import fr.ifremer.wao.services.AuthenticatedWaoUser; +import java.util.Collection; import java.util.List; public class ObsVenteSamplingPlanService extends SamplingPlanService { @@ -69,12 +71,15 @@ public class ObsVenteSamplingPlanService extends SamplingPlanService { for (SampleRow sampleRow : sampleRows) { + Collection<Contact> doneObservations = getDoneObservations(sampleRow); + long sampleRowContactCounts = contactDao.forSampleRowEquals(sampleRow).count(); // ajout de la ligne au build de plan - builder.addSampleRow(sampleRow, sampleRowContactCounts); + builder.addSampleRow(sampleRow, doneObservations, sampleRowContactCounts); } + result = builder.toPlan(); samplingPlansCache.put(samplingPlanCacheKey.clone(), result); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm