[wao] branch feature/5651 updated (6cc3269 -> 92dc9de)
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 6cc3269 Remaniement dans le plan d'échantillonage : introduction d'une classe Effort et d'un template td-effort qu'on peut utiliser pour toutes les cellules .effort new fc64342 Extraction dans WaoUtils de l'algorithme qui détermine le nombre de jour d'une marée ObsMer et ajout d'un algo pour calculer le nombre de jour de mer pour chaque mois (refs #5661) new 92dc9de Dans ObsMerSamplingPlanService, on sépare les préoccupations entre calcul de la clé du cache, lecture du cache et calcul du plan 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 92dc9de394e2e65d86acf5fc4f04e9515ba2e27b Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Oct 9 18:29:52 2014 +0200 Dans ObsMerSamplingPlanService, on sépare les préoccupations entre calcul de la clé du cache, lecture du cache et calcul du plan commit fc6434219b26458dbf43ecca3bdb043e0143e9be Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Oct 9 17:26:24 2014 +0200 Extraction dans WaoUtils de l'algorithme qui détermine le nombre de jour d'une marée ObsMer et ajout d'un algo pour calculer le nombre de jour de mer pour chaque mois (refs #5661) Summary of changes: .../src/main/java/fr/ifremer/wao/WaoUtils.java | 49 ++++++++++ .../java/fr/ifremer/wao/entity/ContactImpl.java | 9 +- .../src/test/java/fr/ifremer/wao/WaoUtilsTest.java | 46 ++++++++++ .../fr/ifremer/wao/entity/ContactImplTest.java | 52 ----------- .../service/ObsMerSamplingPlanService.java | 100 ++++++++++++--------- .../wao/services/service/SamplingPlanCacheKey.java | 12 +++ 6 files changed, 167 insertions(+), 101 deletions(-) delete mode 100644 wao-persistence/src/test/java/fr/ifremer/wao/entity/ContactImplTest.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 feature/5651 in repository wao. See http://git.codelutin.com/wao.git commit fc6434219b26458dbf43ecca3bdb043e0143e9be Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Oct 9 17:26:24 2014 +0200 Extraction dans WaoUtils de l'algorithme qui détermine le nombre de jour d'une marée ObsMer et ajout d'un algo pour calculer le nombre de jour de mer pour chaque mois (refs #5661) --- .../src/main/java/fr/ifremer/wao/WaoUtils.java | 49 ++++++++++++++++++++ .../java/fr/ifremer/wao/entity/ContactImpl.java | 9 +--- .../src/test/java/fr/ifremer/wao/WaoUtilsTest.java | 46 +++++++++++++++++++ .../fr/ifremer/wao/entity/ContactImplTest.java | 52 ---------------------- 4 files changed, 97 insertions(+), 59 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 e644631..be5c664 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java @@ -21,8 +21,10 @@ package fr.ifremer.wao; * #L% */ +import com.google.common.base.Verify; import fr.ifremer.wao.entity.I18nAble; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.time.DateUtils; import org.nuiton.i18n.I18n; import org.nuiton.util.DateUtil; @@ -30,11 +32,15 @@ import org.nuiton.util.DateUtil; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Collection; import java.util.Date; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Locale; +import java.util.Map; +import java.util.TreeMap; public class WaoUtils { @@ -187,4 +193,47 @@ public class WaoUtils { public static boolean isAfterWaoCreation(Date date) { return WAO_CREATION_DATE.before(date); } + + /** + * Il s'agit de la façon de calculer la durée de mer d'un voyage en mer (observation + * ObsMer). Il s'agit d'une durée en jour toutefois, il ne s'agit pas de 1 jour = 24 heures + * mais du nombre de fois où minuit a été passé en mer. À partir du moment où il y a eu + * embarquement, on compte au moins un jour de mer. + * + * @param observationBeginDate date d'embarquement + * @param observationEndDate date de retour + * @return la durée du voyage en jour de mer + */ + public static int getObservationTimeInDays(Date observationBeginDate, Date observationEndDate) { + int observationTimeInDays = DateUtil.getDifferenceInDays( + DateUtils.truncate(observationBeginDate, Calendar.DAY_OF_MONTH), + DateUtils.truncate(observationEndDate, Calendar.DAY_OF_MONTH)) + 1; + Verify.verify(observationTimeInDays > 0); + return observationTimeInDays; + } + + /** + * Étant donné une date d'embarquement et une date de débarquement, pour chaque mois, le + * nombre de jour passé en mer au sens de {@link #getObservationTimeInDays(java.util.Date, java.util.Date)} + */ + public static Map<Date, Integer> getObservationDaysByMonths(Date observationBeginDate, Date observationEndDate) { + Map<Date, MutableInt> tempResult = new HashMap<>(); + Date aDay = DateUtils.truncate(observationBeginDate, Calendar.DAY_OF_MONTH); + do { + Date month = DateUtils.truncate(aDay, Calendar.MONTH); + MutableInt count = tempResult.get(month); + if (count == null) { + count = new MutableInt(); + tempResult.put(month, count); + } + count.increment(); + aDay = DateUtils.addDays(aDay, 1); + } while (aDay.before(observationEndDate)); + Map<Date, Integer> result = new TreeMap<>(); + for (Map.Entry<Date, MutableInt> entry : tempResult.entrySet()) { + result.put(entry.getKey(), entry.getValue().intValue()); + } + return result; + } + } diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactImpl.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactImpl.java index 54eb1ea..0b526e5 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactImpl.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactImpl.java @@ -24,12 +24,10 @@ package fr.ifremer.wao.entity; +import fr.ifremer.wao.WaoUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateUtils; -import org.nuiton.util.DateUtil; -import java.util.Calendar; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -157,10 +155,7 @@ public class ContactImpl extends ContactAbstract { public Integer getObservationTimeInDays() { Integer observationTimeInDays = null; if (getObservationBeginDate() != null && getObservationEndDate() != null) { - // +1 car demandé par le métier - observationTimeInDays = DateUtil.getDifferenceInDays( - DateUtils.truncate(getObservationBeginDate(), Calendar.DAY_OF_MONTH), - DateUtils.truncate(getObservationEndDate(), Calendar.DAY_OF_MONTH)) + 1; + observationTimeInDays = WaoUtils.getObservationTimeInDays(getObservationBeginDate(), getObservationEndDate()); } return observationTimeInDays; } diff --git a/wao-persistence/src/test/java/fr/ifremer/wao/WaoUtilsTest.java b/wao-persistence/src/test/java/fr/ifremer/wao/WaoUtilsTest.java index 3e44827..43f01f0 100644 --- a/wao-persistence/src/test/java/fr/ifremer/wao/WaoUtilsTest.java +++ b/wao-persistence/src/test/java/fr/ifremer/wao/WaoUtilsTest.java @@ -25,9 +25,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; import org.junit.Test; +import org.nuiton.util.DateUtil; import java.text.ParseException; +import java.util.Date; import java.util.Locale; +import java.util.Map; public class WaoUtilsTest { @@ -52,4 +55,47 @@ public class WaoUtilsTest { } } + + @Test + public void testGetObservationTimeInDays() { + + Assert.assertEquals(1, WaoUtils.getObservationTimeInDays(DateUtil.createDate(0, 0, 8, 19, 5, 2014), DateUtil.createDate(0, 0, 18, 19, 5, 2014))); + Assert.assertEquals(2, WaoUtils.getObservationTimeInDays(DateUtil.createDate(0, 0, 18, 19, 5, 2014), DateUtil.createDate(0, 0, 6, 20, 5, 2014))); + Assert.assertEquals(2, WaoUtils.getObservationTimeInDays(DateUtil.createDate(0, 0, 1, 19, 5, 2014), DateUtil.createDate(0, 0, 23, 20, 5, 2014))); + Assert.assertEquals(2, WaoUtils.getObservationTimeInDays(DateUtil.createDate(0, 0, 12, 31, 1, 2014), DateUtil.createDate(0, 0, 23, 1, 2, 2014))); + + } + + @Test + public void testGetObservationDaysByMonths() { + + checkObservationTimeInDays(DateUtil.createDate(0, 0, 8, 19, 5, 2014), DateUtil.createDate(0, 0, 18, 19, 5, 2014), 1); + checkObservationTimeInDays(DateUtil.createDate(0, 0, 18, 19, 5, 2014), DateUtil.createDate(0, 0, 6, 20, 5, 2014), 1); + checkObservationTimeInDays(DateUtil.createDate(0, 0, 1, 19, 5, 2014), DateUtil.createDate(0, 0, 23, 20, 5, 2014), 1); + checkObservationTimeInDays(DateUtil.createDate(0, 0, 12, 31, 1, 2014), DateUtil.createDate(0, 0, 23, 1, 2, 2014), 2); + + } + + protected void checkObservationTimeInDays(Date observationBeginDate, Date observationEndDate, int expectedSize) { + + Map<Date, Integer> observationDaysByMonths = WaoUtils.getObservationDaysByMonths(observationBeginDate, observationEndDate); + + Assert.assertEquals( + "La répartition aurait dû se faire sur " + expectedSize + " mois et non " + observationDaysByMonths, + expectedSize, observationDaysByMonths.size()); + + int expectedObservationTimeInDays = WaoUtils.getObservationTimeInDays(observationBeginDate, observationEndDate); + int actualObservationTimeInDays = 0; + for (Integer monthValue : observationDaysByMonths.values()) { + actualObservationTimeInDays += monthValue; + } + + Assert.assertEquals( + "Il faut répartir " + expectedObservationTimeInDays + " sur les différents mois et non " + actualObservationTimeInDays + ": " + observationDaysByMonths, + expectedObservationTimeInDays, + actualObservationTimeInDays + ); + + } + } \ No newline at end of file diff --git a/wao-persistence/src/test/java/fr/ifremer/wao/entity/ContactImplTest.java b/wao-persistence/src/test/java/fr/ifremer/wao/entity/ContactImplTest.java deleted file mode 100644 index c79f945..0000000 --- a/wao-persistence/src/test/java/fr/ifremer/wao/entity/ContactImplTest.java +++ /dev/null @@ -1,52 +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.junit.Assert; -import org.junit.Test; -import org.nuiton.util.DateUtil; - -import java.util.Date; - -public class ContactImplTest { - - @Test - public void testGetObservationTimeInDays() { - - checkObservationTimeInDays(DateUtil.createDate(0, 0, 8, 19, 05, 2014), DateUtil.createDate(0, 0, 18, 19, 05, 2014), 1); - checkObservationTimeInDays(DateUtil.createDate(0, 0, 18, 19, 05, 2014), DateUtil.createDate(0, 0, 6, 20, 05, 2014), 2); - checkObservationTimeInDays(DateUtil.createDate(0, 0, 1, 19, 05, 2014), DateUtil.createDate(0, 0, 23, 20, 05, 2014), 2); - - } - - public void checkObservationTimeInDays(Date observationBeginDate, Date observationEndDate, int expectedObservationTimeInDays) { - - ContactImpl contact = new ContactImpl(); - contact.setObservationBeginDate(observationBeginDate); - contact.setObservationEndDate(observationEndDate); - - Integer actualObservationTimeInDays = contact.getObservationTimeInDays(); - Assert.assertEquals((Integer) expectedObservationTimeInDays, actualObservationTimeInDays); - - } - -} \ No newline at end of file -- 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 92dc9de394e2e65d86acf5fc4f04e9515ba2e27b Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Oct 9 18:29:52 2014 +0200 Dans ObsMerSamplingPlanService, on sépare les préoccupations entre calcul de la clé du cache, lecture du cache et calcul du plan --- .../service/ObsMerSamplingPlanService.java | 100 ++++++++++++--------- .../wao/services/service/SamplingPlanCacheKey.java | 12 +++ 2 files changed, 70 insertions(+), 42 deletions(-) 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 ff1fd94..2bd85ab 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 @@ -63,6 +63,7 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { SampleRowsFilter sampleRowsFilter) { Locale locale = serviceContext.getLocale(); + if (log.isDebugEnabled()) { log.debug("a sampling plan with locale " + locale + " is asked"); } @@ -78,6 +79,14 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { optionalCompanyId, sampleRowsFilter); + ObsMerSamplingPlan result = getSamplingPlan(samplingPlanCacheKey); + + return result; + + } + + protected ObsMerSamplingPlan getSamplingPlan(SamplingPlanCacheKey samplingPlanCacheKey) { + Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache = serviceContext.getSamplingPlansCache(); @@ -85,54 +94,61 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { if (result == null) { - SampleRowTopiaDao dao = getSampleRowDao(); - ContactTopiaDao contactDao = getContactDao(); - - // recuperation des lignes du plan - List<SampleRow> sampleRows = dao.findAll(sampleRowsFilter); - - // creation du plan d'echantillonnage - ObsMerSamplingPlanBuilder builder = new ObsMerSamplingPlanBuilder( - locale, - optionalCompanyId, - sampleRowsFilter); - - // begin of month - Date periodFrom = sampleRowsFilter.getPeriodFrom(); - // end of month - Date periodTo = WaoUtils.getEndOfMonth(sampleRowsFilter.getPeriodTo()); - - for (SampleRow sampleRow : sampleRows) { - - // calcul effort plannifie - Integer observationTimesInDaysExpected = - getObservationTimesInDayExpected(periodFrom, - periodTo, - sampleRow); - - Pair<Long, Long> realAndEstimated = - getSampleRowObservationTimesInDayRealAndEstimated( - sampleRow.getTopiaId(), periodFrom, periodTo); - Long observationTimesInDaysReal = realAndEstimated.getLeft(); - Long observationTimesInDaysEstimated = realAndEstimated.getRight(); - - long sampleRowContactCounts = contactDao.forSampleRowEquals(sampleRow).count(); - - // ajout de la ligne au build de plan - builder.addSampleRow(sampleRow, - observationTimesInDaysExpected, - observationTimesInDaysReal, - observationTimesInDaysEstimated, - sampleRowContactCounts); - } - result = builder.toPlan(); + result = computeSamplingPlan(samplingPlanCacheKey); samplingPlansCache.put(samplingPlanCacheKey.clone(), result); } - return result; + } + + protected ObsMerSamplingPlan computeSamplingPlan(SamplingPlanCacheKey samplingPlanCacheKey) { + + SampleRowsFilter sampleRowsFilter = samplingPlanCacheKey.getSampleRowsFilter(); + SampleRowTopiaDao dao = getSampleRowDao(); + List<SampleRow> sampleRows = dao.findAll(sampleRowsFilter); + + // creation du plan d'echantillonnage + ObsMerSamplingPlanBuilder builder = new ObsMerSamplingPlanBuilder( + samplingPlanCacheKey.getLocale(), + samplingPlanCacheKey.getOptionalCompanyId(), + sampleRowsFilter); + + // begin of month + Date periodFrom = sampleRowsFilter.getPeriodFrom(); + // end of month + Date periodTo = WaoUtils.getEndOfMonth(sampleRowsFilter.getPeriodTo()); + + ContactTopiaDao contactDao = getContactDao(); + for (SampleRow sampleRow : sampleRows) { + + // calcul effort plannifie + Integer observationTimesInDaysExpected = + getObservationTimesInDayExpected(periodFrom, + periodTo, + sampleRow); + + Pair<Long, Long> realAndEstimated = + getSampleRowObservationTimesInDayRealAndEstimated( + sampleRow.getTopiaId(), periodFrom, periodTo); + Long observationTimesInDaysReal = realAndEstimated.getLeft(); + Long observationTimesInDaysEstimated = realAndEstimated.getRight(); + + long sampleRowContactCounts = contactDao.forSampleRowEquals(sampleRow).count(); + + // ajout de la ligne au build de plan + builder.addSampleRow(sampleRow, + observationTimesInDaysExpected, + observationTimesInDaysReal, + observationTimesInDaysEstimated, + sampleRowContactCounts); + + } + + ObsMerSamplingPlan result = builder.toPlan(); + + return result; } /** diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanCacheKey.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanCacheKey.java index 085dd66..de55ec5 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanCacheKey.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanCacheKey.java @@ -41,6 +41,18 @@ public class SamplingPlanCacheKey implements WaoCacheKey { this.sampleRowsFilter = sampleRowsFilter; } + public Locale getLocale() { + return locale; + } + + public Optional<String> getOptionalCompanyId() { + return optionalCompanyId; + } + + public SampleRowsFilter getSampleRowsFilter() { + return sampleRowsFilter; + } + @Override public boolean equals(Object o) { if (this == o) return true; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm