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>.