[Git][ultreiaio/ird-t3][develop] [N2][N3] Gestion des catégories de poids -10/+10kg dans la stratification N2 et…
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3 Commits: ea4a2e79 by Tony CHEMIT at 2018-02-21T20:14:49+01:00 [N2][N3] Gestion des catégories de poids -10/+10kg dans la stratification N2 et N3 (Mise en place du lancement d'une action (reste à gerer ça au sein des strates) (See #263) - - - - - 8 changed files: - t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratum.java - t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratum.java - t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2Action.java - t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3CatchStratum.java - t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratum.java - t3-actions/src/main/java/fr/ird/t3/actions/data/level3/Level3Action.java - t3-domain/src/main/java/fr/ird/t3/actions/stratum/Stratum.java - t3-domain/src/main/java/fr/ird/t3/actions/stratum/StratumConfiguration.java Changes: ===================================== t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratum.java ===================================== --- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratum.java +++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratum.java @@ -133,9 +133,7 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti Integer nbZones = e.getValue(); if (!activity.isCorrectedElementaryCatchEmpty()) { - for (CorrectedElementaryCatch aCatch : - activity.getCorrectedElementaryCatch()) { - + for (CorrectedElementaryCatch aCatch : activity.getCorrectedElementaryCatch()) { weightCategoriesForSpecies.put(aCatch.getWeightCategoryTreatment(), aCatch.getSpecies()); } } @@ -155,8 +153,7 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti } } - inputModelForSpeciesToFix = - inputModelForAllSpecies.extractForSpecies(getSpeciesToFix()); + inputModelForSpeciesToFix = inputModelForAllSpecies.extractForSpecies(getSpeciesToFix()); } public int getNbActivitiesWithSample() { @@ -225,12 +222,10 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti } public void mergeGlobalCompositionModels(WeightCompositionAggregateModel inputModel, WeightCompositionAggregateModel outputModel) { - inputModel.addModel(inputModelForAllSpecies); outputModel.addModel(outputModelForAllSpecies); } - @Override protected CatchStratumLoader<Level2Configuration> newLoader() { return new L2CatchStratumLoader(); ===================================== t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratum.java ===================================== --- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratum.java +++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratum.java @@ -145,8 +145,7 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac ActivityTopiaDao.fillWeightsFromSetSpeciesCatWeight(activity, weights, null); // obtain the set species frequencies for the current activity - Collection<SetSpeciesFrequency> setSpeciesFrequencies = - activity.getSetSpeciesFrequency(); + Collection<SetSpeciesFrequency> setSpeciesFrequencies = activity.getSetSpeciesFrequency(); if (CollectionUtils.isNotEmpty(setSpeciesFrequencies)) { ===================================== t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2Action.java ===================================== --- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2Action.java +++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2Action.java @@ -25,7 +25,6 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import fr.ird.t3.actions.T3Action; import fr.ird.t3.actions.stratum.OceanContext; import fr.ird.t3.actions.stratum.StratumConfiguration; @@ -54,6 +53,7 @@ import fr.ird.t3.services.ioc.InjectDAO; import fr.ird.t3.services.ioc.InjectEntitiesById; import fr.ird.t3.services.ioc.InjectFromDAO; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaException; @@ -82,7 +82,6 @@ import static org.nuiton.i18n.I18n.l; */ public class Level2Action extends T3Action<Level2Configuration> { - // public static final String PARAM_LEVEL_CONFIGURATION = "levelConfiguration"; private static final Log log = LogFactory.getLog(Level2Action.class); /** * Cache of activity (to avoid to reload them for catch and sample stratum). @@ -211,72 +210,119 @@ public class Level2Action extends T3Action<Level2Configuration> { Level2Configuration configuration = getConfiguration(); - // get time step - int timeStep = configuration.getTimeStep(); + // keep a track of already used activity ids (to remove previous level 2 data) + Set<String> usedActivityIds = new HashSet<>(); + + boolean useWeightCategoriesInStratum = configuration.isUseWeightCategoriesInStratum(); -// nbStratums = zoneBySchoolType.size() * startDates.size(); - nbStratums = oceanContext.values().stream().mapToInt(OceanContext::sizeZones).sum() * startDates.size(); + if (useWeightCategoriesInStratum) { + executeActionWithCategories(configuration, usedActivityIds); + } else { + executeActionWithoutCategories(configuration, usedActivityIds); + } + return true; + } + + private void executeActionWithCategories(Level2Configuration configuration, Set<String> usedActivityIds) throws Exception { + + nbStratums = 0; + for (SchoolType schoolType : schoolTypes) { + List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType); + Collection<ZoneStratumAware> zones = getZones(schoolType); + nbStratums += startDates.size() * zones.size() * weightCategories.size(); + } setNbSteps(3 * nbStratums); - // keep a track of alreay used activity ids (to remove previous level 2 data) - Set<String> usedActivityIds = new HashSet<>(); + int timeStep = configuration.getTimeStep(); - int stratumIndex = 1; + MutableInt stratumIndex = new MutableInt(1); for (SchoolType schoolType : schoolTypes) { + List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType); + Collection<ZoneStratumAware> zones = getZones(schoolType); + for (ZoneStratumAware zone : zones) { + for (WeightCategoryTreatment weightCategory : weightCategories) { + doIterateOnDates(timeStep, configuration, schoolType, zones, zone, weightCategories, weightCategory, usedActivityIds, stratumIndex); + } + } + } + } + + + private void executeActionWithoutCategories(Level2Configuration configuration, Set<String> usedActivityIds) throws Exception { - // get all weight categories for this school type -// List<WeightCategoryTreatment> weightCategories = Lists.newArrayList(weightCategoriesBySchoolType.get(schoolType)); - List<WeightCategoryTreatment> weightCategories = oceanContext.values().stream().flatMap(o -> o.getWeightCategories(schoolType).stream()).distinct().collect(Collectors.toList()); - weightCategoryTreatmentDAO.sort(weightCategories); + nbStratums = 0; + for (SchoolType schoolType : schoolTypes) { + Collection<ZoneStratumAware> zones = getZones(schoolType); + nbStratums += startDates.size() * zones.size(); + } + setNbSteps(3 * nbStratums); - // get all zones for this school type -// Collection<ZoneStratumAware> zones = zoneBySchoolType.get(schoolType); - Collection<ZoneStratumAware> zones = oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList()); + int timeStep = configuration.getTimeStep(); + MutableInt stratumIndex = new MutableInt(1); + for (SchoolType schoolType : schoolTypes) { + List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType); + Collection<ZoneStratumAware> zones = getZones(schoolType); for (ZoneStratumAware zone : zones) { + doIterateOnDates(timeStep, configuration, schoolType, zones, zone, weightCategories, null, usedActivityIds, stratumIndex); + } + } - for (T3Date startDate : startDates) { - - // get end date (only increments on timseStep - 1 to have - // exactly timstep month from beginDate.toStartDate() to - // endDate.toEndDate() - T3Date endDate = startDate.incrementsMonths(timeStep - 1); - - StratumConfiguration<Level2Configuration> - stratumConfiguration = - StratumConfiguration.newStratumConfiguration( - configuration, - zoneMeta, - zone, - schoolType, - startDate, - endDate, - zones, - possibleCatchVessels, - possibleSampleVessels, - null, - activityCache - ); - - try { - L2StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds); - - stratumsResult.add(result); - } finally { - flushTransaction("After stratum " + stratumIndex); - } + } - stratumIndex++; - } + private List<WeightCategoryTreatment> getWeightCategoryTreatments(SchoolType schoolType) { + List<WeightCategoryTreatment> weightCategoryTreatments = oceanContext.values().stream().flatMap(o -> o.getWeightCategories(schoolType).stream()).distinct().collect(Collectors.toList()); + weightCategoryTreatmentDAO.sort(weightCategoryTreatments); + return weightCategoryTreatments; + } + + private Collection<ZoneStratumAware> getZones(SchoolType schoolType) { + return oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList()); + } + + private void doIterateOnDates(int timeStep, Level2Configuration configuration, SchoolType schoolType, Collection<ZoneStratumAware> zones, ZoneStratumAware zone, List<WeightCategoryTreatment> weightCategories, WeightCategoryTreatment weightCategoryTreatment, Set<String> usedActivityIds, MutableInt stratumIndex) throws Exception { + + for (T3Date startDate : startDates) { + + // get end date (only increments on timseStep - 1 to have + // exactly timstep month from beginDate.toStartDate() to + // endDate.toEndDate() + T3Date endDate = startDate.incrementsMonths(timeStep - 1); + + StratumConfiguration<Level2Configuration> + stratumConfiguration = + StratumConfiguration.newStratumConfiguration( + configuration, + zoneMeta, + zone, + schoolType, + weightCategoryTreatment, + startDate, + endDate, + zones, + possibleCatchVessels, + possibleSampleVessels, + null, + activityCache + ); + + try { + L2StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds); + + stratumsResult.add(result); + } finally { + flushTransaction("After stratum " + stratumIndex); } + + stratumIndex.increment(); } - return true; + } - protected L2StratumResult doExecuteStratum( + private L2StratumResult doExecuteStratum( StratumConfiguration<Level2Configuration> stratumConfiguration, List<WeightCategoryTreatment> weightCategories, - int stratumIndex, + MutableInt stratumIndex, Set<String> usedActivityIds) throws Exception { incrementsProgression(); @@ -353,7 +399,7 @@ public class Level2Action extends T3Action<Level2Configuration> { // Fill back CorrectedElementaryCatch.CatchWeight to CorrectedElementaryCatch.CorrectedCatchWeight int activityIndex = 1; - int nbActivites = catchStratum.getNbActivities(); + int nbActivities = catchStratum.getNbActivities(); for (Map.Entry<Activity, Integer> e : catchStratum) { Activity activity = e.getKey(); @@ -366,7 +412,7 @@ public class Level2Action extends T3Action<Level2Configuration> { doExecuteActivityInCatchStratum(catchStratum, activity, activityIndex++, - nbActivites, + nbActivities, newActivity); // keep the stratum substitution level in the activity @@ -380,7 +426,7 @@ public class Level2Action extends T3Action<Level2Configuration> { // can use this sampleStratum int activityIndex = 1; - int nbActivites = catchStratum.getNbActivities(); + int nbActivities = catchStratum.getNbActivities(); for (Map.Entry<Activity, Integer> e : catchStratum) { Activity activity = e.getKey(); @@ -395,7 +441,7 @@ public class Level2Action extends T3Action<Level2Configuration> { activity, nbZones, activityIndex++, - nbActivites, + nbActivities, newActivity); // keep the stratum substitution level in the activity @@ -432,8 +478,8 @@ public class Level2Action extends T3Action<Level2Configuration> { return result; } - protected L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, - List<WeightCategoryTreatment> weightCategories) throws Exception { + private L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, + List<WeightCategoryTreatment> weightCategories) throws Exception { L2CatchStratum catchStratum = new L2CatchStratum(stratumConfiguration, species); catchStratum.init(serviceContext, weightCategories, this); @@ -463,26 +509,25 @@ public class Level2Action extends T3Action<Level2Configuration> { return catchStratum; } - protected L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, - List<WeightCategoryTreatment> weightCategories, - float totalCatchWeight) throws Exception { + private L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, + List<WeightCategoryTreatment> weightCategories, + float totalCatchWeight) throws Exception { L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, species, totalCatchWeight); sampleStratum.init(serviceContext, weightCategories, this); return sampleStratum; } - protected void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum, - L2SampleStratum sampleStratum, - Activity activity, - int nbZones, - int activityIndex, - int nbActivites, - boolean deleteOldData) throws TopiaException, IOException { + private void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum, + L2SampleStratum sampleStratum, + Activity activity, + int nbZones, + int activityIndex, + int nbActivities, + boolean deleteOldData) throws TopiaException, IOException { - String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), - DecoratorService.WITH_ID)); + String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID)); - String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivites, activityStr, nbZones); + String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivities, activityStr, nbZones); if (log.isInfoEnabled()) { log.info(message); } @@ -503,7 +548,6 @@ public class Level2Action extends T3Action<Level2Configuration> { WeightCompositionAggregateModel catchWeightModelForSpeciesToFix = catchWeightModelForAllSpecies.extractForSpecies(species); - // log catches weight message = logCatchWeight(getDecoratorService(), catchWeightModelForAllSpecies, catchWeightModelForSpeciesToFix); if (log.isInfoEnabled()) { @@ -571,15 +615,15 @@ public class Level2Action extends T3Action<Level2Configuration> { } - protected void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum, - Activity activity, - int activityIndex, - int nbActivites, - boolean deleteOldData) throws TopiaException, IOException { + private void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum, + Activity activity, + int activityIndex, + int nbActivities, + boolean deleteOldData) throws TopiaException, IOException { String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID)); - String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivites, activityStr, 1); + String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivities, activityStr, 1); if (log.isInfoEnabled()) { log.info(message); } @@ -631,7 +675,7 @@ public class Level2Action extends T3Action<Level2Configuration> { compositionModel.close(); } - protected void applySampleSpecificComposition(L2CatchStratum catchStratum, Activity activity) throws TopiaException { + private void applySampleSpecificComposition(L2CatchStratum catchStratum, Activity activity) throws TopiaException { WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel(); @@ -675,11 +719,11 @@ public class Level2Action extends T3Action<Level2Configuration> { } - protected void applySampleSpecificComposition(L2CatchStratum catchStratum, - Activity activity, - int nbZones, - WeightCompositionAggregateModel sampleCompositionModel, - WeightCompositionAggregateModel correctedCatchesForSpeciesToFix) throws TopiaException { + private void applySampleSpecificComposition(L2CatchStratum catchStratum, + Activity activity, + int nbZones, + WeightCompositionAggregateModel sampleCompositionModel, + WeightCompositionAggregateModel correctedCatchesForSpeciesToFix) throws TopiaException { WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel(); @@ -692,8 +736,7 @@ public class Level2Action extends T3Action<Level2Configuration> { Map<Species, Float> weights = new HashMap<>(); // get composition model to use - WeightCompositionModel model = - sampleCompositionModel.getModel(weightCategory); + WeightCompositionModel model = sampleCompositionModel.getModel(weightCategory); // set of species still to fix Set<Species> speciesToFix; @@ -721,10 +764,9 @@ public class Level2Action extends T3Action<Level2Configuration> { speciesToFix = model.getSpecies(); - speciesStillToFix = Sets.newHashSet(speciesToFix); + speciesStillToFix = new HashSet<>(speciesToFix); - totalWeight = correctedCatchesForSpeciesToFix.getModel( - weightCategory).getTotalWeight(); + totalWeight = correctedCatchesForSpeciesToFix.getModel(weightCategory).getTotalWeight(); } // divide the total weight to used by the number of zones of this @@ -734,8 +776,7 @@ public class Level2Action extends T3Action<Level2Configuration> { // Apply on all existing corrected catch weight - for (CorrectedElementaryCatch aCatch : - correctedElementaryCatches.get(weightCategory)) { + for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) { Species speciesToUse = aCatch.getSpecies(); @@ -789,8 +830,7 @@ public class Level2Action extends T3Action<Level2Configuration> { float correctedCatchWeight = totalWeight * weightRate; // create new record - CorrectedElementaryCatch aCatch = - correctedElementaryCatchDAO.create(); + CorrectedElementaryCatch aCatch = correctedElementaryCatchDAO.create(); aCatch.setSpecies(speciesToUse); aCatch.setWeightCategoryTreatment(weightCategory); aCatch.setCatchWeight(0f); @@ -809,8 +849,7 @@ public class Level2Action extends T3Action<Level2Configuration> { } // log corrected catches weight - String message = logCorrectedCatchWeight(correctedCatchWeightModel, - getDecoratorService()); + String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService()); if (log.isInfoEnabled()) { log.info(message); } @@ -828,10 +867,6 @@ public class Level2Action extends T3Action<Level2Configuration> { this.schoolTypes = schoolTypes; } -// public void setZoneBySchoolType(Multimap<SchoolType, ZoneStratumAware> zoneBySchoolType) { -// this.zoneBySchoolType = zoneBySchoolType; -// } - public void setSpecies(Set<Species> species) { this.species = species; } @@ -840,10 +875,6 @@ public class Level2Action extends T3Action<Level2Configuration> { this.startDates = startDates; } -// public void setWeightCategoriesBySchoolType(Multimap<SchoolType, WeightCategoryTreatment> weightCategoriesBySchoolType) { -// this.weightCategoriesBySchoolType = weightCategoriesBySchoolType; -// } - public void setPossibleCatchVessels(Set<Vessel> possibleCatchVessels) { this.possibleCatchVessels = possibleCatchVessels; } @@ -921,8 +952,7 @@ public class Level2Action extends T3Action<Level2Configuration> { public String getInputCatchStratumLog() { - WeightCompositionAggregateModel inputCatchModelForSpeciesToFix = - inputCatchModelForAllSpecies.extractForSpecies(species); + WeightCompositionAggregateModel inputCatchModelForSpeciesToFix = inputCatchModelForAllSpecies.extractForSpecies(species); String title = l(locale, "t3.level2.message.strateInputGlobalComposition.resume"); @@ -936,8 +966,7 @@ public class Level2Action extends T3Action<Level2Configuration> { public String getOutputCatchStratumLog() { - WeightCompositionAggregateModel outputCatchModelForSpeciesToFix = - outputCatchModelForAllSpecies.extractForSpecies(species); + WeightCompositionAggregateModel outputCatchModelForSpeciesToFix = outputCatchModelForAllSpecies.extractForSpecies(species); String title = l(locale, "t3.level2.message.strateOutputGlobalComposition.resume"); @@ -959,10 +988,6 @@ public class Level2Action extends T3Action<Level2Configuration> { protected String logCatchWeight(DecoratorService decoratorService, WeightCompositionAggregateModel modelForAllSpecies, WeightCompositionAggregateModel modelForSpeciesToFix) { -// -// WeightCompositionAggregateModel modelForAllSpecies = catchesWeightForAllSpecies.get(activity); -// WeightCompositionAggregateModel modelForSpeciesToFix = -// getCatchesWeightForSpeciesToFix(activity); String title = l(locale, "t3.level2.message.activityCatchWeight.resume", modelForAllSpecies.getTotalModel().getTotalWeight(), @@ -978,8 +1003,7 @@ public class Level2Action extends T3Action<Level2Configuration> { public String logCorrectedCatchWeight(WeightCompositionAggregateModel correctedCatchWeightModel, DecoratorService decoratorService) { - WeightCompositionAggregateModel modelForSpeciesToFix = - correctedCatchWeightModel.extractForSpecies(species); + WeightCompositionAggregateModel modelForSpeciesToFix = correctedCatchWeightModel.extractForSpecies(species); String title = l(locale, "t3.level2.message.activityCorrectedCatchWeight.resume", @@ -997,11 +1021,6 @@ public class Level2Action extends T3Action<Level2Configuration> { WeightCompositionAggregateModel modelForSpeciestoFix, DecoratorService decoratorService) { -// WeightCompositionAggregateModel modelForAllSpecies = specificActivityForAllSpeciesModels.get(activity); -// -// WeightCompositionAggregateModel modelForSpeciestoFix = -// getSpecificCompositionForSpeciesToFix(activity); - String title = l(locale, "t3.level2.message.activityComposition.resume", modelForAllSpecies.getTotalModel().getTotalWeight(), modelForSpeciestoFix.getTotalModel().getTotalWeight()); ===================================== t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3CatchStratum.java ===================================== --- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3CatchStratum.java +++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3CatchStratum.java @@ -53,7 +53,7 @@ public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Acti * * @since 1.3.1 */ - private float totalCatchtWeight; + private float totalCatchWeight; /** * Predicate to filter only species selected in configuration. @@ -85,7 +85,7 @@ public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Acti int nbZones = e.getValue(); // compute total catch weight of the activity (only for species to fix) - totalCatchtWeight += + totalCatchWeight += T3EntityHelper.getTotal( activity.getCorrectedElementaryCatch(), T3Functions.CORRECTED_ELEMENTARY_CATCH_TO_CORRECTED_CATCH_WEIGHT, @@ -118,7 +118,7 @@ public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Acti * @return total catch weight of selected catches for this stratum. */ public float getTotalCatchWeight() { - return totalCatchtWeight; + return totalCatchWeight; } } ===================================== t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratum.java ===================================== --- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratum.java +++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratum.java @@ -24,7 +24,6 @@ import com.google.common.base.Predicate; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; -import com.google.common.collect.Sets; import fr.ird.t3.T3IOUtil; import fr.ird.t3.actions.stratum.SampleStratum; import fr.ird.t3.actions.stratum.StratumConfiguration; @@ -48,6 +47,7 @@ import org.nuiton.topia.persistence.TopiaException; import java.io.IOException; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -182,7 +182,7 @@ public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Ac Multimaps.index(activity.getSetSpeciesFrequency(), T3Functions.SPECIES_AWARE_BY_SPECIES); // get species found (and only the one to use) - Set<Species> speciesFound = Sets.newHashSet(setSpeciesFrequenciesBySpecies.keySet()); + Set<Species> speciesFound = new HashSet<>(setSpeciesFrequenciesBySpecies.keySet()); speciesFound.retainAll(getSpeciesToFix()); // add missing empty model @@ -220,8 +220,7 @@ public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Ac allSetSpeciesFrequenciesBySpecies, compositionModel, weightCategories, - conversionHelper - ); + conversionHelper); } public float getCatchStratumTotalWeight() { ===================================== t3-actions/src/main/java/fr/ird/t3/actions/data/level3/Level3Action.java ===================================== --- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level3/Level3Action.java +++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level3/Level3Action.java @@ -72,6 +72,7 @@ import fr.ird.t3.services.ioc.InjectEntitiesById; import fr.ird.t3.services.ioc.InjectEntityById; import fr.ird.t3.services.ioc.InjectFromDAO; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaException; @@ -85,6 +86,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -207,32 +209,13 @@ public class Level3Action extends T3Action<Level3Configuration> { configuration.setLocale(getLocale()); // get zones type meta to use - setZoneMeta( - newService(ZoneStratumService.class).getZoneMetaById(configuration.getZoneTypeId())); + setZoneMeta(newService(ZoneStratumService.class).getZoneMetaById(configuration.getZoneTypeId())); setZoneVersion(zoneMeta.getZoneVersion(configuration.getZoneVersionId(), getT3TopiaPersistenceContext().get())); -// // get all zones by ocean and shcool types -// setZoneBySchoolType( -// zoneMeta.getZones( -// ocean, -// schoolTypes, -// zoneVersion, -// getT3TopiaPersistenceContext().get() -// ) -// ); - // get start dates to use setStartDates(T3Date.getStartDates(configuration.getBeginDate(), configuration.getEndDate(), configuration.getTimeStep())); -// // get weight categories to use (group by school type) -// setWeightCategoriesBySchoolType( -// weightCategoryTreatmentDAO.getWeightCategories( -// ocean, -// schoolTypes -// ) -// ); - Date toBeginDate = configuration.getBeginDate().toBeginDate(); for (Ocean ocean : oceans) { oceanContext.put(ocean.getTopiaId(), new OceanContext( @@ -251,9 +234,7 @@ public class Level3Action extends T3Action<Level3Configuration> { // get possible vessels for sample stratum setPossibleSampleVessels(vesselDAO.getPossibleSampleVessels(sampleFleets, sampleFlags)); -// conversionHelper = lengthWeightConversionDAO.newConversionHelper(ocean, 0, toBeginDate); - - stratumsResult = Sets.newLinkedHashSet(); + stratumsResult = new LinkedHashSet<>(); topiaCreateDate = new SimpleDateFormat("yyyy-MM-dd").format(serviceContext.getCurrentDate()); @@ -306,8 +287,6 @@ public class Level3Action extends T3Action<Level3Configuration> { super.finalizeAction(); } -// Map<String, Integer> hitActivities = new TreeMap<>(); - @Override protected boolean executeAction() throws Exception { @@ -315,88 +294,133 @@ public class Level3Action extends T3Action<Level3Configuration> { Level3Configuration configuration = getConfiguration(); - // get time step - int timeStep = configuration.getTimeStep(); + // keep a track of already used activity ids (to remove previous level 2 data) + Set<String> usedActivityIds = new HashSet<>(); -// nbStratums = zoneBySchoolType.size() * startDates.size(); - nbStratums = oceanContext.values().stream().mapToInt(OceanContext::sizeZones).sum() * startDates.size(); + boolean useWeightCategoriesInStratum = configuration.isUseWeightCategoriesInStratum(); + + if (useWeightCategoriesInStratum) { + executeActionWithCategories(configuration, usedActivityIds); + } else { + executeActionWithoutCategories(configuration, usedActivityIds); + } + return true; + } + + private void executeActionWithCategories(Level3Configuration configuration, Set<String> usedActivityIds) throws Exception { + + nbStratums = 0; + for (SchoolType schoolType : schoolTypes) { + List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType); + Collection<ZoneStratumAware> zones = getZones(schoolType); + nbStratums += startDates.size() * zones.size() * weightCategories.size(); + } setNbSteps(3 * nbStratums); - // keep a track of alreay used activity ids (to remove previous level 3 data) - Set<String> usedActivityIds = new HashSet<>(); + int timeStep = configuration.getTimeStep(); - int stratumIndex = 0; + MutableInt stratumIndex = new MutableInt(1); for (SchoolType schoolType : schoolTypes) { + Map<String, Integer> stratumMinimumCountBySpecie = stratumMinimumSampleCountBySchoolType.get(schoolType); + List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType); + Collection<ZoneStratumAware> zones = getZones(schoolType); + for (ZoneStratumAware zone : zones) { + for (WeightCategoryTreatment weightCategory : weightCategories) { + doIterateOnDates(timeStep, configuration, schoolType, zones, zone, weightCategories, weightCategory, usedActivityIds, stratumIndex, stratumMinimumCountBySpecie); + } + } + } + } - // get all weight categories for this school type -// List<WeightCategoryTreatment> weightCategories = Lists.newArrayList(weightCategoriesBySchoolType.get(schoolType)); - List<WeightCategoryTreatment> weightCategories = oceanContext.values().stream().flatMap(o -> o.getWeightCategories(schoolType).stream()).distinct().collect(Collectors.toList()); - weightCategoryTreatmentDAO.sort(weightCategories); + private void executeActionWithoutCategories(Level3Configuration configuration, Set<String> usedActivityIds) throws Exception { - // get all zones for this school type -// Collection<ZoneStratumAware> zones = zoneBySchoolType.get(schoolType); - List<ZoneStratumAware> zones = oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList()); + nbStratums = 0; + for (SchoolType schoolType : schoolTypes) { + Collection<ZoneStratumAware> zones = getZones(schoolType); + nbStratums += startDates.size() * zones.size(); + } + setNbSteps(3 * nbStratums); - // get minimum stratum count by species - Map<String, Integer> stratumMinimumCountBySpecie = stratumMinimumSampleCountBySchoolType.get(schoolType); + int timeStep = configuration.getTimeStep(); + MutableInt stratumIndex = new MutableInt(1); + for (SchoolType schoolType : schoolTypes) { + Map<String, Integer> stratumMinimumCountBySpecie = stratumMinimumSampleCountBySchoolType.get(schoolType); + List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType); + Collection<ZoneStratumAware> zones = getZones(schoolType); for (ZoneStratumAware zone : zones) { + doIterateOnDates(timeStep, configuration, schoolType, zones, zone, weightCategories, null, usedActivityIds, stratumIndex, stratumMinimumCountBySpecie); + } + } + } - for (T3Date startDate : startDates) { - - // get end date (only increments on timseStep - 1 to have - // exactly timstep month from beginDate.toStartDate() to - // endDate.toEndDate() - T3Date endDate = startDate.incrementsMonths(timeStep - 1); - - // clear query buffer - queryBuffer = new StringBuilder(); - nbQuery = 0; - - StratumConfiguration<Level3Configuration> - stratumConfiguration = - StratumConfiguration.newStratumConfiguration( - configuration, - zoneMeta, - zone, - schoolType, - startDate, - endDate, - zones, - possibleCatchVessels, - possibleSampleVessels, - stratumMinimumCountBySpecie, - activityCache); - - try { - L3StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds); - stratumsResult.add(result); - } finally { - - // first flush delete previous level 3 data - flushTransaction("Flush delete level 3 data."); - - // flush then new data - long s0 = TimeLog.getTime(); - if (nbQuery > 0) { - if (log.isInfoEnabled()) { - log.info(String.format("Will flush %d queries.", nbQuery)); - } - getT3TopiaPersistenceContext().get().getSqlSupport().executeSql(queryBuffer.toString()); - } - getTimeLog().log(s0, "Execute queries"); + private List<WeightCategoryTreatment> getWeightCategoryTreatments(SchoolType schoolType) { + List<WeightCategoryTreatment> weightCategoryTreatments = oceanContext.values().stream().flatMap(o -> o.getWeightCategories(schoolType).stream()).distinct().collect(Collectors.toList()); + weightCategoryTreatmentDAO.sort(weightCategoryTreatments); + return weightCategoryTreatments; + } + + private Collection<ZoneStratumAware> getZones(SchoolType schoolType) { + return oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList()); + } + + private void doIterateOnDates(int timeStep, Level3Configuration configuration, SchoolType schoolType, Collection<ZoneStratumAware> zones, ZoneStratumAware zone, List<WeightCategoryTreatment> weightCategories, WeightCategoryTreatment weightCategoryTreatment, Set<String> usedActivityIds, MutableInt stratumIndex, Map<String, Integer> stratumMinimumCountBySpecie) throws Exception { + + for (T3Date startDate : startDates) { + + // clear query buffer + queryBuffer = new StringBuilder(); + nbQuery = 0; + + // get end date (only increments on timeStep - 1 to have + // exactly timeStep month from beginDate.toStartDate() to endDate.toEndDate() + T3Date endDate = startDate.incrementsMonths(timeStep - 1); + + StratumConfiguration<Level3Configuration> + stratumConfiguration = + StratumConfiguration.newStratumConfiguration( + configuration, + zoneMeta, + zone, + schoolType, + weightCategoryTreatment, + startDate, + endDate, + zones, + possibleCatchVessels, + possibleSampleVessels, + stratumMinimumCountBySpecie, + activityCache + ); + + try { + L3StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds); + stratumsResult.add(result); + } finally { + + // first flush delete previous level 3 data + flushTransaction("Flush delete level 3 data."); + + // flush then new data + long s0 = TimeLog.getTime(); + if (nbQuery > 0) { + if (log.isInfoEnabled()) { + log.info(String.format("Will flush %d queries.", nbQuery)); } - stratumIndex++; + getT3TopiaPersistenceContext().get().getSqlSupport().executeSql(queryBuffer.toString()); } + getTimeLog().log(s0, "Execute queries"); } + + stratumIndex.increment(); } - return true; + } - protected L3StratumResult doExecuteStratum(StratumConfiguration<Level3Configuration> conf, - List<WeightCategoryTreatment> weightCategories, - int stratumIndex, - Set<String> usedActivityIds) throws Exception { + private L3StratumResult doExecuteStratum(StratumConfiguration<Level3Configuration> conf, + List<WeightCategoryTreatment> weightCategories, + MutableInt stratumIndex, + Set<String> usedActivityIds) throws Exception { incrementsProgression(); @@ -488,7 +512,7 @@ public class Level3Action extends T3Action<Level3Configuration> { addInfoMessage(message); int activityIndex = 1; - int nbActivites = catchStratum.getNbActivities(); + int nbActivities = catchStratum.getNbActivities(); for (Map.Entry<Activity, Integer> e : catchStratum) { Activity activity = e.getKey(); @@ -499,13 +523,6 @@ public class Level3Action extends T3Action<Level3Configuration> { boolean newActivity = usedActivityIds.add(activity.getTopiaId()); if (!newActivity) { Preconditions.checkState(nbZones > 1, "Only a multi-zone activity can be seen more tha once!, problem with activity: " + activity.getTopiaId()); - -// // mark it -// Integer nb = hitActivities.get(activity.getTopiaId()); -// if (nb == null) { -// nb = 0; -// } -// hitActivities.put(activity.getTopiaId(), nb + 1); } OceanContext oceanContext = this.oceanContext.get(activity.getOcean().getTopiaId()); @@ -518,10 +535,9 @@ public class Level3Action extends T3Action<Level3Configuration> { nbZones, activityIndex++, weightCategories, - nbActivites, + nbActivities, newActivity, - result.getTotalFishesCount() - ); + result.getTotalFishesCount()); // keep the stratum substitution level in the activity activity.setStratumLevelN3(level); @@ -554,8 +570,7 @@ public class Level3Action extends T3Action<Level3Configuration> { l(locale, "t3.level3.catchStratum.nbFishesResume.title"), totalFishesCountModel.extractForSpecies(species), BEFORE_LEVEL3, - AFTER_LEVEL3 - ); + AFTER_LEVEL3); if (log.isInfoEnabled()) { log.info(message); @@ -584,42 +599,32 @@ public class Level3Action extends T3Action<Level3Configuration> { totalFishesCountModel.addValues(AFTER_LEVEL3, activity.getExtrapolatedAllSetSpeciesFrequency()); } - protected void doExecuteActivityInCatchStratum(L3CatchStratum catchStratum, - L3SampleStratum sampleStratum, - Activity activity, - OceanContext oceanContext, - int nbZones, - int activityIndex, - List<WeightCategoryTreatment> weightCategories, - int nbActivites, - boolean deleteOldData, - SpeciesCountAggregateModel totalFishesCount) throws TopiaException { + private void doExecuteActivityInCatchStratum(L3CatchStratum catchStratum, + L3SampleStratum sampleStratum, + Activity activity, + OceanContext oceanContext, + int nbZones, + int activityIndex, + List<WeightCategoryTreatment> weightCategories, + int nbActivities, + boolean deleteOldData, + SpeciesCountAggregateModel totalFishesCount) throws TopiaException { String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID)); - String message = l(locale, "t3.level3.message.start.activity", activityIndex, nbActivites, activityStr, nbZones); + String message = l(locale, "t3.level3.message.start.activity", activityIndex, nbActivities, activityStr, nbZones); if (log.isInfoEnabled()) { log.info(message); } addInfoMessage(message); - // to deal with muli-zone activities (must keep a track of what was - // already odne) + // to deal with multiple-zone activities (must keep a track of what was already done) Map<String, String> previousValues; boolean activityMultiZone = nbZones > 1; if (activityMultiZone) { - - // get previous values - previousValues = activityWithMultiZones.get(activity.getTopiaId()); - - if (previousValues == null) { - - // create previous values - activityWithMultiZones.put(activity.getTopiaId(), previousValues = new HashMap<>()); - } - + previousValues = activityWithMultiZones.computeIfAbsent(activity.getTopiaId(), k -> new HashMap<>()); } else { previousValues = null; } @@ -630,7 +635,6 @@ public class Level3Action extends T3Action<Level3Configuration> { if (log.isDebugEnabled()) { log.debug(String.format("Delete previous level3 data of %s :: %d", activity.getTopiaId(), activity.sizeExtrapolatedAllSetSpeciesFrequency())); } -// addDeleteQuery(activity); activity.deleteComputedDataLevel3(); } @@ -673,7 +677,6 @@ public class Level3Action extends T3Action<Level3Configuration> { message = l(locale, "t3.level3.message.activity.with.no.sample.useSampleStratum.composition", activityStr); } - if (log.isInfoEnabled()) { log.info(message); } @@ -766,13 +769,13 @@ public class Level3Action extends T3Action<Level3Configuration> { } } - protected void generateFrequencies(Activity activity, - Species aSpecies, - Map<String, String> previousValues, - LengthCompositionModel model, - float totalWeight, - SpeciesCountModel speciesCountModel, - LengthWeightConversion conversions) { + private void generateFrequencies(Activity activity, + Species aSpecies, + Map<String, String> previousValues, + LengthCompositionModel model, + float totalWeight, + SpeciesCountModel speciesCountModel, + LengthWeightConversion conversions) { // get all length classes involved Set<Integer> lengthClasses = model.getLengthClasses(); @@ -803,8 +806,8 @@ public class Level3Action extends T3Action<Level3Configuration> { } - protected L3CatchStratum newCatchStratum(StratumConfiguration<Level3Configuration> stratumConfiguration, - List<WeightCategoryTreatment> weightCategories) throws Exception { + private L3CatchStratum newCatchStratum(StratumConfiguration<Level3Configuration> stratumConfiguration, + List<WeightCategoryTreatment> weightCategories) throws Exception { L3CatchStratum catchStratum = new L3CatchStratum(stratumConfiguration, species, speciesToFixFilter); catchStratum.init(serviceContext, weightCategories, this); // get the total weight of the catch stratum @@ -833,10 +836,10 @@ public class Level3Action extends T3Action<Level3Configuration> { return catchStratum; } - protected L3SampleStratum newSampleStratum(StratumConfiguration<Level3Configuration> stratumConfiguration, - List<WeightCategoryTreatment> weightCategories, - float totalCatchWeight, - LengthWeightConversionHelper conversionHelper) throws Exception { + private L3SampleStratum newSampleStratum(StratumConfiguration<Level3Configuration> stratumConfiguration, + List<WeightCategoryTreatment> weightCategories, + float totalCatchWeight, + LengthWeightConversionHelper conversionHelper) throws Exception { L3SampleStratum sampleStratum = new L3SampleStratum(stratumConfiguration, species, @@ -847,26 +850,13 @@ public class Level3Action extends T3Action<Level3Configuration> { return sampleStratum; } - protected void addInsertOrUpdateQuery(Activity activity, - Map<String, String> previousValues, - Species species, - int lengthClass, - float number, - SpeciesCountModel speciesCountModel) { + private void addInsertOrUpdateQuery(Activity activity, Map<String, String> previousValues, Species species, int lengthClass, float number, SpeciesCountModel speciesCountModel) { String key = species.getTopiaId() + "__" + lengthClass; String oldId = previousValues == null ? null : previousValues.get(key); String query; if (oldId == null) { - // check unique key - String uniqueKey = activity.getTopiaId() + "__" + key; - -// if (!insertCache.add(uniqueKey)) { -// -// // key already used!!! -// throw new IllegalStateException("Tuple (" + uniqueKey + ") already used!"); -// } // insert query TopiaIdFactory topiaIdFactory = getActionContext().getApplicationContext().getConfiguration().getTopiaIdFactory(); String newId = topiaIdFactory.newTopiaId(ExtrapolatedAllSetSpeciesFrequency.class, "" + System.nanoTime()); @@ -906,10 +896,6 @@ public class Level3Action extends T3Action<Level3Configuration> { this.schoolTypes = schoolTypes; } -// public void setZoneBySchoolType(Multimap<SchoolType, ZoneStratumAware> zoneBySchoolType) { -// this.zoneBySchoolType = zoneBySchoolType; -// } - public void setSpecies(Set<Species> species) { this.species = species; } @@ -918,10 +904,6 @@ public class Level3Action extends T3Action<Level3Configuration> { this.startDates = startDates; } -// public void setWeightCategoriesBySchoolType(Multimap<SchoolType, WeightCategoryTreatment> weightCategoriesBySchoolType) { -// this.weightCategoriesBySchoolType = weightCategoriesBySchoolType; -// } - public void setPossibleCatchVessels(Set<Vessel> possibleCatchVessels) { this.possibleCatchVessels = possibleCatchVessels; } ===================================== t3-domain/src/main/java/fr/ird/t3/actions/stratum/Stratum.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/actions/stratum/Stratum.java +++ b/t3-domain/src/main/java/fr/ird/t3/actions/stratum/Stratum.java @@ -46,13 +46,12 @@ import java.util.Set; public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends T3Action<C>> implements Closeable, Iterable<Map.Entry<Activity, Integer>> { /** - * All activities selected for this stratum, with for catch satratum the - * number of zones where the activty should be used. + * All activities selected for this stratum, with for catch stratum the number of zones where the activity should be used. * <p/> * see http://forge.codelutin.com/issues/1935 * <p/> * <strong>Note:</strong> This data are available after invocation of method - * {@link Stratum#init(T3ServiceContext, List, T3Action}. + * {@link Stratum#init(T3ServiceContext, List, T3Action)}. */ private Map<Activity, Integer> activities; @@ -85,8 +84,7 @@ public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends return activities.entrySet().iterator(); } - protected Stratum(StratumConfiguration<C> configuration, - Collection<Species> speciesToFix) { + protected Stratum(StratumConfiguration<C> configuration, Collection<Species> speciesToFix) { this.configuration = configuration; this.speciesToFix = ImmutableSet.copyOf(speciesToFix); } @@ -130,9 +128,7 @@ public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends protected void checkInitMethodInvoked(Object data) { if (data == null) { - throw new IllegalStateException( - "You must invoke the #init(tx) method before accessing " + - "stratum data."); + throw new IllegalStateException("You must invoke the #init(tx) method before accessing stratum data."); } } } ===================================== t3-domain/src/main/java/fr/ird/t3/actions/stratum/StratumConfiguration.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/actions/stratum/StratumConfiguration.java +++ b/t3-domain/src/main/java/fr/ird/t3/actions/stratum/StratumConfiguration.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% @@ -24,9 +24,11 @@ import com.google.common.cache.LoadingCache; import fr.ird.t3.entities.data.Activity; import fr.ird.t3.entities.reference.SchoolType; import fr.ird.t3.entities.reference.Vessel; +import fr.ird.t3.entities.reference.WeightCategoryTreatment; import fr.ird.t3.entities.reference.zone.ZoneStratumAware; import fr.ird.t3.entities.reference.zone.ZoneStratumAwareMeta; import fr.ird.t3.entities.type.T3Date; + import java.util.Collection; import java.util.Iterator; import java.util.Map; @@ -41,33 +43,68 @@ import java.util.concurrent.ExecutionException; */ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { + private final C configuration; + private final Collection<ZoneStratumAware> zones; + private final ZoneStratumAwareMeta zoneMeta; + private final ZoneStratumAware zone; + private final SchoolType schoolType; + private final WeightCategoryTreatment weightCategoryTreatment; + private final T3Date beginDate; + private final T3Date endDate; + private final Set<Vessel> possibleCatchVessels; + private final Set<Vessel> possibleSampleVessels; + private final Map<String, Integer> stratumMinimumCountBySpecie; + private final LoadingCache<String, Activity> activityCache; + private String[] zoneIds; + + protected StratumConfiguration(C configuration, + ZoneStratumAwareMeta zoneMeta, + ZoneStratumAware zone, + SchoolType schoolType, + WeightCategoryTreatment weightCategoryTreatment, T3Date beginDate, + T3Date endDate, + Collection<ZoneStratumAware> zones, + Set<Vessel> possibleCatchVessels, + Set<Vessel> possibleSampleVessels, + Map<String, Integer> stratumMinimumCountBySpecie, + LoadingCache<String, Activity> activityCache) { + this.configuration = configuration; + this.zoneMeta = zoneMeta; + this.zone = zone; + this.schoolType = schoolType; + this.weightCategoryTreatment = weightCategoryTreatment; + this.beginDate = beginDate; + this.endDate = endDate; + this.zones = zones; + this.possibleCatchVessels = possibleCatchVessels; + this.possibleSampleVessels = possibleSampleVessels; + this.stratumMinimumCountBySpecie = stratumMinimumCountBySpecie; + this.activityCache = activityCache; + } + /** * Obtain a new stratum configuration given all his parameters. * + * @param <C> type of configuration * @param conf the level action configuration * @param zoneMeta type of zone to use * @param zone the zone of the stratum * @param schoolType the school type of the stratum + * @param weightCategoryTreatment the weight category of the stratum (not nul only if {@link LevelConfigurationWithStratum#isUseWeightCategoriesInStratum()} is {@code true}. * @param startDate the start date of the stratum * @param endDate the end date of the stratum - * @param zones all the zones useables by the level - * action which used this stratum (can - * be used for sample stratum substitution) - * @param possibleCatchVessels set of possible vessels to use when - * selecting data in the catch stratum - * @param possibleSampleVessels set of possible vessels to use when - * selecting data in the sample stratum - * @param stratumMinimumCountBySpecie minimum sample count needed by species - * for sample stratum substitution - * @param <C> type of configuration - * @return the new instanciated stratum configuration + * @param zones all the zones useable by the level action which used this stratum (can be used for sample stratum substitution) + * @param possibleCatchVessels set of possible vessels to use when selecting data in the catch stratum + * @param possibleSampleVessels set of possible vessels to use when selecting data in the sample stratum + * @param stratumMinimumCountBySpecie minimum sample count needed by species for sample stratum substitution + * @return the new instantiated stratum configuration */ public static <C extends LevelConfigurationWithStratum> StratumConfiguration<C> newStratumConfiguration( C conf, ZoneStratumAwareMeta zoneMeta, ZoneStratumAware zone, SchoolType schoolType, - T3Date startDate, + WeightCategoryTreatment weightCategoryTreatment, T3Date startDate, T3Date endDate, Collection<ZoneStratumAware> zones, Set<Vessel> possibleCatchVessels, @@ -75,11 +112,12 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { Map<String, Integer> stratumMinimumCountBySpecie, LoadingCache<String, Activity> activityCache) { - return new StratumConfiguration<C>( + return new StratumConfiguration<>( conf, zoneMeta, zone, schoolType, + weightCategoryTreatment, startDate, endDate, zones, @@ -89,54 +127,6 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { activityCache); } - private final C configuration; - - private final ZoneStratumAwareMeta zoneMeta; - - private final ZoneStratumAware zone; - - private final Collection<ZoneStratumAware> zones; - - private String[] zoneIds; - - private final SchoolType schoolType; - - private final T3Date beginDate; - - private final T3Date endDate; - - private final Set<Vessel> possibleCatchVessels; - - private final Set<Vessel> possibleSampleVessels; - - private final Map<String, Integer> stratumMinimumCountBySpecie; - - private final LoadingCache<String, Activity> activityCache; - - protected StratumConfiguration(C configuration, - ZoneStratumAwareMeta zoneMeta, - ZoneStratumAware zone, - SchoolType schoolType, - T3Date beginDate, - T3Date endDate, - Collection<ZoneStratumAware> zones, - Set<Vessel> possibleCatchVessels, - Set<Vessel> possibleSampleVessels, - Map<String, Integer> stratumMinimumCountBySpecie, - LoadingCache<String, Activity> activityCache) { - this.configuration = configuration; - this.zoneMeta = zoneMeta; - this.zone = zone; - this.schoolType = schoolType; - this.beginDate = beginDate; - this.endDate = endDate; - this.zones = zones; - this.possibleCatchVessels = possibleCatchVessels; - this.possibleSampleVessels = possibleSampleVessels; - this.stratumMinimumCountBySpecie = stratumMinimumCountBySpecie; - this.activityCache = activityCache; - } - public C getConfiguration() { return configuration; } @@ -181,6 +171,10 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { return stratumMinimumCountBySpecie; } + public WeightCategoryTreatment getWeightCategoryTreatment() { + return weightCategoryTreatment; + } + public String[] getZoneIds() { if (zoneIds == null) { Collection<ZoneStratumAware> allZones = getZones(); @@ -204,8 +198,6 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { @Override public String toString() { - return super.toString() + " [schooltype: " + schoolType.getLabel1() + - ", zone: " + zone.getTopiaId() + ", startDate:" + - beginDate + ", endDate:" + endDate + "]"; + return String.format("%s [schoolType: %s, zone: %s, startDate:%s, endDate:%s, weightCategory: %s]", super.toString(), schoolType.getLabel1(), zone.getTopiaId(), beginDate, endDate, weightCategoryTreatment); } } View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/ea4a2e79d10126ad158b77d01c5379333... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/ea4a2e79d10126ad158b77d01c5379333... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT