This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 5d6b2f229d296dce252cbd15e0b23804eef48fde Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Dec 26 11:39:06 2014 +0100 Passage du plan scléro en nombre d'individus (totaux manquants) --- .../service/ObsMerSamplingPlanService.java | 27 -------- .../wao/services/service/SamplingPlanService.java | 22 +++++++ .../service/SclerochronologySamplingPlan.java | 9 ++- .../SclerochronologySamplingPlanBuilder.java | 77 ++++++++++++++++++++-- .../SclerochronologySamplingPlanService.java | 6 +- .../SclerochronologySamplingPlanServiceTest.java | 20 ++++++ .../main/resources/i18n/wao-web_en_GB.properties | 1 + .../main/resources/i18n/wao-web_fr_FR.properties | 1 + .../content/sclerochronology/sampling-plan.jsp | 10 +-- 9 files changed, 133 insertions(+), 40 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 8d447f7..474c825 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 @@ -24,13 +24,9 @@ package fr.ifremer.wao.services.service; 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.Sets; -import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.SampleRowsFilter; import fr.ifremer.wao.WaoTechnicalException; import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactState; import fr.ifremer.wao.entity.ContactTopiaDao; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowTopiaDao; @@ -131,29 +127,6 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { } - /** - * 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 Collection<Contact> getDoneObservations(SampleRow sampleRow) { - - ContactsFilter contactFilter = new ContactsFilter(); - - contactFilter.getSampleRowFilter().setSampleRowIds(ImmutableSet.of(sampleRow.getTopiaId())); - - contactFilter.setContactStates(ImmutableSet.of(ContactState.OBSERVATION_DONE)); - // on exclue les contacts qui sont invalidés par le programme - contactFilter.setProgramAcceptations(Sets.newHashSet(true, null)); - // on exclue les contacts invalidés par la société - contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); - - List<Contact> contacts = getContactDao().forFilter(contactFilter, false).findAll(); - - return contacts; - - } - - public InputStream exportSamplingPlanWithStatistics(AuthenticatedWaoUser authenticatedWaoUser, SampleRowsFilter filter) { ObsMerSamplingPlan samplingPlan = getSamplingPlan(authenticatedWaoUser, filter); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java index ce1e214..8c40446 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java @@ -823,4 +823,26 @@ public class SamplingPlanService extends WaoServiceSupport { } } + + /** + * 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 Collection<Contact> getDoneObservations(SampleRow sampleRow) { + + ContactsFilter contactFilter = new ContactsFilter(); + + contactFilter.getSampleRowFilter().setSampleRowIds(ImmutableSet.of(sampleRow.getTopiaId())); + + contactFilter.setContactStates(ImmutableSet.of(ContactState.OBSERVATION_DONE)); + // on exclue les contacts qui sont invalidés par le programme + contactFilter.setProgramAcceptations(Sets.newHashSet(true, null)); + // on exclue les contacts invalidés par la société + contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); + + List<Contact> contacts = getContactDao().forFilter(contactFilter, false).findAll(); + + return contacts; + + } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java index 9fccaff..28dc7ec 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java @@ -50,8 +50,11 @@ public class SclerochronologySamplingPlan extends SamplingPlan implements Iterab protected String species; - public SclerochronologySamplingPlanSampleRowPart(Locale locale, Map<Date, Effort> effortInObservationsPerMonths, SampleRow sampleRow, long sampleRowContactCounts) { + protected Map<Date, Effort> effortInIndividualsPerMonths; + + public SclerochronologySamplingPlanSampleRowPart(Locale locale, Map<Date, Effort> effortInObservationsPerMonths, Map<Date, Effort> effortInIndividualsPerMonths, SampleRow sampleRow, long sampleRowContactCounts) { super(locale, effortInObservationsPerMonths, sampleRow, sampleRowContactCounts); + this.effortInIndividualsPerMonths = effortInIndividualsPerMonths; species = sampleRow.getSpecies().getVernacularName(); samplingContext = WaoUtils.l(locale, sampleRow.getSclerochronologySamplingContext()); samplingContextInfo = sampleRow.getSclerochronologySamplingContextInfo(); @@ -79,6 +82,10 @@ public class SclerochronologySamplingPlan extends SamplingPlan implements Iterab return samplingContext; } + public Map<Date, Effort> getEffortInIndividualsPerMonths() { + return effortInIndividualsPerMonths; + } + @Override public Map<String, String> getDcf5CodesAndDescriptions() { throw new UnsupportedOperationException("not in " + ObsProgram.SCLEROCHRONOLOGY); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java index aed9964..0c97760 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java @@ -23,15 +23,21 @@ 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.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.apache.commons.lang3.time.DateUtils; import org.nuiton.util.PeriodDates; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashSet; @@ -129,7 +135,7 @@ public class SclerochronologySamplingPlanBuilder { this.months = periodDates.getMonths(); } - public SclerochronologySamplingPlanBuilder addSampleRow(SampleRow sampleRow, long sampleRowContactCounts) { + public SclerochronologySamplingPlanBuilder addSampleRow(SampleRow sampleRow, Collection<Contact> doneObservations, long sampleRowContactCounts) { String facade = sampleRow.getFacade(); FacadeContext facadeContext = facadeMap.get(facade); @@ -146,13 +152,15 @@ public class SclerochronologySamplingPlanBuilder { // get sector context SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); - // compute nb tides per month + // calcul de l'effort en nombre d'observations puis en nombre d'individus Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths = getEffortInObservationsPerMonths(sampleRow); + Map<Date, SamplingPlan.Effort> effortInIndividualsPerMonths = getEffortInIndividualsPerMonths(sampleRow, doneObservations); // add sample row sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), sampleRow, effortInObservationsPerMonths, + effortInIndividualsPerMonths, sampleRowContactCounts); sampleRowsFilterValues.addSampleRow(sampleRow); @@ -242,6 +250,60 @@ public class SclerochronologySamplingPlanBuilder { return result; } + protected Map<Date, SamplingPlan.Effort> getEffortInIndividualsPerMonths(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> estimatedSampledIndividualsByMonths = LinkedListMultimap.create(); + LinkedListMultimap<Date, Integer> realSampledIndividualsByMonths = LinkedListMultimap.create(); + + for (Contact doneObservation : doneObservations) { + + // on prend l'observation, on regarde combien de jour ça ajoute à chaque mois + Date month = DateUtils.truncate(doneObservation.getObservationBeginDate(), Calendar.MONTH); + + if (BooleanUtils.isTrue(doneObservation.getValidationCompany())) { + realSampledIndividualsByMonths.put(month, doneObservation.getSampleSize()); + } + + estimatedSampledIndividualsByMonths.put(month, doneObservation.getSampleSize()); + + } + + Map<Date, SamplingPlan.Effort> effortInIndividualsPerMonths = new TreeMap<>(); + + for (Date month : months) { + + // calcul du plannifié + Integer expected = null; + Integer expectedObservations = SampleRows.getExpectedTidesValue(sampleRow, month); + if (expectedObservations != null) { + expected = expectedObservations; + } + + // calcul de l'estimé et du réel + Collection<Integer> estimatedDoneObservationDays = estimatedSampledIndividualsByMonths.asMap().get(month); + Integer estimated = 0; // car estimatedDoneObservationDays peut être null si aucune observation sur le mois + if (estimatedDoneObservationDays != null) { + estimated = WaoUtils.sum(estimatedDoneObservationDays); + } + + Collection<Integer> realDoneObservationDays = realSampledIndividualsByMonths.asMap().get(month); + Integer real = 0; // car realDoneObservationDays peut être null si aucune observation sur le mois + if (realDoneObservationDays != null) { + real = WaoUtils.sum(realDoneObservationDays); + } + + SamplingPlan.Effort effortForMonth = new SamplingPlan.Effort(expected, real, estimated); + effortInIndividualsPerMonths.put(month, effortForMonth); + + } + + return effortInIndividualsPerMonths; + + } + protected static class FacadeContext { protected String facade; @@ -295,15 +357,18 @@ public class SclerochronologySamplingPlanBuilder { this.rows = new ArrayList<>(); } - protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, - SampleRow row, - Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths, - long sampleRowContactCounts) { + protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow( + Locale locale, + SampleRow row, + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths, + Map<Date, SamplingPlan.Effort> effortInIndividualsPerMonths, + long sampleRowContactCounts) { SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart rowPart = new SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart( locale, effortInObservationsPerMonths, + effortInIndividualsPerMonths, row, sampleRowContactCounts); rows.add(rowPart); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java index f0cd05f..22666bb 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.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 SclerochronologySamplingPlanService extends SamplingPlanService { @@ -69,10 +71,12 @@ public class SclerochronologySamplingPlanService 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); } diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java index b1b0c0b..5aa1aeb 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java @@ -132,4 +132,24 @@ public class SclerochronologySamplingPlanServiceTest extends AbstractWaoServiceT Assert.assertTrue(sampleRowLog.getLogText().contains("Merlu")); } + + @Test + public void testContactsShowsInSamplingPlan() { + fixtures.contacts(); + AuthenticatedWaoUser admin = fixtures.admin(); + SampleRowsFilter filter = service.newSampleRowsFilter(admin); + SclerochronologySamplingPlan samplingPlan = service.getSamplingPlan(admin, filter); + + for (SamplingPlan.SamplingPlanFacadePart facade : samplingPlan) { + for (SamplingPlan.SamplingPlanSectorPart<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart> sector : facade) { + for (SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart row : sector) { + if (row.getCode().equals("2015_S0001")) { + SamplingPlan.Effort effortInIndividualsForJanuary = Iterables.get(row.getEffortInIndividualsPerMonths().values(), 0); + Assert.assertEquals(53, effortInIndividualsForJanuary.getEstimated().intValue()); + Assert.assertEquals(53, effortInIndividualsForJanuary.getReal().intValue()); + } + } + } + } + } } \ No newline at end of file diff --git a/wao-web/src/main/resources/i18n/wao-web_en_GB.properties b/wao-web/src/main/resources/i18n/wao-web_en_GB.properties index 5e9770e..d6f16a6 100644 --- a/wao-web/src/main/resources/i18n/wao-web_en_GB.properties +++ b/wao-web/src/main/resources/i18n/wao-web_en_GB.properties @@ -533,6 +533,7 @@ wao.ui.samplingPlan.averageObservationsCount=Number of observations wao.ui.samplingPlan.averageTideTime=Average tide time (d.) wao.ui.samplingPlan.effort=Observation effort wao.ui.samplingPlan.effort.obsVente=Observation effort +wao.ui.samplingPlan.effort.sclerochronology=Observation effort in number of individuals wao.ui.samplingPlan.effort.tip=There is a difference between "0" as effort and leave it empty. O means that no effort is asked to the observers but they can still create contacts for this month. Leaving the field empty makes impossible for the observers to create contacts for this months. wao.ui.samplingPlan.estimated=estimated wao.ui.samplingPlan.expected=expected diff --git a/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties b/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties index 28c8e87..01f930b 100644 --- a/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties +++ b/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties @@ -534,6 +534,7 @@ wao.ui.samplingPlan.averageObservationsCount=Nombre d'observations wao.ui.samplingPlan.averageTideTime=Durée moyenne d'une marée (J.) wao.ui.samplingPlan.effort=Effort d'observation en nombre de marées wao.ui.samplingPlan.effort.obsVente=Effort d'observation en nombre de sorties +wao.ui.samplingPlan.effort.sclerochronology=Effort d'observation en nombre d'individus wao.ui.samplingPlan.effort.tip=Il y a une différence entre saisir « 0 » comme effort mensuel et laisser la case vide. Si vous indiquez un effort de 0, aucun effort n'est demandé aux observateurs mais ils pourront tout de même saisir un contact. Si vous laissez la case vide, les observateurs ne pourront pas créer de contacts pour ce mois. wao.ui.samplingPlan.estimated=estimé wao.ui.samplingPlan.expected=planifié diff --git a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp index 0082bc8..3ae34b5 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp @@ -203,7 +203,7 @@ <s:text name="wao.ui.samplingPlan.sampledProfessions" /> </th> <th colspan="${nbColumnsForMonths}"> - <s:text name="wao.ui.samplingPlan.effort" /> + <s:text name="wao.ui.samplingPlan.effort.sclerochronology" /> <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> [ @@ -322,13 +322,13 @@ <td class="only-in-full-view"><s:property value="%{formatMonth(periodEnd)}" /></td> <!-- Months columns --> <s:iterator value="samplingPlan.months" var="month"> - <s:set var="effort" value="#samplingPlanRow.effortInObservationsPerMonths.get(#month)"/> + <s:set var="effort" value="#samplingPlanRow.effortInIndividualsPerMonths.get(#month)"/> <s:set var="now" value="%{isCurrentMonth(#month)}"/> <s:set var="showPercentage" value="false"/> <%@include file="../templates/td-effort.jsp" %> </s:iterator> - <s:set var="effort" value="#samplingPlanRow.totalObservations"/> + <s:set var="effort" value="#samplingPlanRow.totalIndividuals"/> <s:set var="now" value="false"/> <s:set var="showPercentage" value="true"/> <%@include file="../templates/td-effort.jsp" %> @@ -425,13 +425,13 @@ </th> <!-- Months columns --> <s:iterator value="samplingPlan.months" var="month"> - <s:set var="effort" value="samplingPlan.totalEffortInObservationsPerMonths.get(#month)"/> + <s:set var="effort" value="samplingPlan.totalEffortInIndividualsPerMonths.get(#month)"/> <s:set var="now" value="%{isCurrentMonth(#month)}"/> <s:set var="showPercentage" value="true"/> <%@include file="../templates/td-effort.jsp" %> </s:iterator> - <s:set var="effort" value="samplingPlan.highTotalEffortInObservations"/> + <s:set var="effort" value="samplingPlan.highTotalEffortInIndividuals"/> <s:set var="now" value="false"/> <s:set var="showPercentage" value="true"/> <%@include file="../templates/td-effort.jsp" %> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.