Author: bleny Date: 2010-10-22 12:45:49 +0000 (Fri, 22 Oct 2010) New Revision: 706 Log: add data reliability indicator in service and UI Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSynthesisImplTest.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java trunk/wao-ui/src/main/webapp/Synthesis.tml 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 2010-10-22 10:36:47 UTC (rev 705) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-10-22 12:45:49 UTC (rev 706) @@ -46,6 +46,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -515,6 +516,118 @@ } @Override + protected Map<String, Double> executeGetDataReliability + (TopiaContext transaction, SamplingFilter filter) throws Exception { + + + WaoQueryBuilder builder = context.newQueryBuilder(); + ContactProperty contactProperty = builder.initializeForContact(); + + WaoQueryHelper.CompanyProperty companyProperty = + contactProperty.observerProperty().companyProperty(); + + TopiaQuery query = builder.applySamplingFilter(filter). + addEquals(contactProperty.state(), ContactState.BOARDING_DONE.ordinal()). + addEquals(contactProperty.validationCompany(), Boolean.TRUE). + addEquals(contactProperty.validationProgram(), Boolean.TRUE). + + + // Set the results wanted : by company, by reliability, + // get number of each realiability level + setSelect(companyProperty.name(), contactProperty.dataReliabilityOrdinal(), "COUNT(*)"). + addGroup(companyProperty.name(), contactProperty.dataReliabilityOrdinal()); + + if (log.isDebugEnabled()) { + log.debug("query for data reliability is " + query); + } + + List<Object[]> queryResults = transaction.findByQuery(query); + + if (log.isDebugEnabled()) { + for (Object[] result : queryResults) { + log.debug("result for data reliability contains " + + Arrays.toString(result)); + } + } + + // example results : [IMA, 0, 12] + // [OCEANIC DEVELOPPEMENT, 0, 94] + // [IFREMER, 0, 53] + // [YLAHE, 0, 145] + // [COFREPECHE, 0, 227] + // first column is the name of the company + // second column is the ordinal for DataReliability level + // third column is the number of contacts with this level + + List<String> companies = new ArrayList<String>(); + + Map<String, Long> companyNumberOfReliableData = new HashMap<String, Long>(); + + // value is the sum of reliable, doubtful and non-reliable contacts + // in this sum, number of "unknown" must be ignored + Map<String, Long> companyNumberOfEvaluatedData = new HashMap<String, Long>(); + + for (Object[] row : queryResults) { + String rowCompanyName = (String) row[0]; + int rowDataReliabilityOrdinal = (Integer) row[1]; + Long rowCount = (Long) row[2]; + + DataReliability reliability = + DataReliability.valueOf(rowDataReliabilityOrdinal); + + companies.add(rowCompanyName); + + if (reliability == DataReliability.RELIABLE) { + companyNumberOfReliableData.put(rowCompanyName, rowCount); + } + + if (reliability != DataReliability.UNKNOWN) { + Long oldValue = companyNumberOfEvaluatedData.get(rowCompanyName); + if (oldValue == null) { + // it's a sum, so init to 0 + oldValue = 0L; + } + Long newValue = oldValue + rowCount; + companyNumberOfEvaluatedData.put(rowCompanyName, newValue); + } + } + + // now compute the results (take care of zeros) + Map<String, Double> results = new HashMap<String, Double>(); + + for (String companyName : companies) { + Long numberOfEvaluated = companyNumberOfReliableData.get(companyName); + + if (numberOfEvaluated == null) { + // we will not divide by 0 + + if (log.isTraceEnabled()) { + log.trace("company " + companyName + " has never been " + + "evaluated yet. It will not be included in results"); + } + + // company is considered trustful + results.put(companyName, 1.0); + } else { + Long numberOfReliable = companyNumberOfReliableData.get(companyName); + if (numberOfReliable == null) { + numberOfReliable = 0L; + } + + Double result = (double) numberOfReliable / (double) numberOfEvaluated; + results.put(companyName, result); + + if (log.isDebugEnabled()) { + log.debug("result for company " + companyName + " is " + result); + } + } + } + + return results; + + } + + @Override public Map<String, PieChartData> executeGetContactPieChartDataByBoatDistrict( TopiaContext transaction, ContactFilter filter) throws TopiaException { @@ -572,19 +685,8 @@ return results; } - @Override - protected Map<Company, Double> executeGetDataReliability - (TopiaContext transaction, SamplingFilter filter) throws Exception { + protected Double getIndicatorValueForDataSampling(SamplingFilter filter) { - log.debug("period " + filter.getPeriod()); - - return null; - - } - - protected Double getIndicatorValueForDataSampling - (TopiaContext transaction, SamplingFilter filter) { - List<SortedMap<Date, Integer>> res = getDataSampling(filter); int totalNumberOfRealized = 0; @@ -619,11 +721,8 @@ return percentRealized; } - protected Double getIndicatorValueForBoarding - (TopiaContext transaction, SamplingFilter filter) { - + protected Double getIndicatorValueForBoarding(SamplingFilter filter) { BoardingResult boardingResult = getBoardingBoats(filter); - int numberOfBoatWithOneBoarding = boardingResult.getData().get("1"); int totalNumberOfBoarding = 0; for (Integer numberOfBoarding : boardingResult.getData().values()) { @@ -634,8 +733,7 @@ return rate; } - protected Double getIndicatorValueForComplianceBoarding - (TopiaContext transaction, SamplingFilter filter) { + protected Double getIndicatorValueForComplianceBoarding(SamplingFilter filter) { Map<String, Double> complianceBoarding = getComplianceBoardingIndicator(filter); double total = 0.0; int numberOfCompanies = complianceBoarding.size(); @@ -646,8 +744,7 @@ return indicatorValue; } - protected Double getIndicatorValueForAllegroReactivity - (TopiaContext transaction, SamplingFilter filter) { + protected Double getIndicatorValueForAllegroReactivity(SamplingFilter filter) { Collection<ContactAverageReactivity> allegroReactivity = getContactDataInputDateReactivity(filter); @@ -661,6 +758,17 @@ return totalAverages; } + protected Double getIndicatorValueForDataReliability(SamplingFilter filter) { + Map<String, Double> dataReliability = getDataReliability(filter); + double total = 0.0; + int numberOfCompanies = dataReliability.size(); + for (Double reliabilityRate : dataReliability.values()) { + total += reliabilityRate; + } + double indicatorValue = 100 * (total / numberOfCompanies); + return indicatorValue; + } + @Override protected GlobalSynthesisResult executeGetGlobalSynthesisResult (TopiaContext transaction, SamplingFilter filter) throws Exception { @@ -668,20 +776,20 @@ Double value; Map<SynthesisId, Double> indicatorValues = new HashMap<SynthesisId, Double>(); - value = getIndicatorValueForDataSampling(transaction, filter); + value = getIndicatorValueForDataSampling(filter); indicatorValues.put(SynthesisId.GRAPH_SAMPLING, value); - value = getIndicatorValueForBoarding(transaction, filter); + value = getIndicatorValueForBoarding(filter); indicatorValues.put(SynthesisId.GRAPH_BOARDING, value); - value = getIndicatorValueForComplianceBoarding(transaction, filter); + value = getIndicatorValueForComplianceBoarding(filter); indicatorValues.put(SynthesisId.IND_COMPLIANCE_BOARDING, value); - value = getIndicatorValueForAllegroReactivity(transaction, filter); + value = getIndicatorValueForAllegroReactivity(filter); indicatorValues.put(SynthesisId.IND_ALLEGRO_REACTIVITY, value); - // add data reliability indicator here - + value = getIndicatorValueForDataReliability(filter); + indicatorValues.put(SynthesisId.IND_DATA_RELIABILITY, value); List<Indicator> indicators = executeGetGlobalSynthesisParameters(transaction); Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSynthesisImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSynthesisImplTest.java 2010-10-22 10:36:47 UTC (rev 705) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSynthesisImplTest.java 2010-10-22 12:45:49 UTC (rev 706) @@ -586,4 +586,10 @@ assertEquals(0, res.getResult(), 0.01); } + @Test + public void testGetDataReliability() throws Exception { + + + + } } 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 2010-10-22 10:36:47 UTC (rev 705) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-10-22 12:45:49 UTC (rev 706) @@ -475,4 +475,23 @@ return ""; } + /********************* INDICATOR : DATA RELIABILITY ***********************/ + + private Map<String, Double> dataReliability; + + /* variable used in template */ + @Property + private Map.Entry<String, Double> dataReliabilityEntry; + + public Map<String, Double> getDataReliability() { + if (dataReliability == null) { + dataReliability = serviceSynthesis.getDataReliability(getFilter()); + } + return dataReliability; + } + + public Double getDataReliabilityValue() throws WaoException { + return getDataReliability().get(user.getCompany()); + } + } \ No newline at end of file Modified: trunk/wao-ui/src/main/webapp/Synthesis.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Synthesis.tml 2010-10-22 10:36:47 UTC (rev 705) +++ trunk/wao-ui/src/main/webapp/Synthesis.tml 2010-10-22 12:45:49 UTC (rev 706) @@ -122,6 +122,12 @@ title="Indicateur de réactivité sur la saisie des données dans Allegro" /> </a> </li> + <li> + <a t:type="actionlink" t:context="[actionSynthesisId,'IND_DATA_RELIABILITY']" t:zone="so-synthesis-main"> + <img src="${asset:context:}/img/synthesis-ind-non-compliance-boarding.png" alt="Indicateur" + title="Indicateur de la qualité des données" /> + </a> + </li> </ul> </div> <div t:type="zone" t:id="delegator" class="fleft" t:update="show" id="so-synthesis-main"> @@ -302,4 +308,42 @@ <t:indicatorLevels t:indicator="activeIndicator" t:highlightLevel="activeIndicatorLevel" /> </div> </t:block> + <!-- IND1 : COMPLIANCE_BOARDING --> + <t:block t:id="ind5"> + <div class="ind-table acenter" id="so-noncomplianceboarding"> + <h2>Qualité de la donnée</h2> + <br /> + <t:if t:test="user.admin"> + <table class="t-data-grid"> + <thead> + <tr> + <th class="company">Société</th> + <th>Indicateur</th> + </tr> + </thead> + <tbody> + <tr t:type="loop" t:source="dataReliability.entrySet()" t:value="dataReliabilityEntry"> + <td class="company">${dataReliabilityEntry.key}</td> + <td class="number"> + <t:output t:value="dataReliabilityEntry.value" t:format="percentFormat"/> + </td> + </tr> + </tbody> + </table> + <p:else> + <div class="indicator"> + <p class="number"> + <span t:type="output" t:value="complianceBoardingValue" t:format="percentFormat"> + ${complianceBoardingValue} + </span> + </p> + </div> + </p:else> + </t:if> + + <!-- now render a table with position on global synthesis --> + <br /> + <t:indicatorLevels t:indicator="activeIndicator" t:highlightLevel="activeIndicatorLevel" /> + </div> + </t:block> </t:layout>