branch feature/6910-obsVente-effort created (now 2b97239)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6910-obsVente-effort in repository wao. See http://git.codelutin.com/wao.git at 2b97239 refs #6910 modification du calcul de l'effort, dans l'onglet synthèse This branch includes the following new commits: new dbf2509 refs #6910 modification du calcul de l'effort, calculé pour le nombre sortie et non plus par le nombre de contactes new 2b97239 refs #6910 modification du calcul de l'effort, dans l'onglet synthèse 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 2b9723925323093219afbf019b295c2a1560a54b Author: dcosse <cosse@codelutin.com> Date: Thu Apr 9 15:40:51 2015 +0200 refs #6910 modification du calcul de l'effort, dans l'onglet synthèse commit dbf250972037a5b899e2ba3eafd0a860db53e51e Author: dcosse <cosse@codelutin.com> Date: Thu Apr 9 15:22:11 2015 +0200 refs #6910 modification du calcul de l'effort, calculé pour le nombre sortie et non plus par le nombre de contactes -- 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/6910-obsVente-effort in repository wao. See http://git.codelutin.com/wao.git commit dbf250972037a5b899e2ba3eafd0a860db53e51e Author: dcosse <cosse@codelutin.com> Date: Thu Apr 9 15:22:11 2015 +0200 refs #6910 modification du calcul de l'effort, calculé pour le nombre sortie et non plus par le nombre de contactes --- .../service/ObsVenteSamplingPlanBuilder.java | 40 ++++++++++++++++------ .../WEB-INF/content/edit-sample-row-input.jsp | 8 ++++- .../WEB-INF/content/obsvente/sampling-plan.jsp | 2 +- 3 files changed, 38 insertions(+), 12 deletions(-) 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 3172a75..e06caed 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 @@ -34,8 +34,10 @@ 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.collections4.map.MultiKeyMap; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.commons.lang3.tuple.Pair; import org.nuiton.util.PeriodDates; import java.util.ArrayList; @@ -111,30 +113,39 @@ public class ObsVenteSamplingPlanBuilder { Map<Date, MutableInt> estimatedObservationsByMonths = new TreeMap<>(); Map<Date, MutableInt> realObservationsByMonths = new TreeMap<>(); + // un sortie correspondre à n couples début/fin d'observation + MultiKeyMap<Object, Pair<Date, Date>> nbRealObservationsByTripForMonth = new MultiKeyMap<>(); + MultiKeyMap<Object, Pair<Date, Date>> nbEstimatedObservationsByTrip = new MultiKeyMap<>(); + + for (Contact doneObservation : doneObservations) { Date month = WaoUtils.truncateToMonth(doneObservation.getObservationBeginDate()); + Date obsBeginDate = doneObservation.getObservationBeginDate(); + Date obsEndDate = doneObservation.getObservationEndDate(); // si le contact doit être compté dans le réel if (BooleanUtils.isTrue(doneObservation.getValidationCompany())) { - // on compte 1 observation - MutableInt real = realObservationsByMonths.get(month); + Pair<Date, Date> real = nbRealObservationsByTripForMonth.get(obsBeginDate, obsEndDate); if (real == null) { - real = new MutableInt(0); - realObservationsByMonths.put(month, real); + // on ajoute 1 observation + Pair<Date, Date> obs = Pair.of(obsBeginDate, obsEndDate); + nbRealObservationsByTripForMonth.put(obsBeginDate, obsEndDate, obs); + + increaseOutput(realObservationsByMonths, month); } - 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); + Pair<Date, Date> estimated = nbEstimatedObservationsByTrip.get(obsBeginDate, obsEndDate); if (estimated == null) { - estimated = new MutableInt(0); - estimatedObservationsByMonths.put(month, estimated); + // on ajoute 1 observation dans l'estimé + Pair<Date, Date> obs = Pair.of(obsBeginDate, obsEndDate); + nbEstimatedObservationsByTrip.put(obsBeginDate, obsEndDate, obs); + + increaseOutput(estimatedObservationsByMonths, month); } - estimated.increment(); } @@ -174,6 +185,15 @@ public class ObsVenteSamplingPlanBuilder { return this; } + protected void increaseOutput(Map<Date, MutableInt> realObservationsByMonths, Date month) { + MutableInt obsForMonth = realObservationsByMonths.get(month); + if (obsForMonth == null) { + obsForMonth = new MutableInt(0); + realObservationsByMonths.put(month, obsForMonth); + } + obsForMonth.increment(); + } + public ObsVenteSamplingPlan toPlan() { // Get facade parts diff --git a/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp b/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp index c8740f1..38059e8 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp @@ -233,7 +233,13 @@ <div class="control-group"> - <label class="control-label"><s:text name="wao.ui.samplingPlan.effort" /></label> + <s:if test="updateSampleRowCommand.sampleRow.obsProgram.obsVente"> + <label class="control-label"><s:text name="wao.ui.samplingPlan.effort.obsVente" /></label> + </s:if> + <s:else> + <label class="control-label"><s:text name="wao.ui.samplingPlan.effort" /></label> + </s:else> + <div class="controls"> <table id="expectedObservationsByMonthsTable"> <thead> diff --git a/wao-web/src/main/webapp/WEB-INF/content/obsvente/sampling-plan.jsp b/wao-web/src/main/webapp/WEB-INF/content/obsvente/sampling-plan.jsp index ca82536..9bcd581 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/obsvente/sampling-plan.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/obsvente/sampling-plan.jsp @@ -208,7 +208,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.obsVente" /> <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> [ -- 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/6910-obsVente-effort in repository wao. See http://git.codelutin.com/wao.git commit 2b9723925323093219afbf019b295c2a1560a54b Author: dcosse <cosse@codelutin.com> Date: Thu Apr 9 15:40:51 2015 +0200 refs #6910 modification du calcul de l'effort, dans l'onglet synthèse --- .../wao/services/service/SynthesisService.java | 129 +++++++++++++++++++-- .../resources/i18n/wao-services_en_GB.properties | 1 + .../resources/i18n/wao-services_fr_FR.properties | 1 + 3 files changed, 123 insertions(+), 8 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java index e48744b..1949f1b 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java @@ -44,6 +44,8 @@ import fr.ifremer.wao.entity.SampleMonth; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SynthesisId; import fr.ifremer.wao.services.AuthenticatedWaoUser; +import org.apache.commons.collections4.map.MultiKeyMap; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.Range; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; @@ -517,7 +519,7 @@ public class SynthesisService extends WaoServiceSupport { } public JFreeChart getChart() { - + // super // définition de la fenêtre Date periodFromMonth = truncateToTimePeriod(periodFrom); Date periodToMonth = truncateToTimePeriod(periodTo); @@ -622,6 +624,8 @@ public class SynthesisService extends WaoServiceSupport { protected abstract String formatPeriod(Date period); + + /** * Pour ObsMer en nombre d'observation. */ @@ -742,26 +746,135 @@ public class SynthesisService extends WaoServiceSupport { } /** - * Pour ObsVente, le nombre de sortie × le nombre de navires qu'il est demandé d'observer par sortie. + * Pour ObsVente, le nombre de sortie. */ @Override protected int getExpected(SampleMonth sampleMonth) { - int averageObservationsCount = sampleMonth.getSampleRow().getAverageObservationsCount(); - return sampleMonth.getExpectedTidesValue() * averageObservationsCount; + return sampleMonth.getExpectedTidesValue(); } @Override protected String getValueAxisLabel() { - return I18n.l(locale, "wao.synthesis.observationsCount"); + return I18n.l(locale, "wao.synthesis.observationsCount.obsVente"); } - /** - * Le réalisé est le nombre d'observation, on compte 1 observation pour 1 navire donc 1 pour chaque contact. - */ @Override protected Map<Date, Integer> getActualPerPeriods(Contact contact) { return ImmutableMap.of(truncateToTimePeriod(contact.getObservationBeginDate()), 1); } + + @Override + public JFreeChart getChart() { + // obs vente + // définition de la fenêtre + Date periodFromMonth = truncateToTimePeriod(periodFrom); + Date periodToMonth = truncateToTimePeriod(periodTo); + + Range<Date> periodRange = Range.between(periodFromMonth, periodToMonth); + + // Calcul du programmé + SortedMap<Date, Integer> expectedEffortByPeriods = new TreeMap<>(); + for (SampleRow sampleRow : sampleRows) { + for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { + Date month = sampleMonth.getPeriodDate(); + Date period = truncateToTimePeriod(month); + Integer expected = MoreObjects.firstNonNull( + expectedEffortByPeriods.get(period), + 0); + expected += getExpected(sampleMonth); + expectedEffortByPeriods.put(period, expected); + } + } + + if (log.isDebugEnabled()) { + log.debug("expected effort by periods is " + expectedEffortByPeriods); + } + + // Calcul du réalisé + ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); + + // un sortie correspondre à n couples début/fin d'observation + MultiKeyMap<Object, Pair<Date, Date>> nbRealObservationsByTripForMonth = new MultiKeyMap<>(); + + + // Le réalisé est le nombre d'observation, on compte 1 observation pour 1 sortie. + for (Contact doneObservation : contacts) { + Preconditions.checkState(sampleRows.contains(doneObservation.getSampleRow())); + + Date obsBeginDate = doneObservation.getObservationBeginDate(); + Date obsEndDate = doneObservation.getObservationEndDate(); + + // si le contact doit être compté dans le réel + if (BooleanUtils.isTrue(doneObservation.getValidationCompany())) { + + Pair<Date, Date> real = nbRealObservationsByTripForMonth.get(obsBeginDate, obsEndDate); + if (real == null) { + // on ajoute 1 observation + Pair<Date, Date> obs = Pair.of(obsBeginDate, obsEndDate); + nbRealObservationsByTripForMonth.put(obsBeginDate, obsEndDate, obs); + + Map<Date, Integer> actualPerPeriods = getActualPerPeriods(doneObservation); + actualObservationsByPeriods.putAll(Multimaps.forMap(actualPerPeriods)); + } + } + + } + + if (log.isDebugEnabled()) { + log.debug("actual effort by periods is " + actualObservationsByPeriods); + } + + // Création du graphique + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + + // pour la barre représentant le planifié + for (Map.Entry<Date, Integer> entry : expectedEffortByPeriods.entrySet()) { + Date period = entry.getKey(); + if (periodRange.contains(period)) { + Integer expected = entry.getValue(); + dataset.setValue(expected, I18n.l(locale, "wao.synthesis.planned"), formatPeriod(period)); + } + } + + // pour la barre représentant l'estimé ou le réel + String rowKey; + if (realVsEstimated) { + rowKey = I18n.l(locale, "wao.ui.samplingPlan.Actual"); + } else { + rowKey = I18n.l(locale, "wao.synthesis.estimated"); + } + for (Map.Entry<Date, Collection<Integer>> entry : actualObservationsByPeriods.asMap().entrySet()) { + Date period = entry.getKey(); + if (periodRange.contains(period)) { + Integer actual = WaoUtils.sum(entry.getValue()); + dataset.setValue(actual, rowKey, formatPeriod(period)); + } + } + + // Axises + CategoryAxis categoryAxis = new CategoryAxis(""); + + String valueAxisLabel = getValueAxisLabel(); + ValueAxis valueAxis = new NumberAxis(valueAxisLabel); + valueAxis.setUpperMargin(0.15); + + // Renderer for Category + AbstractCategoryItemRenderer renderer = new BarRenderer(); + // Show labels on each element + renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); + renderer.setBaseItemLabelsVisible(Boolean.TRUE); + + CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + plot.setAxisOffset(RectangleInsets.ZERO_INSETS); + + JFreeChart chart = new JFreeChart( + I18n.l(locale, SynthesisId.GRAPH_SAMPLING.getI18nKey()), + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + return chart; + + } } /** diff --git a/wao-services/src/main/resources/i18n/wao-services_en_GB.properties b/wao-services/src/main/resources/i18n/wao-services_en_GB.properties index 61e5090..b70f39c 100644 --- a/wao-services/src/main/resources/i18n/wao-services_en_GB.properties +++ b/wao-services/src/main/resources/i18n/wao-services_en_GB.properties @@ -112,6 +112,7 @@ wao.import.sampleRow.failure.wrongSampleRowCodeFormat=The sample row code '%s' i wao.synthesis.daysCount=Days count wao.synthesis.estimated=Estimated wao.synthesis.observationsCount=Observations count +wao.synthesis.observationsCount.obsVente=Output number wao.synthesis.observationsCount.sclerochronology=Samples count wao.synthesis.planned=Planned wao.ui.chart.numberBoats=Number of boats diff --git a/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties b/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties index 2914eee..1a46dca 100644 --- a/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties +++ b/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties @@ -110,6 +110,7 @@ wao.import.sampleRow.failure.wrongSampleRowCodeFormat=Le code '%s' n'est pas un wao.synthesis.daysCount=Nombre de jours de mer wao.synthesis.estimated=Estimé wao.synthesis.observationsCount=Nombre d'observations +wao.synthesis.observationsCount.obsVente=Nombre de sorties wao.synthesis.observationsCount.sclerochronology=Nombre de prélèvements wao.synthesis.planned=Planifié wao.ui.chart.numberBoats=Nombre de navires -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm