This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository wao. See http://git.codelutin.com/wao.git commit 34567cf2dc51164cbdf44bf93a2ebcddb5b839d2 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Feb 26 12:23:34 2015 +0100 Dans la synthèse, on modifie le TemplateMethod pour pouvoir permettre de préciser un réalisé sur plusieurs mois --- .../wao/services/service/SynthesisService.java | 78 ++++++++++++---------- 1 file changed, 44 insertions(+), 34 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 10010be..20b426f 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 @@ -24,8 +24,12 @@ package fr.ifremer.wao.services.service; import com.google.common.base.MoreObjects; 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; import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.SampleRowsFilter; import fr.ifremer.wao.WaoUtils; @@ -102,7 +106,7 @@ public class SynthesisService extends WaoServiceSupport { filter.setFilterOnObservationBeginDate(true); synthesis.getSampleRowIds().addAll(dao.getSampleRowsIds(filter)); - setExpectedVsActualObservationsByMonthsBarChartData(synthesis, filter); + setExpectedVsActualBarChartDatas(synthesis, filter); if (obsProgram.isObsMer()) { setComplianceBoardingIndicator(synthesis, filter); setDataReliability(synthesis, filter); @@ -215,7 +219,7 @@ public class SynthesisService extends WaoServiceSupport { * Un graphique avec, pour chaque mois, deux barres qui représentent l'effort demandé * vs l'effort réalisé. */ - protected void setExpectedVsActualObservationsByMonthsBarChartData(Synthesis synthesis, ContactsFilter filter) { + protected void setExpectedVsActualBarChartDatas(Synthesis synthesis, ContactsFilter filter) { Preconditions.checkArgument(filter.isFilterOnObservationBeginDate()); @@ -470,8 +474,8 @@ public class SynthesisService extends WaoServiceSupport { public JFreeChart getChart() { // définition de la fenêtre - Date periodFromMonth = truncateToTimePeriodFunction(periodFrom); - Date periodToMonth = truncateToTimePeriodFunction(periodTo); + Date periodFromMonth = truncateToTimePeriod(periodFrom); + Date periodToMonth = truncateToTimePeriod(periodTo); Range<Date> periodRange = Range.between(periodFromMonth, periodToMonth); @@ -480,7 +484,7 @@ public class SynthesisService extends WaoServiceSupport { for (SampleRow sampleRow : sampleRows) { for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { Date month = sampleMonth.getPeriodDate(); - Date period = truncateToTimePeriodFunction(month); + Date period = truncateToTimePeriod(month); if (periodRange.contains(period)) { Integer expected = MoreObjects.firstNonNull( expectedEffortByPeriods.get(period), @@ -496,17 +500,18 @@ public class SynthesisService extends WaoServiceSupport { } // Calcul du réalisé - SortedMap<Date, Integer> actualObservationsByPeriods = new TreeMap<>(); + ListMultimap<Date, Integer> actualObservationsByPeriods = LinkedListMultimap.create(); for (Contact contact : contacts) { Preconditions.checkState(sampleRows.contains(contact.getSampleRow())); - Date period = truncateToTimePeriodFunction(contact.getObservationBeginDate()); - if (periodRange.contains(period)) { - Integer count = MoreObjects.firstNonNull( - actualObservationsByPeriods.get(period), - 0); - count += getActual(contact); - actualObservationsByPeriods.put(period, count); + Map<Date, Integer> actualPerPeriods = getActualPerPeriods(contact); + for (Map.Entry<Date, Integer> entry : actualPerPeriods.entrySet()) { + Date period = entry.getKey(); + if (periodRange.contains(period)) { + Integer actual = entry.getValue(); + actualObservationsByPeriods.put(period, actual); + } } + actualObservationsByPeriods.putAll(Multimaps.forMap(actualPerPeriods)); } if (log.isDebugEnabled()) { @@ -527,9 +532,10 @@ public class SynthesisService extends WaoServiceSupport { } else { rowKey = I18n.l(locale, "wao.synthesis.estimated"); } - for (Map.Entry<Date, Integer> entry : actualObservationsByPeriods.entrySet()) { + + for (Map.Entry<Date, Collection<Integer>> entry : actualObservationsByPeriods.asMap().entrySet()) { Date period = entry.getKey(); - Integer actual = entry.getValue(); + Integer actual = WaoUtils.sum(entry.getValue()); dataset.setValue(actual, rowKey, formatPeriod(period)); } @@ -558,10 +564,7 @@ public class SynthesisService extends WaoServiceSupport { } - /** - * Combien il faut compter de réalisé pour ce contact. - */ - protected abstract int getActual(Contact contact); + protected abstract Map<Date, Integer> getActualPerPeriods(Contact contact); protected abstract String getValueAxisLabel(); @@ -573,7 +576,7 @@ public class SynthesisService extends WaoServiceSupport { /** * Pour une date, indique dans quelle période de temps elle se trouve (mois ? trimestre ?) */ - protected abstract Date truncateToTimePeriodFunction(Date period); + protected abstract Date truncateToTimePeriod(Date period); protected abstract String formatPeriod(Date period); @@ -594,7 +597,7 @@ public class SynthesisService extends WaoServiceSupport { * On est sur un découpage mensuel. */ @Override - protected Date truncateToTimePeriodFunction(Date period) { + protected Date truncateToTimePeriod(Date period) { return WaoUtils.truncateToMonth(period); } @@ -615,8 +618,9 @@ public class SynthesisService extends WaoServiceSupport { * Le réalisé est le nombre d'observation, on compte 1 observation pour 1 navire donc 1 pour chaque contact. */ @Override - protected int getActual(Contact contact) { - return 1; + protected Map<Date, Integer> getActualPerPeriods(Contact contact) { + Date month = truncateToTimePeriod(contact.getObservationBeginDate()); + return ImmutableMap.of(month, 1); } } @@ -637,7 +641,7 @@ public class SynthesisService extends WaoServiceSupport { * On est sur un découpage mensuel. */ @Override - protected Date truncateToTimePeriodFunction(Date period) { + protected Date truncateToTimePeriod(Date period) { return WaoUtils.truncateToMonth(period); } @@ -656,11 +660,15 @@ public class SynthesisService extends WaoServiceSupport { } /** - * Le réalisé est le nombre d'observation, on compte 1 observation pour 1 navire donc 1 pour chaque contact. + * Le réalisé est le de jours de mers pour chaque mois. */ @Override - protected int getActual(Contact contact) { - return contact.getObservationTimeInDays(); + protected Map<Date, Integer> getActualPerPeriods(Contact contact) { + Map<Date, Integer> observationDaysByMonthsForObservation = + WaoUtils.getObservationDaysByMonths( + contact.getObservationBeginDate(), + contact.getObservationEndDate()); + return observationDaysByMonthsForObservation; } } @@ -681,7 +689,7 @@ public class SynthesisService extends WaoServiceSupport { * On est sur un découpage mensuel. */ @Override - protected Date truncateToTimePeriodFunction(Date period) { + protected Date truncateToTimePeriod(Date period) { return WaoUtils.truncateToMonth(period); } @@ -703,8 +711,8 @@ public class SynthesisService extends WaoServiceSupport { * Le réalisé est le nombre d'observation, on compte 1 observation pour 1 navire donc 1 pour chaque contact. */ @Override - protected int getActual(Contact contact) { - return 1; + protected Map<Date, Integer> getActualPerPeriods(Contact contact) { + return ImmutableMap.of(truncateToTimePeriod(contact.getObservationBeginDate()), 1); } } @@ -725,7 +733,7 @@ public class SynthesisService extends WaoServiceSupport { * On est sur un découpage en trimestres. */ @Override - protected Date truncateToTimePeriodFunction(Date period) { + protected Date truncateToTimePeriod(Date period) { return WaoUtils.truncateToTrimester(period); } @@ -743,11 +751,13 @@ public class SynthesisService extends WaoServiceSupport { } /** - * Le réalisé est le nombre d'individus échantilonnés. + * Le réalisé est le nombre d'individus échantilonnés sur le trimestre. */ @Override - protected int getActual(Contact contact) { - return contact.getSampleSize(); + protected Map<Date, Integer> getActualPerPeriods(Contact contact) { + Date trimester = truncateToTimePeriod(contact.getObservationBeginDate()); + Integer actual = contact.getSampleSize(); + return ImmutableMap.of(trimester, actual); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.