[Git][ultreiaio/ird-t3][develop] [N0.4] Calcul des durées de calées pour les activités avec setcount > 1 (Closes #241)
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3 Commits: 4072de7b by Tony CHEMIT at 2018-02-21T02:09:42+01:00 [N0.4] Calcul des durées de calées pour les activités avec setcount > 1 (Closes #241) - - - - - 3 changed files: - t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java - t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties - t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties Changes: ===================================== t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java ===================================== --- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java +++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java @@ -20,7 +20,6 @@ */ package fr.ird.t3.actions.data.level0; -import com.google.common.collect.Maps; import fr.ird.t3.entities.T3Functions; import fr.ird.t3.entities.data.Activity; import fr.ird.t3.entities.data.Trip; @@ -41,14 +40,14 @@ import org.nuiton.util.TimeLog; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeMap; import static org.nuiton.i18n.I18n.l; /** - * Compute for the all activities of selected trips, the set duration and the - * positive set count. + * Compute for the all activities of selected trips, the set duration and the positive set count. * <p/> - * <strong>Note:</strong> The rf2 msut have been computed on each trip. + * <strong>Note:</strong> The rf2 must have been computed on each trip. * * @author Tony Chemit - dev@tchemit.fr * @since 1.0 @@ -56,24 +55,21 @@ import static org.nuiton.i18n.I18n.l; public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0Action<ComputeSetDurationAndPositiveSetCountConfiguration> { /** Logger. */ - private static final Log log = LogFactory.getLog( - ComputeSetDurationAndPositiveSetCountAction.class); - + private static final Log log = LogFactory.getLog(ComputeSetDurationAndPositiveSetCountAction.class); @InjectDAO(entityType = SetDuration.class) - protected SetDurationTopiaDao setDurationDAO; - - /** Count of treated activites. */ - protected int nbActivities; + private SetDurationTopiaDao setDurationDAO; + /** Count of treated activities. */ + private int nbActivities; + /** Count of positive activities found. */ + private int nbPositiveActivities; /** Count of set (sum(a.setCount) on each activity trip). */ - protected int nbSet; - /** Count of positive activites found. */ - protected int nbPositiveActivities; + private int nbSet; /** * Cache of setDuration (improve a lot performance!). * * @since 1.3 */ - protected Map<String, SetDuration> setDurations; + private Map<String, SetDuration> setDurations; public ComputeSetDurationAndPositiveSetCountAction() { super(Level0Step.COMPUTE_SET_DURATION_AND_POSITIVE_SET_COUNT); @@ -98,8 +94,7 @@ public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0A for (Trip trip : tripList) { nbActivities += trip.sizeActivity(); } - - setDurations = Maps.newTreeMap(); + setDurations = new TreeMap<>(); } @Override @@ -108,177 +103,112 @@ public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0A } @Override - protected boolean executeAction() throws Exception { - + protected boolean executeAction() { boolean result = false; - if (CollectionUtils.isNotEmpty(trips)) { - setNbSteps(2 * nbActivities); - - // do action for each data using the prepared action context - for (Trip trip : trips) { - result |= executeForTrip(trip); } } - return result; } - protected boolean executeForTrip(Trip trip) throws TopiaException { - + private boolean executeForTrip(Trip trip) throws TopiaException { long s0 = TimeLog.getTime(); - String tripStr = decorate(trip, DecoratorService.WITH_ID); - - if (!trip.isActivityEmpty()) { - + if (trip.isActivityNotEmpty()) { int year = T3Functions.TRIP_TO_LANDING_YEAR.apply(trip); - Set<Species> species = trip.getElementaryCatchSpecies(); - for (Activity activity : trip.getActivity()) { + String activityStr = String.format("Activity %s - %s", tripStr, decorate(activity)); + int setCount = activity.getSetCount(); + nbSet += setCount; - String activityStr = "Activity " + tripStr + " - " + - decorate(activity); - - nbSet += activity.getSetCount(); - incrementsProgression(); - - float totalCatchesWeight = - activity.getElementaryCatchTotalWeightRf2(species); - + float totalCatchesWeight = activity.getElementaryCatchTotalWeightRf2(species); if (log.isDebugEnabled()) { - log.debug("Total catches " + totalCatchesWeight + - " for " + activityStr); + log.debug(String.format("Total catches %s for %s", totalCatchesWeight, activityStr)); } + int positiveSetCount = computePositiveSetCount(totalCatchesWeight > 0, activity); + activity.setPositiveSetCount(positiveSetCount); + if (positiveSetCount > 0) { + nbPositiveActivities++; + } + incrementsProgression(); - computePositiveSetCount(activityStr, totalCatchesWeight, activity); - + float subCatch = totalCatchesWeight; + if (positiveSetCount > 0) { + subCatch = subCatch / activity.getPositiveSetCount(); + } + int negativeSetCount = setCount - positiveSetCount; + Float setDuration = computeSetDuration(year, subCatch, activity, negativeSetCount); + activity.setSetDuration(setDuration); incrementsProgression(); - computeSetDuration(year, - totalCatchesWeight, activity); String message = l(locale, "t3.level0.computeActivitySetDurationAndPositiveSetCount", - activityStr, - activity.getSetDuration(), - activity.getPositiveSetCount() - ); + activityStr, setDuration, positiveSetCount, negativeSetCount); addInfoMessage(message); if (log.isDebugEnabled()) { log.debug(message); } } } - markTripAsTreated(trip); - getTimeLog().log(s0, "executeForTrip for " + tripStr); - // always commit since trip is always modified return true; } - protected void computePositiveSetCount(String activityStr, - float totalCatchesWeight, - Activity activity) { - - int positiveSetCount = 0; - - if (totalCatchesWeight > 0) { - - // ok some catches found on activity, it means - // positive set - - positiveSetCount = activity.getSetCount(); - - } else { - if (log.isDebugEnabled()) { - log.debug("Catches with no catches! for " + activityStr); - } - } - - if (log.isDebugEnabled()) { - String message = "Computed positive Set Count = " + - positiveSetCount + " for " + activityStr; - log.debug(message); - } - activity.setPositiveSetCount(positiveSetCount); - - if (positiveSetCount > 0) { - nbPositiveActivities++; + private int computePositiveSetCount(boolean withCatches, Activity activity) { + if (withCatches) { + // ok some catches found on activity, it means positive set + return activity.getSetCount(); } + return 0; } - protected void computeSetDuration(int year, - float totalCatchesWeight, - Activity activity) throws TopiaException { - + private Float computeSetDuration(int year, float subCatch, Activity activity, int negativeSetCount) throws TopiaException { // get the correct setDuration SetDuration setDuration = getSetDuration(activity, year); - if (setDuration == null) { - - activity.setSetDuration(0f); - - } else { - - Float setTime; - - if (activity.isSetNull()) { - - // use setDuration nullSetValue - setTime = setDuration.getNullSetValue(); - if (log.isDebugEnabled()) { - log.debug("Computed set duration (set is null) = " + - setTime); - } - } else if (activity.isWithSetDuration()) { - - // use setDuration computedValue - setTime = setDuration.getParameterB() + - setDuration.getParameterA() * totalCatchesWeight; - if (log.isDebugEnabled()) { - log.debug("Computed set duration = " + setTime); - } - } else { - - // no setDuration - setTime = null; - if (log.isDebugEnabled()) { - log.debug("Use null set duration (set is null) "); - } + if (log.isDebugEnabled()) { + log.debug("No setDuration found, use 0 value."); } - - activity.setSetDuration(setTime); + return 0f; + } + float nullSetDuration = negativeSetCount * setDuration.getNullSetValue(); + if (activity.isSetNull()) { + if (log.isDebugEnabled()) { + log.debug(String.format("Use nullValue of set duration = %s", nullSetDuration)); + } + return nullSetDuration; + } + if (activity.isWithSetDuration()) { + float subDuration = (setDuration.getParameterB() + setDuration.getParameterA() * subCatch); + float positiveSetDuration = activity.getPositiveSetCount() * subDuration; + if (log.isDebugEnabled()) { + log.debug(String.format("Computed positive set duration = %s", positiveSetDuration)); + } + return nullSetDuration + positiveSetDuration; + } + // no setDuration + if (log.isDebugEnabled()) { + log.debug("Use null set duration (set is null) "); } + return null; } - protected SetDuration getSetDuration(Activity activity, int year) throws TopiaException { + private SetDuration getSetDuration(Activity activity, int year) throws TopiaException { Ocean ocean = activity.getOcean(); Country fleetCountry = activity.getTrip().getVessel().getFleetCountry(); SchoolType schoolType = activity.getSchoolType(); - String key = ocean.getCode() + ":" + - fleetCountry.getCode() + ":" + - schoolType.getCode() + ":" + - year; - + String key = ocean.getCode() + ":" + fleetCountry.getCode() + ":" + schoolType.getCode() + ":" + year; SetDuration result = setDurations.get(key); if (result == null) { - // no result found in cache - if (!setDurations.containsKey(key)) { - // try to load it - - result = setDurationDAO.findByActivityAndYear( - activity, - year - ); - + result = setDurationDAO.findByActivityAndYear(activity, year); if (result == null) { addWarningMessage( l(getLocale(), "t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound", @@ -288,11 +218,9 @@ public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0A year)); } } - // store it once for all (even if result is null) setDurations.put(key, result); } - return result; } ===================================== t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties ===================================== --- a/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties +++ b/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties @@ -18,7 +18,7 @@ t3.import.warning.on.analyze=%s warnings detected on analyze import db t3.input.AnalyzeInputSource=Data Import\: Analyze t3.input.ImportInputSource=Input Data Import t3.level0.action=Level 0 Operation\: %s -t3.level0.computeActivitySetDurationAndPositiveSetCount=%s, set duration\: %s, positiveSetCount\: %s +t3.level0.computeActivitySetDurationAndPositiveSetCount=%s, set duration\: %s, positiveSetCount\: %s, negativeSetCount \: %s t3.level0.computeRF1.complete.trips.to.use.for.vessel=Found %s complete trip(s) for vessel %s t3.level0.computeRF1.resume.for.complete.trip=Total catches weight %s / Total landing weight %s / Total local market weight %s / Detailled total local market weight %s / RF1 \= %s t3.level0.computeRF1.resume.for.trip=Trip %s, Total catches weight %s / Total landing weight %s / Total local market weight %s / Detailled total local market weight %s ===================================== t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties ===================================== --- a/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties +++ b/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties @@ -18,7 +18,7 @@ t3.import.warning.on.analyze=%s avertissements détectées lors de l'analyse de t3.input.AnalyzeInputSource=Import de données \: Analyse des données t3.input.ImportInputSource=Import de données t3.level0.action=Opération du niveau 0 \: %s -t3.level0.computeActivitySetDurationAndPositiveSetCount=%s, durée de calée \: %s, positiveSetCount \: %s +t3.level0.computeActivitySetDurationAndPositiveSetCount=%s, durée de calée \: %s, positiveSetCount \: %s, negativeSetCount \: %s t3.level0.computeRF1.complete.trips.to.use.for.vessel=%s marée(s) complète(s) trouvées pour le navire %s t3.level0.computeRF1.resume.for.complete.trip=Poids total capturé %s / Poids total vendu %s / Poids marché local résumé %s / Poids marché local détaillé %s / RF1 \= %s t3.level0.computeRF1.resume.for.trip=Marée %s, Poids total capturé %s / Poids total vendu %s / Poids marché local résumé %s / Poids marché local détaillé %s View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/4072de7b084af636430951ea39172719b... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/4072de7b084af636430951ea39172719b... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT