[Suiviobsmer-commits] r698 - 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-ui/src/main/java/fr/ifremer/wao/ui/components wao-ui/src/main/webapp
Author: bleny Date: 2010-10-20 13:01:31 +0000 (Wed, 20 Oct 2010) New Revision: 698 Log: WIP ; moved to business global synthesis in business Added: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalIndicatorValue.java trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ContactState.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-ui/src/main/java/fr/ifremer/wao/ui/components/IndicatorLevels.java trunk/wao-ui/src/main/webapp/Contacts.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ContactState.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ContactState.java 2010-10-19 15:58:34 UTC (rev 697) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ContactState.java 2010-10-20 13:01:31 UTC (rev 698) @@ -49,18 +49,29 @@ BOAT_DEFINITIVE_REFUSED("Refus définitif", true, true); + /** @deprecated I18N should be done properly by tapestry */ + @Deprecated private String libelle; private boolean finalState; private boolean unfinishedState; + /** @deprecated I18N should be done properly by tapestry */ + @Deprecated ContactState(String value, boolean finalState, boolean unfinishedState) { this.libelle = value; this.finalState = finalState; this.unfinishedState = unfinishedState; } + ContactState(boolean finalState, boolean unfinishedState) { + this.finalState = finalState; + this.unfinishedState = unfinishedState; + } + + /** @deprecated I18N should be done properly by tapestry */ + @Deprecated public String libelle() { return this.libelle; } Added: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalIndicatorValue.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalIndicatorValue.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalIndicatorValue.java 2010-10-20 13:01:31 UTC (rev 698) @@ -0,0 +1,16 @@ +package fr.ifremer.wao.bean; + +public enum GlobalIndicatorValue { + + VERY_BAD, + + BAD, + + NEUTRAL, + + GOOD, + + VERY_GOOD; + + +} Added: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java 2010-10-20 13:01:31 UTC (rev 698) @@ -0,0 +1,72 @@ +package fr.ifremer.wao.bean; + +import fr.ifremer.wao.entity.Indicator; +import fr.ifremer.wao.entity.IndicatorLevel; + +import java.util.List; +import java.util.Map; + +public class GlobalSynthesisResultImpl extends GlobalSynthesisResult { + + protected Map<SynthesisId, Double> values; + + protected List<Indicator> indicators; + + public void setIndicatorValues(Map<SynthesisId, Double> indicatorValues) { + this.values = indicatorValues; + } + + public void setIndicators(List<Indicator> indicators) { + this.indicators = indicators; + } + + /** in the list of indicators, find the one with given synthesisId. */ + protected Indicator findIndicator(SynthesisId id) { + for (Indicator indicator : indicators) { + if (indicator.getSynthesisId().equals(id)) { + return indicator; + } + } + return null; + } + + @Override + public IndicatorLevel getLevelForIndicator(SynthesisId synthesisId) { + Indicator indicator = findIndicator(synthesisId); + Double value = values.get(indicator); + IndicatorLevel result = indicator.getLevelForValue(value); + return result; + } + + /** return a value between 1 and 6 */ + @Override + public GlobalIndicatorValue getGlobalLevel() { + // compute an average with coefficients + double totalValues = 0.0; + double totalCoefficients = 0.0; + + for (Indicator indicator : indicators) { + Double value = values.get(indicator.getSynthesisId()); + Double coefficient = indicator.getCoefficient(); + + totalValues += value * coefficient; + totalCoefficients += coefficient; + } + + double value = totalValues / totalCoefficients; + + GlobalIndicatorValue result = null; + if (value >= 1.0 && value < 2.0) { + result = GlobalIndicatorValue.VERY_BAD; + } else if (value >= 2.0 && value < 3.0) { + result = GlobalIndicatorValue.BAD; + } else if (value >= 3.0 && value < 5.0) { + result = GlobalIndicatorValue.NEUTRAL; + } else if (value >= 5.0 && value < 5.5) { + result = GlobalIndicatorValue.GOOD; + } else if (value >= 5.5 && value <= 6.0) { + result = GlobalIndicatorValue.VERY_GOOD; + } + return result; + } +} 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-19 15:58:34 UTC (rev 697) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-10-20 13:01:31 UTC (rev 698) @@ -64,7 +64,7 @@ */ public class ServiceSynthesisImpl extends ServiceSynthesisAbstract { - private static final Logger logger = + private static final Logger log = LoggerFactory.getLogger(ServiceSynthesisImpl.class); private WaoContext context; @@ -146,8 +146,8 @@ // builder.setSampleRowProperty("M." + SampleMonth.SAMPLE_ROW); // builder.applySamplingFilter(filter); - if (logger.isTraceEnabled()) { - logger.trace("Exec query : " + query); + if (log.isTraceEnabled()) { + log.trace("Exec query : " + query); } List<Object[]> res = transaction.findByQuery(query); @@ -158,10 +158,10 @@ int sumExpected = ((Long)tab[2]).intValue(); serie1.put(date, sumExpected); serie2.put(date, sumReal); - if (logger.isTraceEnabled()) { + if (log.isTraceEnabled()) { DateFormat dateFormat = new SimpleDateFormat(period.getPattern()); - logger.trace("Res : " + dateFormat.format(date) + " : " + log.trace("Res : " + dateFormat.format(date) + " : " + sumReal + " / " + sumExpected); } } @@ -231,8 +231,8 @@ addGroup(contact + "." + Contact.BOAT). addOrderDesc("COUNT(*)"); - if (logger.isTraceEnabled()) { - logger.trace("Exec query : " + query); + if (log.isTraceEnabled()) { + log.trace("Exec query : " + query); } List<Map<String, Object>> nbBoardingsByBoat = transaction.findByQuery(query); @@ -302,8 +302,8 @@ query.setSelect(companyNameProperty, "COUNT(*)"). addGroup(companyNameProperty); - if (logger.isDebugEnabled()) { - logger.debug("Query for total : " + query); + if (log.isDebugEnabled()) { + log.debug("Query for total : " + query); } List<Object[]> totalResults = transaction.findByQuery(query); @@ -318,8 +318,8 @@ toString() ); - if (logger.isDebugEnabled()) { - logger.debug("Query for result : " + query); + if (log.isDebugEnabled()) { + log.debug("Query for result : " + query); } List<Object[]> diffResults = transaction.findByQuery(query); @@ -328,8 +328,8 @@ for (Object[] row : diffResults) { String rowCompanyName = (String)row[0]; Long rowCount = (Long)row[1]; - if (logger.isDebugEnabled()) { - logger.debug("result row : " + rowCompanyName + " = " + rowCount); + if (log.isDebugEnabled()) { + log.debug("result row : " + rowCompanyName + " = " + rowCount); } results.put(rowCompanyName, rowCount.doubleValue()); } @@ -340,8 +340,8 @@ for (Object[] row : totalResults) { String rowCompanyName = (String)row[0]; Long rowCount = (Long)row[1]; - if (logger.isDebugEnabled()) { - logger.debug("total row : " + rowCompanyName + " = " + rowCount); + if (log.isDebugEnabled()) { + log.debug("total row : " + rowCompanyName + " = " + rowCount); } Double value = results.get(rowCompanyName); if (value == null) { @@ -486,8 +486,8 @@ int rowState = (Integer)row[1]; ContactState state = ContactState.valueOf(rowState); Long rowCount = (Long)row[2]; - if (logger.isDebugEnabled()) { - logger.debug("res : " + rowCompanyName + " _ " + state + " _ " + rowCount); + if (log.isDebugEnabled()) { + log.debug("res : " + rowCompanyName + " _ " + state + " _ " + rowCount); } ContactStateStatistics stats = results.get(rowCompanyName); if (stats == null) { @@ -535,8 +535,8 @@ query.setSelect(companyNameProperty, dataInputProperty, tideBeginDateProperty); - if (logger.isDebugEnabled()) { - logger.debug("Query : " + query); + if (log.isDebugEnabled()) { + log.debug("Query : " + query); } List<Object[]> res = transaction.findByQuery(query); @@ -548,11 +548,11 @@ int nbDays = DateUtil.getDifferenceInDays(rowTideBeginDate, rowDataInputDate); - if (logger.isDebugEnabled()) { - logger.debug("Company : " + rowCompanyName); - logger.debug("tideBegin : " + rowTideBeginDate); - logger.debug("dataInput : " + rowDataInputDate); - logger.debug("nbDays : " + nbDays); + if (log.isDebugEnabled()) { + log.debug("Company : " + rowCompanyName); + log.debug("tideBegin : " + rowTideBeginDate); + log.debug("dataInput : " + rowDataInputDate); + log.debug("nbDays : " + nbDays); } ContactAverageReactivity avg = results.get(rowCompanyName); @@ -652,7 +652,117 @@ return results; } + protected Double getIndicatorValueForDataSampling + (TopiaContext transaction, SamplingFilter filter) { + + List<SortedMap<Date, Integer>> res = getDataSampling(filter); + + int totalNumberOfRealized = 0; + int totalNumberOfPlanned = 0; + for (Map.Entry<Date, Integer> entry : res.get(1).entrySet()) { + // res.get(1) contains number of realized + // while res.get(0) contains planned + + Date date = entry.getKey(); + // both variables will contains planned and realized at the same date + int numberOfRealized = entry.getValue(); + int numberOfPlanned = res.get(0).get(date); + + totalNumberOfPlanned += numberOfPlanned; + totalNumberOfRealized += numberOfRealized; + + if (log.isDebugEnabled()) { + log.debug(String.format( + "number of planed %s (%s), number of realized %s (%s)", + numberOfPlanned, totalNumberOfPlanned, + numberOfRealized, totalNumberOfRealized)); + } + } + + double percentRealized = ((double) totalNumberOfRealized / + (double) totalNumberOfPlanned) * 100.0; + + if (log.isDebugEnabled()) { + log.debug(String.format("percent realized %f %%", percentRealized)); + } + + return percentRealized; + } + + protected Double getIndicatorValueForBoarding + (TopiaContext transaction, Company company, Date fromDate) { + + BoardingResult boardingResult = getBoardingBoats(company, fromDate); + + int numberOfBoatWithOneBoarding = boardingResult.getData().get("1"); + int totalNumberOfBoarding = 0; + for (Integer numberOfBoarding : boardingResult.getData().values()) { + totalNumberOfBoarding += numberOfBoarding; + } + double rate = ((double) numberOfBoatWithOneBoarding / + (double) totalNumberOfBoarding) * 100.0; + return rate; + } + + protected Double getIndicatorValueForComplianceBoarding + (TopiaContext transaction, Company company) { + Map<String, Double> complianceBoarding = getComplianceBoardingIndicator(company); + double total = 0.0; + int numberOfCompanies = complianceBoarding.size(); + for (Double compliance : complianceBoarding.values()) { + total += compliance; + } + double indicatorValue = 100 * (total / numberOfCompanies); + return indicatorValue; + } + + protected Double getIndicatorValueForAllegroReactivity + (TopiaContext transaction, Company company, PeriodDates periodDates) { + Collection<ContactAverageReactivity> allegroReactivity = getContactDataInputDateReactivity(company, periodDates); + + double sumAverages = 0.0; + for (ContactAverageReactivity reactivity : allegroReactivity) { + sumAverages += reactivity.getResult(); + } + + double numberOfCompanies = (double) allegroReactivity.size(); + double totalAverages = sumAverages / numberOfCompanies; + return totalAverages; + } + @Override + protected GlobalSynthesisResult executeGetGlobalSynthesisResult + (TopiaContext transaction, Company company, PeriodDates period) + throws Exception { + + GlobalSynthesisResultImpl result = new GlobalSynthesisResultImpl(); + + Double value = 30.0; + Map<SynthesisId, Double> indicatorValues = new HashMap<SynthesisId, Double>(); + + // value = getIndicatorValueForDataSampling(transaction, samplingFilter); + indicatorValues.put(SynthesisId.GRAPH_SAMPLING, value); + + // value = getIndicatorValueForBoarding(transaction, company, fromDate); + indicatorValues.put(SynthesisId.GRAPH_BOARDING, value); + + value = getIndicatorValueForComplianceBoarding(transaction, company); + indicatorValues.put(SynthesisId.IND_COMPLIANCE_BOARDING, value); + + value = getIndicatorValueForAllegroReactivity(transaction, company, period); + indicatorValues.put(SynthesisId.IND_ALLEGRO_REACTIVITY, value); + + // add data reliability indicator here + + + + result.setIndicatorValues(indicatorValues); + List<Indicator> indicators = executeGetGlobalSynthesisParameters(transaction); + result.setIndicators(indicators); + return result; + } + + @Override protected List<Indicator> executeGetGlobalSynthesisParameters(TopiaContext transaction) throws Exception { IndicatorDAO indicatorDAO = WaoDAOHelper.getIndicatorDAO(transaction); List<Indicator> indicators = indicatorDAO.findAll(); 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 2010-10-19 15:58:34 UTC (rev 697) +++ trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-10-20 13:01:31 UTC (rev 698) @@ -81,6 +81,7 @@ wao.error.serviceSynthesis.getContactStateStatistics= wao.error.serviceSynthesis.getDataSampling= wao.error.serviceSynthesis.getGlobalSynthesisParameters=Unable to get data about global synthesis parameters +wao.error.serviceSynthesis.getGlobalSynthesisResult= wao.error.serviceSynthesis.getNonComplianceBoardingIndicator= wao.error.serviceUser.connect= wao.error.serviceUser.createDefaultAdmin= 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 2010-10-19 15:58:34 UTC (rev 697) +++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-10-20 13:01:31 UTC (rev 698) @@ -80,6 +80,7 @@ wao.error.serviceSynthesis.getContactStateStatistics=Impossible de r\u00E9cup\u00E9rer les statistiques sur les \u00E9tats des contacts wao.error.serviceSynthesis.getDataSampling=Impossible de r\u00E9cup\u00E9rer les donn\u00E9es pour le graphique dynamique des efforts de mar\u00E9es 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 wao.error.serviceUser.connect=Une erreur est survenue lors de la demande de connexion wao.error.serviceUser.createDefaultAdmin=Impossible de cr\u00E9er l'administrateur par d\u00E9faut Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/IndicatorLevels.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/IndicatorLevels.java 2010-10-19 15:58:34 UTC (rev 697) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/IndicatorLevels.java 2010-10-20 13:01:31 UTC (rev 698) @@ -46,7 +46,7 @@ } public Boolean isWithLegend() { - if (withLegend = null) { + if (withLegend == null) { withLegend = false; } return withLegend; Modified: trunk/wao-ui/src/main/webapp/Contacts.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Contacts.tml 2010-10-19 15:58:34 UTC (rev 697) +++ trunk/wao-ui/src/main/webapp/Contacts.tml 2010-10-20 13:01:31 UTC (rev 698) @@ -295,9 +295,7 @@ <t:if t:test="contact.validationProgram"> ${contact.dataReliability.label} <p:else> - <t:if t:test="canValidate()"> - <input t:type="select" t:id="dataReliability" t:value="contact.dataReliability" validate="required" /> --> - </t:if> + <input t:type="select" t:id="dataReliability" t:value="contact.dataReliability" validate="required" /> </p:else> </t:if> </t:if>
participants (1)
-
bleny@users.labs.libre-entreprise.org