branch feature/6910-obsVente-effort-bis created (now 97d66bd)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6910-obsVente-effort-bis in repository wao. See http://git.codelutin.com/wao.git at 97d66bd Dans la synthèse changement du calcul du réalisé pour ObsVente en nombre de sorties et pas en nombre d'observations This branch includes the following new commits: new a34e298 refs #6910 modification du calcul de l'effort, calculé pour le nombre sortie et non plus par le nombre de contactes new 5f46ba9 refs #6910 modification du calcul de l'effort, dans l'onglet synthèse new c0d561b refs #6910 modification de traduction new 0f60e71 refs #6910 modification de commentaires new 95891e5 Factorisation HTML new aafd4fe Remaniement dans ExpectedVsActualChartTemplateMethod pour permettre de calculer le réalisé à partir de toute la liste des contacts et pas seulement pour un contact (prérequis pour compter en sorties dans ObsVente) new 97d66bd Dans la synthèse changement du calcul du réalisé pour ObsVente en nombre de sorties et pas en nombre d'observations The 7 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 97d66bdfc7ddbc792ffda1f2b082da8225e19bb3 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 10 16:41:57 2015 +0200 Dans la synthèse changement du calcul du réalisé pour ObsVente en nombre de sorties et pas en nombre d'observations commit aafd4fe689640863644082a3cdbe1060f1fa12b5 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 10 16:18:07 2015 +0200 Remaniement dans ExpectedVsActualChartTemplateMethod pour permettre de calculer le réalisé à partir de toute la liste des contacts et pas seulement pour un contact (prérequis pour compter en sorties dans ObsVente) commit a34e2985b5b96212719285a2f4fed88dc3bf0c14 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 commit 5f46ba93b5993190e7b7225e33534c4075491967 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 c0d561b4ac04844ae14d734a8d89659b59d57e76 Author: dcosse <cosse@codelutin.com> Date: Thu Apr 9 16:04:33 2015 +0200 refs #6910 modification de traduction commit 0f60e7199342399f59e83bc3d89bb21c8dc9668a Author: dcosse <cosse@codelutin.com> Date: Thu Apr 9 16:22:55 2015 +0200 refs #6910 modification de commentaires commit 95891e57f117da580fa286ba6fbe3f10fc53031c Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Apr 9 17:18:00 2015 +0200 Factorisation HTML -- 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-bis in repository wao. See http://git.codelutin.com/wao.git commit a34e2985b5b96212719285a2f4fed88dc3bf0c14 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-bis in repository wao. See http://git.codelutin.com/wao.git commit 5f46ba93b5993190e7b7225e33534c4075491967 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>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/6910-obsVente-effort-bis in repository wao. See http://git.codelutin.com/wao.git commit c0d561b4ac04844ae14d734a8d89659b59d57e76 Author: dcosse <cosse@codelutin.com> Date: Thu Apr 9 16:04:33 2015 +0200 refs #6910 modification de traduction --- wao-services/src/main/resources/i18n/wao-services_en_GB.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b70f39c..ff8349a 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,7 +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.obsVente=Trip's number wao.synthesis.observationsCount.sclerochronology=Samples count wao.synthesis.planned=Planned wao.ui.chart.numberBoats=Number of boats -- 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-bis in repository wao. See http://git.codelutin.com/wao.git commit 0f60e7199342399f59e83bc3d89bb21c8dc9668a Author: dcosse <cosse@codelutin.com> Date: Thu Apr 9 16:22:55 2015 +0200 refs #6910 modification de commentaires --- .../main/java/fr/ifremer/wao/services/service/SynthesisService.java | 6 +----- 1 file changed, 1 insertion(+), 5 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 1949f1b..4a3efc9 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 @@ -519,7 +519,6 @@ public class SynthesisService extends WaoServiceSupport { } public JFreeChart getChart() { - // super // définition de la fenêtre Date periodFromMonth = truncateToTimePeriod(periodFrom); Date periodToMonth = truncateToTimePeriod(periodTo); @@ -765,7 +764,6 @@ public class SynthesisService extends WaoServiceSupport { @Override public JFreeChart getChart() { - // obs vente // définition de la fenêtre Date periodFromMonth = truncateToTimePeriod(periodFrom); Date periodToMonth = truncateToTimePeriod(periodTo); @@ -793,11 +791,9 @@ public class SynthesisService extends WaoServiceSupport { // Calcul du réalisé ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); - // un sortie correspondre à n couples début/fin d'observation + // Le réalisé est le nombre de sortie, on compte 1 sortie pour un et unique couple 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())); -- 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-bis in repository wao. See http://git.codelutin.com/wao.git commit 95891e57f117da580fa286ba6fbe3f10fc53031c Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Apr 9 17:18:00 2015 +0200 Factorisation HTML --- .../main/webapp/WEB-INF/content/edit-sample-row-input.jsp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 38059e8..a1dcfbf 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,12 +233,14 @@ <div class="control-group"> - <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> + <label class="control-label"> + <s:if test="updateSampleRowCommand.sampleRow.obsProgram.obsVente"> + <s:text name="wao.ui.samplingPlan.effort.obsVente" /> + </s:if> + <s:else> + <s:text name="wao.ui.samplingPlan.effort" /> + </s:else> + </label> <div class="controls"> <table id="expectedObservationsByMonthsTable"> -- 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-bis in repository wao. See http://git.codelutin.com/wao.git commit aafd4fe689640863644082a3cdbe1060f1fa12b5 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 10 16:18:07 2015 +0200 Remaniement dans ExpectedVsActualChartTemplateMethod pour permettre de calculer le réalisé à partir de toute la liste des contacts et pas seulement pour un contact (prérequis pour compter en sorties dans ObsVente) --- .../wao/services/service/SynthesisService.java | 195 +++++---------------- 1 file changed, 47 insertions(+), 148 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 4a3efc9..5ffcdc9 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 @@ -25,7 +25,6 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.cache.Cache; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; @@ -44,8 +43,6 @@ 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; @@ -544,12 +541,7 @@ public class SynthesisService extends WaoServiceSupport { } // Calcul du réalisé - ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); - for (Contact contact : contacts) { - Preconditions.checkState(sampleRows.contains(contact.getSampleRow())); - Map<Date, Integer> actualPerPeriods = getActualPerPeriods(contact); - actualObservationsByPeriods.putAll(Multimaps.forMap(actualPerPeriods)); - } + Multimap<Date, Integer> actualObservationsByPeriods = getActualObservationsByPeriods(contacts); if (log.isDebugEnabled()) { log.debug("actual effort by periods is " + actualObservationsByPeriods); @@ -607,7 +599,14 @@ public class SynthesisService extends WaoServiceSupport { } - protected abstract Map<Date, Integer> getActualPerPeriods(Contact contact); + /** + * Calcul du réalisé (estimé ou réel, selon l'ensemble de contacts donné en paramètre). + * + * On doit retourner, pour chaque période (trimestre ? mois ?) l'effort qu'on considère réalisé. + * + * C'est une multimap, donc on peut indiquer plusieurs effort pour une même période. + */ + protected abstract Multimap<Date, Integer> getActualObservationsByPeriods(Collection<Contact> contacts); protected abstract String getValueAxisLabel(); @@ -659,19 +658,21 @@ public class SynthesisService extends WaoServiceSupport { return I18n.l(locale, "wao.synthesis.observationsCount"); } - /** - * 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) { - // on calcule les jours de mers pour chaque mois - Map<Date, Integer> observationDaysByMonthsForObservation = - WaoUtils.getObservationDaysByMonths( - contact.getObservationBeginDate(), - contact.getObservationEndDate()); - // on prend le mois avec le plus de jours de mers pour compter 1 observation - Date month = WaoUtils.getKeyWithHighestValue(observationDaysByMonthsForObservation); - return ImmutableMap.of(month, 1); + protected ListMultimap<Date, Integer> getActualObservationsByPeriods(Collection<Contact> contacts) { + ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); + for (Contact contact : contacts) { + Preconditions.checkState(sampleRows.contains(contact.getSampleRow())); + // on calcule les jours de mers pour chaque mois + Map<Date, Integer> observationDaysByMonthsForObservation = + WaoUtils.getObservationDaysByMonths( + contact.getObservationBeginDate(), + contact.getObservationEndDate()); + // on prend le mois avec le plus de jours de mers pour compter 1 observation + Date month = WaoUtils.getKeyWithHighestValue(observationDaysByMonthsForObservation); + actualObservationsByPeriods.put(month, 1); + } + return actualObservationsByPeriods; } } @@ -710,16 +711,18 @@ public class SynthesisService extends WaoServiceSupport { return I18n.l(locale, "wao.synthesis.daysCount"); } - /** - * Le réalisé est le de jours de mers pour chaque mois. - */ @Override - protected Map<Date, Integer> getActualPerPeriods(Contact contact) { - Map<Date, Integer> observationDaysByMonthsForObservation = - WaoUtils.getObservationDaysByMonths( - contact.getObservationBeginDate(), - contact.getObservationEndDate()); - return observationDaysByMonthsForObservation; + protected ListMultimap<Date, Integer> getActualObservationsByPeriods(Collection<Contact> contacts) { + ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); + for (Contact contact : contacts) { + Preconditions.checkState(sampleRows.contains(contact.getSampleRow())); + Map<Date, Integer> observationDaysByMonthsForObservation = + WaoUtils.getObservationDaysByMonths( + contact.getObservationBeginDate(), + contact.getObservationEndDate()); + actualObservationsByPeriods.putAll(Multimaps.forMap(observationDaysByMonthsForObservation)); + } + return actualObservationsByPeriods; } } @@ -758,118 +761,13 @@ public class SynthesisService extends WaoServiceSupport { } @Override - protected Map<Date, Integer> getActualPerPeriods(Contact contact) { - return ImmutableMap.of(truncateToTimePeriod(contact.getObservationBeginDate()), 1); - } - - @Override - public JFreeChart getChart() { - // 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é + protected ListMultimap<Date, Integer> getActualObservationsByPeriods(Collection<Contact> contacts) { ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); - - // Le réalisé est le nombre de sortie, on compte 1 sortie pour un et unique couple début/fin d'observation - MultiKeyMap<Object, Pair<Date, Date>> nbRealObservationsByTripForMonth = new MultiKeyMap<>(); - - 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)); - } + for (Contact contact : contacts) { + Preconditions.checkState(sampleRows.contains(contact.getSampleRow())); + actualObservationsByPeriods.put(truncateToTimePeriod(contact.getObservationBeginDate()), 1); } - - // 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; - + return actualObservationsByPeriods; } } @@ -907,14 +805,15 @@ public class SynthesisService extends WaoServiceSupport { return I18n.l(locale, "wao.synthesis.observationsCount.sclerochronology"); } - /** - * Le réalisé est le nombre d'individus échantilonnés sur le trimestre. - */ @Override - protected Map<Date, Integer> getActualPerPeriods(Contact contact) { - Date trimester = truncateToTimePeriod(contact.getObservationBeginDate()); - Integer actual = contact.getSampleSize(); - return ImmutableMap.of(trimester, actual); + protected ListMultimap<Date, Integer> getActualObservationsByPeriods(Collection<Contact> contacts) { + ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); + for (Contact contact : contacts) { + Preconditions.checkState(sampleRows.contains(contact.getSampleRow())); + Date trimester = truncateToTimePeriod(contact.getObservationBeginDate()); + actualObservationsByPeriods.put(trimester, contact.getSampleSize()); + } + return actualObservationsByPeriods; } } -- 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-bis in repository wao. See http://git.codelutin.com/wao.git commit 97d66bdfc7ddbc792ffda1f2b082da8225e19bb3 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 10 16:41:57 2015 +0200 Dans la synthèse changement du calcul du réalisé pour ObsVente en nombre de sorties et pas en nombre d'observations --- .../wao/services/service/SynthesisService.java | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 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 5ffcdc9..b49a15f 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 @@ -25,6 +25,7 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.cache.Cache; +import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; @@ -62,6 +63,7 @@ import org.nuiton.i18n.I18n; import org.nuiton.util.DateUtil; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; @@ -761,13 +763,30 @@ public class SynthesisService extends WaoServiceSupport { } @Override - protected ListMultimap<Date, Integer> getActualObservationsByPeriods(Collection<Contact> contacts) { - ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); + protected Multimap<Date, Integer> getActualObservationsByPeriods(Collection<Contact> contacts) { + HashMultimap<Date, Pair<Date, Date>> actualTripsByPeriods = HashMultimap.create(); for (Contact contact : contacts) { Preconditions.checkState(sampleRows.contains(contact.getSampleRow())); - actualObservationsByPeriods.put(truncateToTimePeriod(contact.getObservationBeginDate()), 1); + Date period = truncateToTimePeriod(contact.getObservationBeginDate()); + + // la sortie + Pair<Date, Date> trip = Pair.of( + contact.getObservationBeginDate(), + contact.getObservationEndDate()); + + // on ajoute la sortie sur la période, elle ne sera comptée qu'une fois car c'est un Set + actualTripsByPeriods.put(period, trip); } - return actualObservationsByPeriods; + + TreeMap<Date, Integer> actualObservationsByPeriods = new TreeMap<>(); + for (Map.Entry<Date, Collection<Pair<Date, Date>>> entry : actualTripsByPeriods.asMap().entrySet()) { + Date period = entry.getKey(); + + // ce qui nous intéresse, c'est le nombre de sortie + actualObservationsByPeriods.put(period, MoreObjects.firstNonNull(entry.getValue(), Collections.emptySet()).size()); + } + + return Multimaps.forMap(actualObservationsByPeriods); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm