[Suiviobsmer-commits] r1237 - in trunk: wao-business/src/main/java/fr/ifremer/wao/bean wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/resources/i18n wao-business/src/main/xmi wao-business/src/test/java/fr/ifremer/wao/service wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/resources/i18n wao-ui/src/main/webapp
Author: bleny Date: 2011-04-26 14:08:44 +0000 (Tue, 26 Apr 2011) New Revision: 1237 Log: add synthesis for count of distinct boats observed Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/SynthesisId.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-business/src/test/java/fr/ifremer/wao/service/ObsDebTest.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties trunk/wao-ui/src/main/webapp/Synthesis.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/SynthesisId.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/SynthesisId.java 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/SynthesisId.java 2011-04-26 14:08:44 UTC (rev 1237) @@ -55,8 +55,11 @@ IND_DATA_RELIABILITY(n_("SynthesisId.IND_DATA_RELIABILITY")), /** ObsDeb, number of observations per hour of the day */ - OBSERVATION_HOUR(n_("SynthesisId.OBSERVATION_HOUR")); + OBSERVATION_HOUR(n_("SynthesisId.OBSERVATION_HOUR")), + /** ObsDeb, number of distinct boats observed by month */ + DISTINCT_BOATS_COUNTS(n_("SynthesisId.DISTINCT_BOATS_COUNTS")); + /** An i18n key to make enumeration printable in logs and UI. */ protected String i18nKey; Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2011-04-26 14:08:44 UTC (rev 1237) @@ -65,8 +65,6 @@ import fr.ifremer.wao.entity.IndicatorLogImpl; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.WaoUser; -import org.apache.commons.collections.OrderedMap; -import org.apache.commons.collections.map.HashedMap; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; @@ -83,10 +81,12 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; @@ -1297,5 +1297,75 @@ return result; } + + @Override + protected Map<String, Map<String, Integer>> executeGetDistinctBoatsCounts(TopiaContext transaction, SamplingFilter samplingFilter) throws Exception { + WaoQueryBuilder builder = context.newQueryBuilder(); + builder.initializeForContact(); + TopiaQuery query = builder.applySamplingFilter(samplingFilter); + ContactDAO contactDAO = WaoDAOHelper.getContactDAO(transaction); + List<Contact> contacts = contactDAO.findAllByQuery(query); + if (log.isDebugEnabled()) { + log.debug(contacts.size() + " found for distinct boats count synthesis"); + } + SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy"); + SimpleDateFormat monthFormat = new SimpleDateFormat("M"); + + // For each year of the contact found, for each month of this year, the + // boats observed this month of this year. We use a set, so we ensure + // that the boats are distincts + Map<String, Map<String, Set<Boat>>> temp = new HashMap<String, Map<String, Set<Boat>>>(); + + for (Contact contact : contacts) { + Date observationDate = contact.getObservationBeginDate(); + + if (observationDate != null) { + String year = yearFormat.format(observationDate); + String month = monthFormat.format(observationDate); + + Map<String, Set<Boat>> monthToBoats = temp.get(year); + if (monthToBoats == null) { + monthToBoats = new TreeMap<String, Set<Boat>>(); + temp.put(year, monthToBoats); + } + Set<Boat> boats = monthToBoats.get(month); + if (boats == null) { + boats = new HashSet<Boat>(); + monthToBoats.put(month, boats); + } + boats.add(contact.getBoat()); + } + } + + // Same collection as above, but the each set is replaced by its size() so we + // get for each month of each year the number of distinct boats + Map<String, Map<String, Integer>> result = new TreeMap<String, Map<String, Integer>>(); + for (Map.Entry<String, Map<String, Set<Boat>>> entry : temp.entrySet()) { + String year = entry.getKey(); + for (Map.Entry<String, Set<Boat>> entry2 : entry.getValue().entrySet()) { + String month = entry2.getKey(); + Map<String, Integer> monthToCount = result.get(year); + if (monthToCount == null) { + monthToCount = new TreeMap<String, Integer>(); + result.put(year, monthToCount); + } + monthToCount.put(month, temp.get(year).get(month).size()); + } + } + + if (log.isDebugEnabled()) { + log.debug("boat counts synthesis returns "); + for (Map.Entry<String, Map<String, Integer>> entry : result.entrySet()) { + String year = entry.getKey(); + for (Map.Entry<String, Integer> monthToBoatsCount : entry.getValue().entrySet()) { + String month = monthToBoatsCount.getKey(); + Integer count = monthToBoatsCount.getValue(); + log.debug(year + " " + month + " " + count); + } + } + } + + return result; + } } Modified: trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties 2011-04-26 14:08:44 UTC (rev 1237) @@ -30,6 +30,7 @@ SamplingStrategy.SIMULTANEOUS_G1_G2_SPECIES=Simultaneous \: G1+G2 species SamplingStrategy.SIMULTANEOUS_G1_SPECIES=Simultaneous \: G1 species SamplingStrategy.SPECIFIC_STOCK=Specific stock +SynthesisId.DISTINCT_BOATS_COUNTS=Counts of distinct boat observed SynthesisId.GRAPH_BOARDING=Boarding conformance rate on a given boat SynthesisId.GRAPH_SAMPLING=Sampling plan completion rate SynthesisId.IND_ALLEGRO_REACTIVITY=Data input delay @@ -222,6 +223,7 @@ wao.error.serviceSampling.validateSampleRow= wao.error.serviceSynthesis.getAllIndicatorLogs= wao.error.serviceSynthesis.getBoardingBoats= +wao.error.serviceSynthesis.getBoatsCount= wao.error.serviceSynthesis.getComplianceBoardingIndicator= wao.error.serviceSynthesis.getContactDataInputDateReactivity= wao.error.serviceSynthesis.getContactPieChartData= @@ -230,6 +232,7 @@ wao.error.serviceSynthesis.getContactStateStatistics= wao.error.serviceSynthesis.getDataReliability= wao.error.serviceSynthesis.getDataSampling= +wao.error.serviceSynthesis.getDistinctBoatsCounts= wao.error.serviceSynthesis.getGlobalSynthesisParameters=Unable to get data about global synthesis parameters wao.error.serviceSynthesis.getGlobalSynthesisResult= wao.error.serviceSynthesis.getNonComplianceBoardingIndicator= Modified: trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties 2011-04-26 14:08:44 UTC (rev 1237) @@ -30,6 +30,7 @@ SamplingStrategy.SIMULTANEOUS_G1_G2_SPECIES=Simultan\u00E9 \: esp\u00E8ces G1+G2 SamplingStrategy.SIMULTANEOUS_G1_SPECIES=Simultan\u00E9 \: esp\u00E8ces G1 SamplingStrategy.SPECIFIC_STOCK=Stock sp\u00E9cifique +SynthesisId.DISTINCT_BOATS_COUNTS=Nombres de navires distincts observ\u00E9s SynthesisId.GRAPH_BOARDING=Taux d'embarquement sur un m\u00EAme navire conforme aux exigences SynthesisId.GRAPH_SAMPLING=Taux de r\u00E9alisation du plan d'\u00E9chantillonage SynthesisId.IND_ALLEGRO_REACTIVITY=D\u00E9lais de transmission des donn\u00E9es @@ -222,6 +223,7 @@ wao.error.serviceSampling.validateSampleRow= wao.error.serviceSynthesis.getAllIndicatorLogs= wao.error.serviceSynthesis.getBoardingBoats=Impossible de r\u00E9cup\u00E9rer les donn\u00E9es du graphique concernant les embarquements sur les navires +wao.error.serviceSynthesis.getBoatsCount= wao.error.serviceSynthesis.getComplianceBoardingIndicator= wao.error.serviceSynthesis.getContactDataInputDateReactivity=Impossible de r\u00E9cup\u00E9rer l'indicateur de r\u00E9activit\u00E9 sur les dates de saisies dans Allegro wao.error.serviceSynthesis.getContactPieChartData= @@ -230,6 +232,7 @@ wao.error.serviceSynthesis.getContactStateStatistics=Impossible de r\u00E9cup\u00E9rer les statistiques sur les \u00E9tats des contacts wao.error.serviceSynthesis.getDataReliability= wao.error.serviceSynthesis.getDataSampling=Impossible de r\u00E9cup\u00E9rer les donn\u00E9es pour le graphique dynamique des efforts de mar\u00E9es +wao.error.serviceSynthesis.getDistinctBoatsCounts= wao.error.serviceSynthesis.getGlobalSynthesisParameters=Impossible de r\u00E9cup\u00E9rer les donn\u00E9es concernant les indicateurs pour la synth\u00E8se globale wao.error.serviceSynthesis.getGlobalSynthesisResult= wao.error.serviceSynthesis.getNonComplianceBoardingIndicator=Impossible de r\u00E9cup\u00E9rer l'indicateur de non respect du nombre d'observateurs embarqu\u00E9s Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ObsDebTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ObsDebTest.java 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ObsDebTest.java 2011-04-26 14:08:44 UTC (rev 1237) @@ -423,10 +423,16 @@ public void coordinatorCanGetSynthesisResults() throws WaoBusinessException, IOException { observerCanCreateContact(); + // TODO 20110426 bleny consider validation company and validation program when counting + SamplingFilter samplingFilter = serviceSampling.newSamplingFilter(fixtures.joshAsCoordinator()); Map<String, Map<String, Integer>> observationHours = serviceSynthesis.getObservationHours(samplingFilter); - // TODO 20110426 bleny consider validation company and validation program when counting Assert.assertEquals(2, observationHours.get("2010").get("09:00").intValue()); + + samplingFilter = serviceSampling.newSamplingFilter(fixtures.joshAsCoordinator()); + Map<String, Map<String, Integer>> boatsCounts = serviceSynthesis.getDistinctBoatsCounts(samplingFilter); + // Two distinct boats observed on February 2010 + Assert.assertEquals(2, boatsCounts.get("2010").get("2").intValue()); } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2011-04-26 14:08:44 UTC (rev 1237) @@ -515,6 +515,16 @@ return ChartUtils.createCategoryChart(title, axisName, categoryName, ChartType.BAR, result); } + /********************* INDICATOR : OBSERVATION HOUR ***********************/ + + public JFreeChart getDistinctBoatsCountsChart() throws WaoException { + Map result = serviceSynthesis.getDistinctBoatsCounts(getFilter()); + String title = messages.get(n_("wao.ui.synthesis.distinctBoatsCounts.title")); + String axisName = messages.get(n_("wao.ui.synthesis.distinctBoatsCounts.axisName")); + String categoryName = messages.get(n_("wao.ui.synthesis.distinctBoatsCounts.categoryName")); + return ChartUtils.createCategoryChart(title, axisName, categoryName, ChartType.BAR, result); + } + /********************* GLOBAL SYNTHESIS ***********************************/ @Property Modified: trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties =================================================================== --- trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties 2011-04-26 14:08:44 UTC (rev 1237) @@ -1,3 +1,4 @@ +SynthesisId.DISTINCT_BOATS_COUNTS= SynthesisId.GRAPH_BOARDING= SynthesisId.GRAPH_SAMPLING= SynthesisId.IND_ALLEGRO_REACTIVITY= @@ -287,6 +288,10 @@ wao.ui.synthesis.dataReliability.description=Percentage of the number of tides providing reliable data in relation to the total number of realized tides. wao.ui.synthesis.dataReliability.title=Data reliability wao.ui.synthesis.dataSampling.title=Tides data (realized / expected) +wao.ui.synthesis.distinctBoatsCounts.axisName=Number of boats +wao.ui.synthesis.distinctBoatsCounts.categoryName=Month of the year +wao.ui.synthesis.distinctBoatsCounts.description=For each month, the number of distinct boats observed during this month +wao.ui.synthesis.distinctBoatsCounts.title=Numbers of boats observed depending on the year wao.ui.synthesis.globalSynthesis.globalResult=Result of the global synthesis wao.ui.synthesis.globalSynthesis.title=Global synthesis wao.ui.synthesis.globalSynthesis.title.estimated=Global synthesis (according to estimations) Modified: trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties =================================================================== --- trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties 2011-04-26 14:08:44 UTC (rev 1237) @@ -1,3 +1,4 @@ +SynthesisId.DISTINCT_BOATS_COUNTS= SynthesisId.GRAPH_BOARDING= SynthesisId.GRAPH_SAMPLING= SynthesisId.IND_ALLEGRO_REACTIVITY= @@ -286,6 +287,10 @@ wao.ui.synthesis.dataReliability.description=Pourcentage du nombre de mar\u00E9es exploitables par rapport nombre de mar\u00E9e r\u00E9alis\u00E9es. wao.ui.synthesis.dataReliability.title=Qualit\u00E9 de la donn\u00E9e wao.ui.synthesis.dataSampling.title=Donn\u00E9es des mar\u00E9es (r\u00E9alis\u00E9 / planifi\u00E9) +wao.ui.synthesis.distinctBoatsCounts.axisName=Nombre de navires distincts +wao.ui.synthesis.distinctBoatsCounts.categoryName=Mois de l'ann\u00E9e +wao.ui.synthesis.distinctBoatsCounts.description=Nombre de navires distincts observ\u00E9s selon le mois de l'ann\u00E9e +wao.ui.synthesis.distinctBoatsCounts.title=Nombre de navires observ\u00E9s wao.ui.synthesis.globalSynthesis.globalResult=Bilan de la synth\u00E8se global wao.ui.synthesis.globalSynthesis.title=Synth\u00E8se globale wao.ui.synthesis.globalSynthesis.title.estimated=Synth\u00E8se globale (selon estimations) Modified: trunk/wao-ui/src/main/webapp/Synthesis.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Synthesis.tml 2011-04-26 08:45:24 UTC (rev 1236) +++ trunk/wao-ui/src/main/webapp/Synthesis.tml 2011-04-26 14:08:44 UTC (rev 1237) @@ -49,6 +49,11 @@ <img src="${asset:context:}/img/synthesis-observation-hour.png" alt="${message:SynthesisId.OBSERVATION_HOUR}" /> </a> </li> + <li> + <a t:type="actionlink" t:context="[actionSynthesisId,'DISTINCT_BOATS_COUNTS']" t:zone="so-synthesis-main" title="${message:SynthesisId.DISTINCT_BOATS_COUNTS}"> + <img src="${asset:context:}/img/synthesis-distinct-boats-counts.png" alt="${message:SynthesisId.DISTINCT_BOATS_COUNTS}" /> + </a> + </li> <p:else> <li> <a t:type="actionlink" t:context="[actionSynthesisId,'GRAPH_SAMPLING']" t:zone="so-synthesis-main" title="${message:SynthesisId.GRAPH_SAMPLING}"> @@ -370,4 +375,16 @@ <t:chart t:width="600" t:height="400" t:chart="observationHoursChart" /> </div> </t:block> + <!-- IND6 : OBSERVATION HOUR --> + <t:block t:id="ind7"> + <div class="ind-table acenter" id="so-datareliability"> + <h2>${message:wao.ui.synthesis.distinctBoatsCounts.title}</h2> + <br /> + <p> + ${message:wao.ui.synthesis.distinctBoatsCounts.description} + </p> + + <t:chart t:width="600" t:height="400" t:chart="distinctBoatsCountsChart" /> + </div> + </t:block> </t:layout>
participants (1)
-
bleny@users.labs.libre-entreprise.org