Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3

Commits:

29 changed files:

Changes:

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratum.java
    ... ... @@ -23,13 +23,9 @@ package fr.ird.t3.actions.data.level2;
    23 23
     import com.google.common.collect.HashMultimap;
    
    24 24
     import com.google.common.collect.Multimap;
    
    25 25
     import com.google.common.collect.SetMultimap;
    
    26
    -import fr.ird.t3.T3IOUtil;
    
    27 26
     import fr.ird.t3.actions.stratum.CatchStratum;
    
    28
    -import fr.ird.t3.actions.stratum.CatchStratumLoader;
    
    29
    -import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    30 27
     import fr.ird.t3.entities.data.Activity;
    
    31 28
     import fr.ird.t3.entities.data.CorrectedElementaryCatch;
    
    32
    -import fr.ird.t3.entities.data.WeightCategoryTreatmentAware;
    
    33 29
     import fr.ird.t3.entities.reference.Species;
    
    34 30
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    35 31
     import fr.ird.t3.models.WeightCompositionAggregateModel;
    
    ... ... @@ -42,12 +38,10 @@ import org.apache.commons.logging.LogFactory;
    42 38
     
    
    43 39
     import java.io.IOException;
    
    44 40
     import java.util.Collection;
    
    45
    -import java.util.HashMap;
    
    46 41
     import java.util.List;
    
    47 42
     import java.util.Locale;
    
    48 43
     import java.util.Map;
    
    49 44
     import java.util.Set;
    
    50
    -import java.util.function.Function;
    
    51 45
     
    
    52 46
     import static org.nuiton.i18n.I18n.l;
    
    53 47
     
    
    ... ... @@ -57,7 +51,7 @@ import static org.nuiton.i18n.I18n.l;
    57 51
      * @author Tony Chemit - dev@tchemit.fr
    
    58 52
      * @since 1.3
    
    59 53
      */
    
    60
    -public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Action> {
    
    54
    +public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Action, L2StratumConfiguration> {
    
    61 55
     
    
    62 56
         private static final Log log = LogFactory.getLog(L2CatchStratum.class);
    
    63 57
         /**
    
    ... ... @@ -101,14 +95,14 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti
    101 95
          */
    
    102 96
         private WeightCompositionAggregateModel inputModelForSpeciesToFix;
    
    103 97
     
    
    104
    -    private L2CatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, Collection<Species> speciesToFix) {
    
    98
    +    private L2CatchStratum(L2StratumConfiguration stratumConfiguration, Collection<Species> speciesToFix) {
    
    105 99
             super(stratumConfiguration, speciesToFix);
    
    106 100
             weightCategoriesForSpecies = HashMultimap.create();
    
    107 101
             inputModelForAllSpecies = new WeightCompositionAggregateModel();
    
    108 102
             outputModelForAllSpecies = new WeightCompositionAggregateModel();
    
    109 103
         }
    
    110 104
     
    
    111
    -    static L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
    
    105
    +    static L2CatchStratum newCatchStratum(L2StratumConfiguration stratumConfiguration,
    
    112 106
                                               List<WeightCategoryTreatment> weightCategories,
    
    113 107
                                               Collection<Species> species,
    
    114 108
                                               Level2Action action) throws Exception {
    
    ... ... @@ -133,29 +127,6 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti
    133 127
             return catchStratum;
    
    134 128
         }
    
    135 129
     
    
    136
    -    private static <X extends WeightCategoryTreatmentAware> void fillWeights(
    
    137
    -            WeightCategoryTreatment weightCategory,
    
    138
    -            Collection<X> data,
    
    139
    -            Map<Species, Float> weights,
    
    140
    -            Function<X, Float> function,
    
    141
    -            WeightCompositionAggregateModel model,
    
    142
    -            int divideFactor) {
    
    143
    -        if (weights == null) {
    
    144
    -            weights = new HashMap<>();
    
    145
    -        }
    
    146
    -        for (X setSpeciesCatWeight : data) {
    
    147
    -            Species species = setSpeciesCatWeight.getSpecies();
    
    148
    -            Float weight = weights.get(species);
    
    149
    -            if (weight == null) {
    
    150
    -                weight = 0f;
    
    151
    -            }
    
    152
    -            weight += function.apply(setSpeciesCatWeight) / divideFactor;
    
    153
    -            weights.put(species, weight);
    
    154
    -        }
    
    155
    -        if (model != null) {
    
    156
    -            model.addModel(weightCategory, weights);
    
    157
    -        }
    
    158
    -    }
    
    159 130
     
    
    160 131
         @Override
    
    161 132
         public void close() throws IOException {
    
    ... ... @@ -242,11 +213,7 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti
    242 213
         }
    
    243 214
     
    
    244 215
         @Override
    
    245
    -    public L2StratumConfiguration getConfiguration() {
    
    246
    -        return (L2StratumConfiguration) super.getConfiguration();
    
    247
    -    }
    
    248
    -    @Override
    
    249
    -    protected CatchStratumLoader<Level2Configuration> newLoader() {
    
    216
    +    protected L2CatchStratumLoader newLoader() {
    
    250 217
             return new L2CatchStratumLoader();
    
    251 218
         }
    
    252 219
     
    
    ... ... @@ -258,23 +225,8 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti
    258 225
     
    
    259 226
         WeightCompositionAggregateModel sampleWeightModelForAllSpecies(Activity activity) {
    
    260 227
             WeightCompositionAggregateModel sampleWeightModelFroAllSpecies = new WeightCompositionAggregateModel();
    
    261
    -        L2SampleStratum.fillWeightsFromSetSpeciesCatWeight(activity, null, sampleWeightModelFroAllSpecies);
    
    228
    +        fillWeightsFromSamplesWeight(activity, null, sampleWeightModelFroAllSpecies);
    
    262 229
             return sampleWeightModelFroAllSpecies;
    
    263 230
         }
    
    264 231
     
    
    265
    -    private void fillWeightsFromCatchesWeight(Activity activity, WeightCompositionAggregateModel model, int dividerFactor) {
    
    266
    -        Map<WeightCategoryTreatment, Map<Species, Float>> weights = new HashMap<>();
    
    267
    -        Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> data = getCorrectedElementaryCatchByCategory(activity);
    
    268
    -        T3IOUtil.fillMapWithDefaultValue(weights, data.keySet(), HashMap::new);
    
    269
    -        for (WeightCategoryTreatment weightCategory : data.keySet()) {
    
    270
    -            Map<Species, Float> speciesFloatMap = weights.get(weightCategory);
    
    271
    -            Collection<CorrectedElementaryCatch> correctedElementaryCatches = data.get(weightCategory);
    
    272
    -            fillWeights(weightCategory,
    
    273
    -                    correctedElementaryCatches,
    
    274
    -                    speciesFloatMap,
    
    275
    -                    CorrectedElementaryCatch::getCatchWeight,
    
    276
    -                    model,
    
    277
    -                    dividerFactor);
    
    278
    -        }
    
    279
    -    }
    
    280 232
     }

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratumLoader.java
    ... ... @@ -20,19 +20,12 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.data.level2;
    
    22 22
     
    
    23
    -import com.google.common.base.Preconditions;
    
    24 23
     import fr.ird.t3.actions.stratum.CatchStratumLoader;
    
    25
    -import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    26 24
     import fr.ird.t3.entities.data.Activity;
    
    27 25
     import fr.ird.t3.entities.data.ActivityTopiaDao;
    
    28
    -import fr.ird.t3.entities.data.Trip;
    
    29
    -import fr.ird.t3.entities.reference.Vessel;
    
    30
    -import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    31 26
     import fr.ird.t3.services.ioc.InjectDAO;
    
    32 27
     
    
    33
    -import java.util.HashMap;
    
    34 28
     import java.util.Map;
    
    35
    -import java.util.Set;
    
    36 29
     
    
    37 30
     /**
    
    38 31
      * To load a {@link L2CatchStratum} for a given stratum configuration.
    
    ... ... @@ -40,13 +33,13 @@ import java.util.Set;
    40 33
      * @author Tony Chemit - dev@tchemit.fr
    
    41 34
      * @since 1.3
    
    42 35
      */
    
    43
    -public class L2CatchStratumLoader extends CatchStratumLoader<Level2Configuration> {
    
    36
    +public class L2CatchStratumLoader extends CatchStratumLoader<Level2Configuration, Level2Action, L2StratumConfiguration> {
    
    44 37
     
    
    45 38
         @InjectDAO(entityType = Activity.class)
    
    46 39
         private ActivityTopiaDao activityDAO;
    
    47 40
     
    
    48 41
         @Override
    
    49
    -    public Map<Activity, Integer> loadData(StratumConfiguration<Level2Configuration> configuration) {
    
    42
    +    public Map<Activity, Integer> loadData(L2StratumConfiguration configuration) {
    
    50 43
             // on commence par récupérer les activités :
    
    51 44
             // - dans la zone
    
    52 45
             // - avec le bon type de banc
    
    ... ... @@ -67,36 +60,4 @@ public class L2CatchStratumLoader extends CatchStratumLoader<Level2Configuration
    67 60
             // - maree.bateau dans la bonne flotte OK
    
    68 61
             return filterActivities(configuration, activityIds);
    
    69 62
         }
    
    70
    -
    
    71
    -    private Map<Activity, Integer> filterActivities(StratumConfiguration<Level2Configuration> configuration, Map<String, Integer> activityIds) {
    
    72
    -        Map<Activity, Integer> result = new HashMap<>();
    
    73
    -        if (activityIds != null && activityIds.size() > 0) {
    
    74
    -            Set<Vessel> possibleVessels = configuration.getPossibleCatchVessels();
    
    75
    -            WeightCategoryTreatment weightCategoryTreatment = configuration.getWeightCategoryTreatment();
    
    76
    -            for (Map.Entry<String, Integer> e : activityIds.entrySet()) {
    
    77
    -                String activityId = e.getKey();
    
    78
    -                // get activity
    
    79
    -                Activity activity = configuration.getActivity(activityId);
    
    80
    -                // get his trip
    
    81
    -                Trip trip = activity.getTrip();
    
    82
    -                if (!possibleVessels.contains(trip.getVessel())) {
    
    83
    -                    // not a matching boat
    
    84
    -                    continue;
    
    85
    -                }
    
    86
    -                // recheck activity have some catches.
    
    87
    -                Preconditions.checkState(activity.isCorrectedElementaryCatchNotEmpty(),
    
    88
    -                        String.format("Can not accept an activity (%s) with no catch", activity.getTopiaId()));
    
    89
    -                if (weightCategoryTreatment != null) {
    
    90
    -                    // weight category is in stratum, check there is catch using this category
    
    91
    -                    boolean foundWeightCategory = activity.withCorrectedElementaryCatch(weightCategoryTreatment);
    
    92
    -                    if (!foundWeightCategory) {
    
    93
    -                        // reject - the stratum weight category not found for this activity
    
    94
    -                        continue;
    
    95
    -                    }
    
    96
    -                }
    
    97
    -                result.put(activity, e.getValue());
    
    98
    -            }
    
    99
    -        }
    
    100
    -        return result;
    
    101
    -    }
    
    102
    -}
    63
    +}
    \ No newline at end of file

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratum.java
    ... ... @@ -20,26 +20,17 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.data.level2;
    
    22 22
     
    
    23
    -import com.google.common.collect.ArrayListMultimap;
    
    24
    -import com.google.common.collect.Multimap;
    
    25
    -import com.google.common.collect.Multimaps;
    
    26
    -import fr.ird.t3.T3IOUtil;
    
    27 23
     import fr.ird.t3.actions.stratum.SampleStratum;
    
    28
    -import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    29 24
     import fr.ird.t3.entities.data.Activity;
    
    30
    -import fr.ird.t3.entities.data.SetSpeciesCatWeight;
    
    31 25
     import fr.ird.t3.entities.data.SetSpeciesFrequency;
    
    32
    -import fr.ird.t3.entities.data.WeightCategoryTreatmentAware;
    
    33 26
     import fr.ird.t3.entities.reference.Species;
    
    34 27
     import fr.ird.t3.entities.reference.WeightCategory;
    
    35 28
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    36 29
     import fr.ird.t3.models.WeightCompositionAggregateModel;
    
    37 30
     import fr.ird.t3.models.WeightCompositionModelHelper;
    
    38 31
     import fr.ird.t3.services.T3ServiceContext;
    
    39
    -import org.apache.commons.collections4.CollectionUtils;
    
    40 32
     import org.apache.commons.logging.Log;
    
    41 33
     import org.apache.commons.logging.LogFactory;
    
    42
    -import org.nuiton.topia.persistence.TopiaException;
    
    43 34
     
    
    44 35
     import java.io.IOException;
    
    45 36
     import java.util.Collection;
    
    ... ... @@ -48,7 +39,6 @@ import java.util.List;
    48 39
     import java.util.Locale;
    
    49 40
     import java.util.Map;
    
    50 41
     import java.util.Set;
    
    51
    -import java.util.function.Function;
    
    52 42
     
    
    53 43
     import static org.nuiton.i18n.I18n.l;
    
    54 44
     
    
    ... ... @@ -58,20 +48,17 @@ import static org.nuiton.i18n.I18n.l;
    58 48
      * @author Tony Chemit - dev@tchemit.fr
    
    59 49
      * @since 1.2
    
    60 50
      */
    
    61
    -public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Action, L2SampleStratum> {
    
    51
    +public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Action, L2StratumConfiguration, L2SampleStratum> {
    
    62 52
     
    
    63 53
         private static final Log log = LogFactory.getLog(L2SampleStratum.class);
    
    64
    -
    
    65 54
         /**
    
    66 55
          * Total weight of the catch stratum.
    
    67 56
          * <p/>
    
    68 57
          * This is needed to test sample stratum quality when loading data.
    
    69 58
          */
    
    70 59
         private final float catchStratumTotalWeight;
    
    71
    -
    
    72 60
         /** Weight composition for all species found in catches. */
    
    73 61
         private final WeightCompositionAggregateModel modelsForAllSpecies;
    
    74
    -
    
    75 62
         /** Weight composition model for only species to fix. */
    
    76 63
         private WeightCompositionAggregateModel modelsForSpeciesToFix;
    
    77 64
     
    
    ... ... @@ -89,70 +76,22 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac
    89 76
          */
    
    90 77
         private float sampleStratumTotalWeight;
    
    91 78
     
    
    92
    -    private L2SampleStratum(StratumConfiguration<Level2Configuration> configuration, Collection<Species> speciesToFix, float catchStratumTotalWeight) {
    
    79
    +    private L2SampleStratum(L2StratumConfiguration configuration, L2CatchStratum catchStratum, Collection<Species> speciesToFix) {
    
    93 80
             super(configuration, speciesToFix);
    
    94
    -        this.catchStratumTotalWeight = catchStratumTotalWeight;
    
    81
    +        this.catchStratumTotalWeight = catchStratum.getTotalCatchWeightForSpeciesToFix();
    
    95 82
             this.modelsForAllSpecies = new WeightCompositionAggregateModel();
    
    96 83
         }
    
    97 84
     
    
    98
    -    static L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
    
    85
    +    static L2SampleStratum newSampleStratum(L2StratumConfiguration stratumConfiguration,
    
    86
    +                                            L2CatchStratum catchStratum,
    
    99 87
                                                 List<WeightCategoryTreatment> weightCategories,
    
    100
    -                                            float totalCatchWeight,
    
    101 88
                                                 Collection<Species> species,
    
    102 89
                                                 Level2Action action) throws Exception {
    
    103
    -        L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, species, totalCatchWeight);
    
    90
    +        L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, catchStratum, species);
    
    104 91
             sampleStratum.init(action.getServiceContext(), weightCategories, action);
    
    105 92
             return sampleStratum;
    
    106 93
         }
    
    107 94
     
    
    108
    -    public static void fillWeightsFromSetSpeciesCatWeight(Activity activity,
    
    109
    -                                                          Map<WeightCategoryTreatment, Map<Species, Float>> weights,
    
    110
    -                                                          WeightCompositionAggregateModel model) {
    
    111
    -        if (weights == null) {
    
    112
    -            weights = new HashMap<>();
    
    113
    -        }
    
    114
    -        Multimap<WeightCategoryTreatment, SetSpeciesCatWeight> data = groupByWeightCategoryTreatment(activity.getSetSpeciesCatWeight());
    
    115
    -        T3IOUtil.fillMapWithDefaultValue(weights, data.keySet(), HashMap::new);
    
    116
    -        for (WeightCategoryTreatment weightCategory : data.keySet()) {
    
    117
    -            Map<Species, Float> speciesFloatMap = weights.get(weightCategory);
    
    118
    -            Collection<SetSpeciesCatWeight> setSpeciesCatWeights = data.get(weightCategory);
    
    119
    -            fillWeights(weightCategory, setSpeciesCatWeights, speciesFloatMap, SetSpeciesCatWeight::getWeight, model);
    
    120
    -        }
    
    121
    -    }
    
    122
    -
    
    123
    -    private static <X extends WeightCategoryTreatmentAware> Multimap<WeightCategoryTreatment, X> groupByWeightCategoryTreatment(Collection<X> activity) {
    
    124
    -        Multimap<WeightCategoryTreatment, X> index;
    
    125
    -        if (CollectionUtils.isEmpty(activity)) {
    
    126
    -            index = ArrayListMultimap.create();
    
    127
    -        } else {
    
    128
    -            index = Multimaps.index(activity, WeightCategoryTreatmentAware::getWeightCategoryTreatment);
    
    129
    -        }
    
    130
    -        return index;
    
    131
    -    }
    
    132
    -
    
    133
    -    private static <X extends WeightCategoryTreatmentAware> void fillWeights(
    
    134
    -            WeightCategoryTreatment weightCategory,
    
    135
    -            Collection<X> data,
    
    136
    -            Map<Species, Float> weights,
    
    137
    -            Function<X, Float> function,
    
    138
    -            WeightCompositionAggregateModel model) {
    
    139
    -        if (weights == null) {
    
    140
    -            weights = new HashMap<>();
    
    141
    -        }
    
    142
    -        for (X setSpeciesCatWeight : data) {
    
    143
    -            Species species = setSpeciesCatWeight.getSpecies();
    
    144
    -            Float weight = weights.get(species);
    
    145
    -            if (weight == null) {
    
    146
    -                weight = 0f;
    
    147
    -            }
    
    148
    -            weight += function.apply(setSpeciesCatWeight);
    
    149
    -            weights.put(species, weight);
    
    150
    -        }
    
    151
    -        if (model != null) {
    
    152
    -            model.addModel(weightCategory, weights);
    
    153
    -        }
    
    154
    -    }
    
    155
    -
    
    156 95
         @Override
    
    157 96
         public void close() throws IOException {
    
    158 97
             super.close();
    
    ... ... @@ -189,23 +128,20 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac
    189 128
             return sampleStratumTotalWeight;
    
    190 129
         }
    
    191 130
     
    
    192
    -    //FIXME-263 si la categorie de poids que faire ?
    
    193 131
         @Override
    
    194
    -    protected void mergeNewActivities(T3ServiceContext serviceContext, Set<Activity> activities) throws TopiaException {
    
    132
    +    protected void mergeNewActivities(T3ServiceContext serviceContext, Set<Activity> activities) {
    
    195 133
             Set<Species> species = getSpeciesToFix();
    
    196 134
             // all weights (for each species) for all weight categories found
    
    197 135
             Map<WeightCategoryTreatment, Map<Species, Float>> weights = new HashMap<>();
    
    198 136
             for (Activity activity : activities) {
    
    199 137
                 // split cat weight by weight category
    
    200
    -            fillWeightsFromSetSpeciesCatWeight(activity, weights, null);
    
    138
    +            fillWeightsFromSamplesWeight(activity, weights, null);
    
    201 139
                 // obtain the set species frequencies for the current activity
    
    202
    -            Collection<SetSpeciesFrequency> setSpeciesFrequencies = activity.getSetSpeciesFrequency();
    
    203
    -            if (activity.isSetSpeciesFrequencyNotEmpty()) {
    
    204
    -                // compute sample count for this activity
    
    205
    -                int newCount = computeSampleCount(setSpeciesFrequencies, species);
    
    206
    -                // merge it with final total count
    
    207
    -                sampleStratumTotalCount += newCount;
    
    208
    -            }
    
    140
    +            Collection<SetSpeciesFrequency> setSpeciesFrequencies = getSetSpeciesFrequency(activity);
    
    141
    +            // compute sample count for this activity
    
    142
    +            int newCount = computeSampleCount(setSpeciesFrequencies, species);
    
    143
    +            // merge it with final total count
    
    144
    +            sampleStratumTotalCount += newCount;
    
    209 145
             }
    
    210 146
             // add all weights to model
    
    211 147
             for (Map.Entry<WeightCategoryTreatment, Map<Species, Float>> e : weights.entrySet()) {
    
    ... ... @@ -221,18 +157,6 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac
    221 157
             log.info(String.format("sampleStratumTotalCount  = %d / sampleStratumTotalWeight = %f", getSampleStratumTotalCount(), getSampleStratumTotalWeight()));
    
    222 158
         }
    
    223 159
     
    
    224
    -    //FIXME-263 si la categorie de poids que faire ?
    
    225
    -    private int computeSampleCount(Collection<SetSpeciesFrequency> setSpeciesFrequencies, Collection<Species> speciesToFix) {
    
    226
    -        int newCount = 0;
    
    227
    -        for (SetSpeciesFrequency setSpeciesFrequency : setSpeciesFrequencies) {
    
    228
    -            Species species = setSpeciesFrequency.getSpecies();
    
    229
    -            if (speciesToFix.contains(species)) {
    
    230
    -                newCount += setSpeciesFrequency.getNumber();
    
    231
    -            }
    
    232
    -        }
    
    233
    -        return newCount;
    
    234
    -    }
    
    235
    -
    
    236 160
         @Override
    
    237 161
         public String logSampleStratumLevel(int substitutionLevel, Level2Action messager) {
    
    238 162
             Locale l = messager.getLocale();
    
    ... ... @@ -251,8 +175,14 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac
    251 175
                     modelsForSpeciesToFix);
    
    252 176
         }
    
    253 177
     
    
    254
    -    @Override
    
    255
    -    public L2StratumConfiguration getConfiguration() {
    
    256
    -        return (L2StratumConfiguration) super.getConfiguration();
    
    178
    +    private int computeSampleCount(Collection<SetSpeciesFrequency> setSpeciesFrequencies, Collection<Species> speciesToFix) {
    
    179
    +        int newCount = 0;
    
    180
    +        for (SetSpeciesFrequency setSpeciesFrequency : setSpeciesFrequencies) {
    
    181
    +            Species species = setSpeciesFrequency.getSpecies();
    
    182
    +            if (speciesToFix.contains(species)) {
    
    183
    +                newCount += setSpeciesFrequency.getNumber();
    
    184
    +            }
    
    185
    +        }
    
    186
    +        return newCount;
    
    257 187
         }
    
    258 188
     }

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratumLoader.java
    ... ... @@ -28,6 +28,7 @@ import fr.ird.t3.entities.data.ActivityTopiaDao;
    28 28
     import fr.ird.t3.entities.data.Trip;
    
    29 29
     import fr.ird.t3.entities.reference.SchoolType;
    
    30 30
     import fr.ird.t3.entities.reference.Vessel;
    
    31
    +import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    31 32
     import fr.ird.t3.entities.type.T3Date;
    
    32 33
     import fr.ird.t3.services.ioc.InjectDAO;
    
    33 34
     import org.apache.commons.logging.Log;
    
    ... ... @@ -43,7 +44,7 @@ import java.util.Set;
    43 44
      * @author Tony Chemit - dev@tchemit.fr
    
    44 45
      * @since 1.3
    
    45 46
      */
    
    46
    -public abstract class L2SampleStratumLoader extends SampleStratumLoader<Level2Configuration, Level2Action, L2SampleStratum> {
    
    47
    +public abstract class L2SampleStratumLoader extends SampleStratumLoader<Level2Configuration, Level2Action, L2StratumConfiguration, L2SampleStratum> {
    
    47 48
     
    
    48 49
         private static final Log log = LogFactory.getLog(L2SampleStratumLoader.class);
    
    49 50
         /**
    
    ... ... @@ -91,7 +92,7 @@ public abstract class L2SampleStratumLoader extends SampleStratumLoader<Level2Co
    91 92
     
    
    92 93
         @Override
    
    93 94
         protected Set<String> findActivityIds(String schoolTypeId, T3Date beginDate, T3Date endDate, String... zoneIds) {
    
    94
    -        StratumConfiguration<Level2Configuration> configuration = getSampleStratum().getConfiguration();
    
    95
    +        StratumConfiguration<Level2Configuration, Level2Action> configuration = getSampleStratum().getConfiguration();
    
    95 96
             Set<String> result = new HashSet<>();
    
    96 97
             for (String zoneId : zoneIds) {
    
    97 98
                 // on commence par récupérer les activités :
    
    ... ... @@ -110,28 +111,6 @@ public abstract class L2SampleStratumLoader extends SampleStratumLoader<Level2Co
    110 111
         }
    
    111 112
     
    
    112 113
         @Override
    
    113
    -    protected Set<Activity> filterActivities(Set<String> activityIds) {
    
    114
    -        Set<Activity> result = new HashSet<>();
    
    115
    -        StratumConfiguration<Level2Configuration> configuration = getSampleStratum().getConfiguration();
    
    116
    -        Set<Vessel> possibleVessels = configuration.getPossibleSampleVessels();
    
    117
    -        for (String activityId : activityIds) {
    
    118
    -            Activity activity = configuration.getActivity(activityId);
    
    119
    -            // recheck activity have some samples.
    
    120
    -            Preconditions.checkState(
    
    121
    -                    !activity.isSetSpeciesCatWeightEmpty(),
    
    122
    -                    String.format("Can not accept an activity (%s) with no sample", activity.getTopiaId()));
    
    123
    -            // get his trip
    
    124
    -            Trip trip = activity.getTrip();
    
    125
    -            if (!possibleVessels.contains(trip.getVessel())) {
    
    126
    -                // not a matching boat
    
    127
    -                continue;
    
    128
    -            }
    
    129
    -            result.add(activity);
    
    130
    -        }
    
    131
    -        return result;
    
    132
    -    }
    
    133
    -
    
    134
    -    @Override
    
    135 114
         public boolean isStratumOk() {
    
    136 115
             // test if we have enough sample weight
    
    137 116
             L2SampleStratum sampleStratum = getSampleStratum();
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratumLoaderAtlantic.java
    ... ... @@ -39,8 +39,7 @@ public class L2SampleStratumLoaderAtlantic extends L2SampleStratumLoader {
    39 39
     
    
    40 40
         @Override
    
    41 41
         protected Set<String> findActivityIds(int level) {
    
    42
    -
    
    43
    -        StratumConfiguration<Level2Configuration> configuration = getSampleStratum().getConfiguration();
    
    42
    +        StratumConfiguration<Level2Configuration, Level2Action> configuration = getSampleStratum().getConfiguration();
    
    44 43
             String schoolTypeId = configuration.getSchoolType().getTopiaId();
    
    45 44
             String zoneId = configuration.getZone().getTopiaId();
    
    46 45
             T3Date beginDate = configuration.getBeginDate();
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratumLoaderIndian.java
    ... ... @@ -40,7 +40,7 @@ public class L2SampleStratumLoaderIndian extends L2SampleStratumLoader {
    40 40
         @Override
    
    41 41
         protected Set<String> findActivityIds(int level) {
    
    42 42
     
    
    43
    -        StratumConfiguration<Level2Configuration> configuration = getSampleStratum().getConfiguration();
    
    43
    +        StratumConfiguration<Level2Configuration, Level2Action> configuration = getSampleStratum().getConfiguration();
    
    44 44
             String schoolTypeId = configuration.getSchoolType().getTopiaId();
    
    45 45
             String zoneId = configuration.getZone().getTopiaId();
    
    46 46
             T3Date beginDate = configuration.getBeginDate();
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2StratumConfiguration.java
    ... ... @@ -35,9 +35,7 @@ import java.util.List;
    35 35
      *
    
    36 36
      * @author Tony Chemit - dev@tchemit.fr
    
    37 37
      */
    
    38
    -public class L2StratumConfiguration extends StratumConfiguration<Level2Configuration> {
    
    39
    -
    
    40
    -    private final List<WeightCategoryTreatment> weightCategoryTreatments;
    
    38
    +class L2StratumConfiguration extends StratumConfiguration<Level2Configuration, Level2Action> {
    
    41 39
     
    
    42 40
         L2StratumConfiguration(Level2InputContext inputContext,
    
    43 41
                                SchoolType schoolType,
    
    ... ... @@ -48,23 +46,15 @@ public class L2StratumConfiguration extends StratumConfiguration<Level2Configura
    48 46
                                Collection<ZoneStratumAware> zones,
    
    49 47
                                List<WeightCategoryTreatment> weightCategoryTreatments) {
    
    50 48
             super(
    
    51
    -                inputContext.getConfiguration(),
    
    52
    -                inputContext.getZoneMeta(),
    
    49
    +                inputContext,
    
    53 50
                     zone,
    
    54 51
                     schoolType,
    
    55 52
                     weightCategoryTreatment,
    
    56 53
                     beginDate,
    
    57 54
                     beginDate.incrementsMonths(inputContext.getConfiguration().getTimeStep() - 1),
    
    58 55
                     zones,
    
    59
    -                inputContext.getPossibleCatchVessels(),
    
    60
    -                inputContext.getPossibleSampleVessels(),
    
    61 56
                     null,
    
    62
    -                inputContext.getActivityCache(),
    
    57
    +                weightCategoryTreatments,
    
    63 58
                     stratumIndex);
    
    64
    -        this.weightCategoryTreatments = weightCategoryTreatments;
    
    65
    -    }
    
    66
    -
    
    67
    -    public List<WeightCategoryTreatment> getWeightCategoryTreatments() {
    
    68
    -        return weightCategoryTreatments;
    
    69 59
         }
    
    70 60
     }

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2StratumResult.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -23,8 +23,6 @@ package fr.ird.t3.actions.data.level2;
    23 23
     import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    24 24
     import fr.ird.t3.actions.stratum.StratumResult;
    
    25 25
     
    
    26
    -import java.io.IOException;
    
    27
    -
    
    28 26
     /**
    
    29 27
      * Result of a level 2 Stratum.
    
    30 28
      *
    
    ... ... @@ -33,7 +31,7 @@ import java.io.IOException;
    33 31
      */
    
    34 32
     public class L2StratumResult extends StratumResult<Level2Configuration> {
    
    35 33
     
    
    36
    -    public L2StratumResult(StratumConfiguration<Level2Configuration> configuration, String label) {
    
    34
    +    public L2StratumResult(StratumConfiguration<Level2Configuration, Level2Action> configuration, String label) {
    
    37 35
             super(configuration, label);
    
    38 36
         }
    
    39 37
     
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2Action.java
    ... ... @@ -174,7 +174,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    174 174
                     incrementsProgression();
    
    175 175
                 } else {
    
    176 176
                     // compute sample stratum
    
    177
    -                try (L2SampleStratum sampleStratum = L2SampleStratum.newSampleStratum(stratumConfiguration, weightCategories, catchStratum.getTotalCatchWeightForSpeciesToFix(), species, this)) {
    
    177
    +                try (L2SampleStratum sampleStratum = L2SampleStratum.newSampleStratum(stratumConfiguration, catchStratum, weightCategories, species, this)) {
    
    178 178
                         incrementsProgression();
    
    179 179
                         // get the substitution level for the sample stratum
    
    180 180
                         Integer level = sampleStratum.getSubstitutionLevel();
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2OutputContext.java
    ... ... @@ -40,16 +40,16 @@ import static org.nuiton.i18n.I18n.l;
    40 40
      */
    
    41 41
     public class Level2OutputContext extends LevelOutputContext<Level2Configuration, Level2Action, Level2InputContext, L2StratumResult> {
    
    42 42
     
    
    43
    -    private long totalCatchWeightForSpeciesFoFix;
    
    44
    -    private long totalCatchWeight;
    
    45 43
         /**
    
    46 44
          * Input Weight composition (based on {@link CorrectedElementaryCatch#getCatchWeight()}) for all species found in catches.
    
    47 45
          */
    
    48
    -    private WeightCompositionAggregateModel inputCatchModelForAllSpecies;
    
    46
    +    private final WeightCompositionAggregateModel inputCatchModelForAllSpecies;
    
    49 47
         /**
    
    50 48
          * Output Weight composition (based on {@link CorrectedElementaryCatch#getCorrectedCatchWeight()}) for all species found in catches.
    
    51 49
          */
    
    52
    -    private WeightCompositionAggregateModel outputCatchModelForAllSpecies;
    
    50
    +    private final WeightCompositionAggregateModel outputCatchModelForAllSpecies;
    
    51
    +    private long totalCatchWeightForSpeciesFoFix;
    
    52
    +    private long totalCatchWeight;
    
    53 53
     
    
    54 54
         public Level2OutputContext(Level2Action action, Level2InputContext inputContext) {
    
    55 55
             super(action, inputContext);
    
    ... ... @@ -57,10 +57,12 @@ public class Level2OutputContext extends LevelOutputContext<Level2Configuration,
    57 57
             this.outputCatchModelForAllSpecies = new WeightCompositionAggregateModel();
    
    58 58
         }
    
    59 59
     
    
    60
    +    @SuppressWarnings("unused")
    
    60 61
         public long getTotalCatchWeightForSpeciesFoFix() {
    
    61 62
             return totalCatchWeightForSpeciesFoFix;
    
    62 63
         }
    
    63 64
     
    
    65
    +    @SuppressWarnings("unused")
    
    64 66
         public long getTotalCatchWeight() {
    
    65 67
             return totalCatchWeight;
    
    66 68
         }
    
    ... ... @@ -72,22 +74,17 @@ public class Level2OutputContext extends LevelOutputContext<Level2Configuration,
    72 74
             mergeResult(stratumResult);
    
    73 75
         }
    
    74 76
     
    
    77
    +    @SuppressWarnings("unused")
    
    75 78
         public WeightCompositionAggregateModel getInputCatchModelForAllSpecies() {
    
    76 79
             return inputCatchModelForAllSpecies;
    
    77 80
         }
    
    78 81
     
    
    79
    -    public void setInputCatchModelForAllSpecies(WeightCompositionAggregateModel inputCatchModelForAllSpecies) {
    
    80
    -        this.inputCatchModelForAllSpecies = inputCatchModelForAllSpecies;
    
    81
    -    }
    
    82
    -
    
    82
    +    @SuppressWarnings("unused")
    
    83 83
         public WeightCompositionAggregateModel getOutputCatchModelForAllSpecies() {
    
    84 84
             return outputCatchModelForAllSpecies;
    
    85 85
         }
    
    86 86
     
    
    87
    -    public void setOutputCatchModelForAllSpecies(WeightCompositionAggregateModel outputCatchModelForAllSpecies) {
    
    88
    -        this.outputCatchModelForAllSpecies = outputCatchModelForAllSpecies;
    
    89
    -    }
    
    90
    -
    
    87
    +    @SuppressWarnings("unused")
    
    91 88
         public String getInputCatchStratumLog() {
    
    92 89
             Collection<Species> species = getSpecies();
    
    93 90
             WeightCompositionAggregateModel inputCatchModelForSpeciesToFix = inputCatchModelForAllSpecies.extractForSpecies(species);
    
    ... ... @@ -99,6 +96,7 @@ public class Level2OutputContext extends LevelOutputContext<Level2Configuration,
    99 96
                     inputCatchModelForSpeciesToFix);
    
    100 97
         }
    
    101 98
     
    
    99
    +    @SuppressWarnings("unused")
    
    102 100
         public String getOutputCatchStratumLog() {
    
    103 101
             Collection<Species> species = getSpecies();
    
    104 102
             WeightCompositionAggregateModel outputCatchModelForSpeciesToFix = outputCatchModelForAllSpecies.extractForSpecies(species);
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3CatchStratum.java
    ... ... @@ -21,13 +21,10 @@
    21 21
     package fr.ird.t3.actions.data.level3;
    
    22 22
     
    
    23 23
     import fr.ird.t3.actions.stratum.CatchStratum;
    
    24
    -import fr.ird.t3.actions.stratum.CatchStratumLoader;
    
    25
    -import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    26 24
     import fr.ird.t3.entities.T3EntityHelper;
    
    27 25
     import fr.ird.t3.entities.T3Suppliers;
    
    28 26
     import fr.ird.t3.entities.data.Activity;
    
    29 27
     import fr.ird.t3.entities.data.CorrectedElementaryCatch;
    
    30
    -import fr.ird.t3.entities.data.SpeciesAware;
    
    31 28
     import fr.ird.t3.entities.reference.Species;
    
    32 29
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    33 30
     import fr.ird.t3.services.T3ServiceContext;
    
    ... ... @@ -35,7 +32,6 @@ import fr.ird.t3.services.T3ServiceContext;
    35 32
     import java.util.Collection;
    
    36 33
     import java.util.List;
    
    37 34
     import java.util.Map;
    
    38
    -import java.util.function.Predicate;
    
    39 35
     
    
    40 36
     /**
    
    41 37
      * Define a catch stratum for a given stratum of a level 2 treatment.
    
    ... ... @@ -43,16 +39,9 @@ import java.util.function.Predicate;
    43 39
      * @author Tony Chemit - dev@tchemit.fr
    
    44 40
      * @since 1.3
    
    45 41
      */
    
    46
    -public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Action> {
    
    42
    +public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Action, L3StratumConfiguration> {
    
    47 43
     
    
    48 44
         /**
    
    49
    -     * Predicate to filter only species selected in configuration.
    
    50
    -     *
    
    51
    -     * @see #getSpeciesToFix()
    
    52
    -     * @since 1.4
    
    53
    -     */
    
    54
    -    private final Predicate<? super SpeciesAware> speciesToFixFilter;
    
    55
    -    /**
    
    56 45
          * Keep the total weight of all the catches in the stratum.
    
    57 46
          * <p/>
    
    58 47
          * Used by sampleStratum for quality tests.
    
    ... ... @@ -61,17 +50,12 @@ public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Acti
    61 50
          */
    
    62 51
         private float totalCatchWeight;
    
    63 52
     
    
    64
    -    L3CatchStratum(StratumConfiguration<Level3Configuration> stratumConfiguration, Collection<Species> speciesToFix, Predicate<? super SpeciesAware> speciesToFixFilter) {
    
    53
    +    L3CatchStratum(L3StratumConfiguration stratumConfiguration, Collection<Species> speciesToFix) {
    
    65 54
             super(stratumConfiguration, speciesToFix);
    
    66
    -        this.speciesToFixFilter = speciesToFixFilter;
    
    67
    -    }
    
    68
    -    @Override
    
    69
    -    public L3StratumConfiguration getConfiguration() {
    
    70
    -        return (L3StratumConfiguration) super.getConfiguration();
    
    71 55
         }
    
    72 56
     
    
    73 57
         @Override
    
    74
    -    protected CatchStratumLoader<Level3Configuration> newLoader() {
    
    58
    +    protected L3CatchStratumLoader newLoader() {
    
    75 59
             return new L3CatchStratumLoader();
    
    76 60
         }
    
    77 61
     
    
    ... ... @@ -87,7 +71,7 @@ public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Acti
    87 71
                         T3EntityHelper.getTotal(
    
    88 72
                                 getCorrectedElementaryCatch(activity),
    
    89 73
                                 CorrectedElementaryCatch::getCorrectedCatchWeight,
    
    90
    -                            speciesToFixFilter,
    
    74
    +                            getConfiguration().getSpeciesToFixFilter(),
    
    91 75
                                 T3Suppliers.newActivityDecorateSupplier(
    
    92 76
                                         serviceContext,
    
    93 77
                                         activity,
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3CatchStratumLoader.java
    ... ... @@ -20,18 +20,12 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.data.level3;
    
    22 22
     
    
    23
    -import com.google.common.base.Preconditions;
    
    24 23
     import fr.ird.t3.actions.stratum.CatchStratumLoader;
    
    25
    -import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    26 24
     import fr.ird.t3.entities.data.Activity;
    
    27 25
     import fr.ird.t3.entities.data.ActivityTopiaDao;
    
    28
    -import fr.ird.t3.entities.data.Trip;
    
    29
    -import fr.ird.t3.entities.reference.Vessel;
    
    30 26
     import fr.ird.t3.services.ioc.InjectDAO;
    
    31 27
     
    
    32
    -import java.util.HashMap;
    
    33 28
     import java.util.Map;
    
    34
    -import java.util.Set;
    
    35 29
     
    
    36 30
     /**
    
    37 31
      * To load a {@link L3CatchStratum} for a given stratum configuration.
    
    ... ... @@ -39,13 +33,13 @@ import java.util.Set;
    39 33
      * @author Tony Chemit - dev@tchemit.fr
    
    40 34
      * @since 1.3
    
    41 35
      */
    
    42
    -public class L3CatchStratumLoader extends CatchStratumLoader<Level3Configuration> {
    
    36
    +public class L3CatchStratumLoader extends CatchStratumLoader<Level3Configuration, Level3Action, L3StratumConfiguration> {
    
    43 37
     
    
    44 38
         @InjectDAO(entityType = Activity.class)
    
    45 39
         private ActivityTopiaDao activityDAO;
    
    46 40
     
    
    47 41
         @Override
    
    48
    -    public Map<Activity, Integer> loadData(StratumConfiguration<Level3Configuration> configuration) {
    
    42
    +    public Map<Activity, Integer> loadData(L3StratumConfiguration configuration) {
    
    49 43
             // on commence par récupérer les activités :
    
    50 44
             // - dans la zone
    
    51 45
             // - avec le bon type de banc
    
    ... ... @@ -66,29 +60,4 @@ public class L3CatchStratumLoader extends CatchStratumLoader<Level3Configuration
    66 60
             // - maree.bateau dans la bonne flotte OK
    
    67 61
             return filterActivities(configuration, activityIds);
    
    68 62
         }
    
    69
    -
    
    70
    -    private Map<Activity, Integer> filterActivities(StratumConfiguration<Level3Configuration> configuration, Map<String, Integer> activityIds) {
    
    71
    -
    
    72
    -        Set<Vessel> possibleVessels = configuration.getPossibleCatchVessels();
    
    73
    -
    
    74
    -        Map<Activity, Integer> result = new HashMap<>();
    
    75
    -        if (activityIds != null && activityIds.size() > 0) {
    
    76
    -            for (Map.Entry<String, Integer> e : activityIds.entrySet()) {
    
    77
    -                String activityId = e.getKey();
    
    78
    -                // get activity
    
    79
    -                Activity activity = configuration.getActivity(activityId);
    
    80
    -                // get his trip
    
    81
    -                Trip trip = activity.getTrip();
    
    82
    -                if (!possibleVessels.contains(trip.getVessel())) {
    
    83
    -                    // not a matching boat
    
    84
    -                    continue;
    
    85
    -                }
    
    86
    -                // recheck activity have some catches.
    
    87
    -                Preconditions.checkState(!activity.isCorrectedElementaryCatchEmpty(),
    
    88
    -                        String.format("Can not accept an activity (%s) with no catch", activity.getTopiaId()));
    
    89
    -                result.put(activity, e.getValue());
    
    90
    -            }
    
    91
    -        }
    
    92
    -        return result;
    
    93
    -    }
    
    94 63
     }

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratum.java
    ... ... @@ -25,7 +25,6 @@ import com.google.common.collect.Multimap;
    25 25
     import com.google.common.collect.Multimaps;
    
    26 26
     import fr.ird.t3.T3IOUtil;
    
    27 27
     import fr.ird.t3.actions.stratum.SampleStratum;
    
    28
    -import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    29 28
     import fr.ird.t3.entities.T3EntityHelper;
    
    30 29
     import fr.ird.t3.entities.T3Suppliers;
    
    31 30
     import fr.ird.t3.entities.cache.LengthWeightConversionWithContextCache;
    
    ... ... @@ -34,7 +33,6 @@ import fr.ird.t3.entities.data.Activity;
    34 33
     import fr.ird.t3.entities.data.SetSpeciesCatWeight;
    
    35 34
     import fr.ird.t3.entities.data.SetSpeciesFrequency;
    
    36 35
     import fr.ird.t3.entities.data.SetSpeciesFrequencyTopiaDao;
    
    37
    -import fr.ird.t3.entities.data.SpeciesAware;
    
    38 36
     import fr.ird.t3.entities.reference.LengthWeightConversion;
    
    39 37
     import fr.ird.t3.entities.reference.Species;
    
    40 38
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    ... ... @@ -54,7 +52,6 @@ import java.util.List;
    54 52
     import java.util.Locale;
    
    55 53
     import java.util.Map;
    
    56 54
     import java.util.Set;
    
    57
    -import java.util.function.Predicate;
    
    58 55
     
    
    59 56
     import static org.nuiton.i18n.I18n.l;
    
    60 57
     
    
    ... ... @@ -64,7 +61,7 @@ import static org.nuiton.i18n.I18n.l;
    64 61
      * @author Tony Chemit - dev@tchemit.fr
    
    65 62
      * @since 1.2
    
    66 63
      */
    
    67
    -public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Action, L3SampleStratum> {
    
    64
    +public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Action, L3StratumConfiguration, L3SampleStratum> {
    
    68 65
     
    
    69 66
         private static final Log log = LogFactory.getLog(L3SampleStratum.class);
    
    70 67
     
    
    ... ... @@ -101,31 +98,22 @@ public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Ac
    101 98
          */
    
    102 99
         private final LengthWeightConversionWithContextCache conversionHelper;
    
    103 100
         /**
    
    104
    -     * Predicate to filter only species selected in configuration.
    
    105
    -     *
    
    106
    -     * @see #getSpeciesToFix()
    
    107
    -     * @since 1.4
    
    108
    -     */
    
    109
    -    private final Predicate<? super SpeciesAware> speciesToFixFilter;
    
    110
    -    /**
    
    111 101
          * Total weight of the sample stratum.
    
    112 102
          * <p/>
    
    113 103
          * This is needed to test sample stratum quality when loading data.
    
    114 104
          */
    
    115 105
         private float sampleStratumTotalWeight;
    
    116 106
     
    
    117
    -    L3SampleStratum(StratumConfiguration<Level3Configuration> configuration,
    
    107
    +    L3SampleStratum(L3StratumConfiguration configuration,
    
    118 108
                         Collection<Species> speciesToFix,
    
    119 109
                         float catchStratumTotalWeight,
    
    120
    -                    LengthWeightConversionWithContextCache conversionHelper,
    
    121
    -                    Predicate<? super SpeciesAware> speciesToFixFilter) {
    
    110
    +                    LengthWeightConversionWithContextCache conversionHelper) {
    
    122 111
             super(configuration, speciesToFix);
    
    123 112
             this.catchStratumTotalWeight = catchStratumTotalWeight;
    
    124 113
             this.conversionHelper = conversionHelper;
    
    125 114
             this.speciesCount = new HashMap<>();
    
    126 115
             this.compositionModel = new HashMap<>();
    
    127 116
             this.allSetSpeciesFrequenciesBySpecies = ArrayListMultimap.create();
    
    128
    -        this.speciesToFixFilter = speciesToFixFilter;
    
    129 117
         }
    
    130 118
     
    
    131 119
         @Override
    
    ... ... @@ -155,18 +143,13 @@ public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Ac
    155 143
         }
    
    156 144
     
    
    157 145
         @Override
    
    158
    -    public L3StratumConfiguration getConfiguration() {
    
    159
    -        return (L3StratumConfiguration) super.getConfiguration();
    
    160
    -    }
    
    161
    -
    
    162
    -    @Override
    
    163 146
         public void mergeNewActivities(T3ServiceContext serviceContext, Set<Activity> activities) {
    
    164 147
             for (Activity activity : activities) {
    
    165 148
                 // add total weight of samples of the activity (only for selected species)
    
    166 149
                 float totalWeight = T3EntityHelper.getTotal(
    
    167 150
                         activity.getSetSpeciesCatWeight(),
    
    168 151
                         SetSpeciesCatWeight::getWeight,
    
    169
    -                    speciesToFixFilter,
    
    152
    +                    getConfiguration().getSpeciesToFixFilter(),
    
    170 153
                         T3Suppliers.newActivityDecorateSupplier(
    
    171 154
                                 serviceContext,
    
    172 155
                                 activity,
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratumLoader.java
    ... ... @@ -20,14 +20,11 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.data.level3;
    
    22 22
     
    
    23
    -import com.google.common.base.Preconditions;
    
    24 23
     import fr.ird.t3.actions.stratum.SampleStratumLoader;
    
    25 24
     import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    26 25
     import fr.ird.t3.entities.data.Activity;
    
    27 26
     import fr.ird.t3.entities.data.ActivityTopiaDao;
    
    28
    -import fr.ird.t3.entities.data.Trip;
    
    29 27
     import fr.ird.t3.entities.reference.Species;
    
    30
    -import fr.ird.t3.entities.reference.Vessel;
    
    31 28
     import fr.ird.t3.entities.type.T3Date;
    
    32 29
     import fr.ird.t3.services.ioc.InjectDAO;
    
    33 30
     import org.apache.commons.logging.Log;
    
    ... ... @@ -45,7 +42,7 @@ import java.util.Set;
    45 42
      * @author Tony Chemit - dev@tchemit.fr
    
    46 43
      * @since 1.3
    
    47 44
      */
    
    48
    -public abstract class L3SampleStratumLoader extends SampleStratumLoader<Level3Configuration, Level3Action, L3SampleStratum> {
    
    45
    +public abstract class L3SampleStratumLoader extends SampleStratumLoader<Level3Configuration, Level3Action, L3StratumConfiguration, L3SampleStratum> {
    
    49 46
     
    
    50 47
         private static final Log log = LogFactory.getLog(L3SampleStratumLoader.class);
    
    51 48
     
    
    ... ... @@ -83,7 +80,7 @@ public abstract class L3SampleStratumLoader extends SampleStratumLoader<Level3Co
    83 80
         @Override
    
    84 81
         protected Set<String> findActivityIds(String schoolTypeId, T3Date beginDate, T3Date endDate, String... zoneIds) {
    
    85 82
             Set<String> result = new HashSet<>();
    
    86
    -        StratumConfiguration<Level3Configuration> configuration = getSampleStratum().getConfiguration();
    
    83
    +        StratumConfiguration<Level3Configuration, Level3Action> configuration = getSampleStratum().getConfiguration();
    
    87 84
             for (String zoneId : zoneIds) {
    
    88 85
                 // on commence par récupérer les activités :
    
    89 86
                 // - dans la zone ET
    
    ... ... @@ -101,28 +98,6 @@ public abstract class L3SampleStratumLoader extends SampleStratumLoader<Level3Co
    101 98
         }
    
    102 99
     
    
    103 100
         @Override
    
    104
    -    protected Set<Activity> filterActivities(Set<String> activityIds) {
    
    105
    -        Set<Activity> result = new HashSet<>();
    
    106
    -        StratumConfiguration<Level3Configuration> configuration = getSampleStratum().getConfiguration();
    
    107
    -        Set<Vessel> possibleVessels = configuration.getPossibleSampleVessels();
    
    108
    -        for (String activityId : activityIds) {
    
    109
    -            Activity activity = configuration.getActivity(activityId);
    
    110
    -            // get his trip
    
    111
    -            Trip trip = activity.getTrip();
    
    112
    -            if (!possibleVessels.contains(trip.getVessel())) {
    
    113
    -                // not a matching boat
    
    114
    -                continue;
    
    115
    -            }
    
    116
    -            // recheck activity have some samples.
    
    117
    -            Preconditions.checkState(
    
    118
    -                    !activity.isSetSpeciesCatWeightEmpty(),
    
    119
    -                    String.format("Can not accept an activity (%s) with no sample", activity.getTopiaId()));
    
    120
    -            result.add(activity);
    
    121
    -        }
    
    122
    -        return result;
    
    123
    -    }
    
    124
    -
    
    125
    -    @Override
    
    126 101
         public boolean isStratumOk() {
    
    127 102
             L3SampleStratum stratum = getSampleStratum();
    
    128 103
             // test if we have enough sample weight
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratumLoaderAtlantic.java
    ... ... @@ -39,7 +39,7 @@ public class L3SampleStratumLoaderAtlantic extends L3SampleStratumLoader {
    39 39
     
    
    40 40
         @Override
    
    41 41
         protected Set<String> findActivityIds(int level) {
    
    42
    -        StratumConfiguration<Level3Configuration> configuration = getSampleStratum().getConfiguration();
    
    42
    +        StratumConfiguration<Level3Configuration, Level3Action> configuration = getSampleStratum().getConfiguration();
    
    43 43
             String schoolTypeId = configuration.getSchoolType().getTopiaId();
    
    44 44
             String zoneId = configuration.getZone().getTopiaId();
    
    45 45
             T3Date beginDate = configuration.getBeginDate();
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratumLoaderIndian.java
    ... ... @@ -40,7 +40,7 @@ public class L3SampleStratumLoaderIndian extends L3SampleStratumLoader {
    40 40
         @Override
    
    41 41
         protected Set<String> findActivityIds(int level) {
    
    42 42
     
    
    43
    -        StratumConfiguration<Level3Configuration> configuration = getSampleStratum().getConfiguration();
    
    43
    +        StratumConfiguration<Level3Configuration, Level3Action> configuration = getSampleStratum().getConfiguration();
    
    44 44
             String schoolTypeId = configuration.getSchoolType().getTopiaId();
    
    45 45
             String zoneId = configuration.getZone().getTopiaId();
    
    46 46
             T3Date beginDate = configuration.getBeginDate();
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3StratumConfiguration.java
    ... ... @@ -22,7 +22,6 @@ package fr.ird.t3.actions.data.level3;
    22 22
      */
    
    23 23
     
    
    24 24
     import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    25
    -import fr.ird.t3.entities.cache.LengthWeightConversionWithContextCache;
    
    26 25
     import fr.ird.t3.entities.reference.SchoolType;
    
    27 26
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    28 27
     import fr.ird.t3.entities.reference.zone.ZoneStratumAware;
    
    ... ... @@ -37,11 +36,9 @@ import java.util.Map;
    37 36
      *
    
    38 37
      * @author Tony Chemit - dev@tchemit.fr
    
    39 38
      */
    
    40
    -public class L3StratumConfiguration extends StratumConfiguration<Level3Configuration> {
    
    39
    +class L3StratumConfiguration extends StratumConfiguration<Level3Configuration, Level3Action> {
    
    41 40
     
    
    42
    -    private final List<WeightCategoryTreatment> weightCategoryTreatments;
    
    43 41
         private final Map<String, Integer> stratumMinimumSampleCount;
    
    44
    -    private final LengthWeightConversionWithContextCache conversionHelper;
    
    45 42
     
    
    46 43
         L3StratumConfiguration(Level3InputContext inputContext,
    
    47 44
                                SchoolType schoolType,
    
    ... ... @@ -53,33 +50,20 @@ public class L3StratumConfiguration extends StratumConfiguration<Level3Configura
    53 50
                                List<WeightCategoryTreatment> weightCategoryTreatments,
    
    54 51
                                Map<String, Integer> stratumMinimumSampleCount) {
    
    55 52
             super(
    
    56
    -                inputContext.getConfiguration(),
    
    57
    -                inputContext.getZoneMeta(),
    
    53
    +                inputContext,
    
    58 54
                     zone,
    
    59 55
                     schoolType,
    
    60 56
                     weightCategoryTreatment,
    
    61 57
                     beginDate,
    
    62 58
                     beginDate.incrementsMonths(inputContext.getConfiguration().getTimeStep() - 1),
    
    63 59
                     zones,
    
    64
    -                inputContext.getPossibleCatchVessels(),
    
    65
    -                inputContext.getPossibleSampleVessels(),
    
    66 60
                     stratumMinimumSampleCount,
    
    67
    -                inputContext.getActivityCache(),
    
    61
    +                weightCategoryTreatments,
    
    68 62
                     stratumIndex);
    
    69
    -        this.weightCategoryTreatments = weightCategoryTreatments;
    
    70 63
             this.stratumMinimumSampleCount = stratumMinimumSampleCount;
    
    71
    -        this.conversionHelper = inputContext.newLengthWeightConversionWithContextCache(zone.getOcean(), beginDate.toBeginDate());
    
    72
    -    }
    
    73
    -
    
    74
    -    public List<WeightCategoryTreatment> getWeightCategoryTreatments() {
    
    75
    -        return weightCategoryTreatments;
    
    76 64
         }
    
    77 65
     
    
    78 66
         public Map<String, Integer> getStratumMinimumSampleCount() {
    
    79 67
             return stratumMinimumSampleCount;
    
    80 68
         }
    
    81
    -
    
    82
    -    public LengthWeightConversionWithContextCache getConversionHelper() {
    
    83
    -        return conversionHelper;
    
    84
    -    }
    
    85 69
     }

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3StratumResult.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -24,8 +24,6 @@ import fr.ird.t3.actions.stratum.StratumConfiguration;
    24 24
     import fr.ird.t3.actions.stratum.StratumResult;
    
    25 25
     import fr.ird.t3.models.SpeciesCountAggregateModel;
    
    26 26
     
    
    27
    -import java.io.IOException;
    
    28
    -
    
    29 27
     /**
    
    30 28
      * Result of a level 3 Stratum.
    
    31 29
      *
    
    ... ... @@ -42,7 +40,7 @@ public class L3StratumResult extends StratumResult<Level3Configuration> {
    42 40
          */
    
    43 41
         private final SpeciesCountAggregateModel totalFishesCount;
    
    44 42
     
    
    45
    -    public L3StratumResult(StratumConfiguration<Level3Configuration> configuration, String label) {
    
    43
    +    public L3StratumResult(StratumConfiguration<Level3Configuration, Level3Action> configuration, String label) {
    
    46 44
             super(configuration, label);
    
    47 45
             totalFishesCount = new SpeciesCountAggregateModel();
    
    48 46
         }
    
    ... ... @@ -52,7 +50,7 @@ public class L3StratumResult extends StratumResult<Level3Configuration> {
    52 50
         }
    
    53 51
     
    
    54 52
         @Override
    
    55
    -    public void close() throws IOException {
    
    53
    +    public void close() {
    
    56 54
             totalFishesCount.close();
    
    57 55
         }
    
    58 56
     
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/Level3Action.java
    ... ... @@ -405,7 +405,7 @@ public class Level3Action extends T3Action<Level3Configuration> {
    405 405
         }
    
    406 406
     
    
    407 407
         private L3CatchStratum newCatchStratum(L3StratumConfiguration stratumConfiguration) throws Exception {
    
    408
    -        L3CatchStratum catchStratum = new L3CatchStratum(stratumConfiguration, inputContext.getSpecies(), inputContext.getSpeciesToFixFilter());
    
    408
    +        L3CatchStratum catchStratum = new L3CatchStratum(stratumConfiguration, inputContext.getSpecies());
    
    409 409
             catchStratum.init(serviceContext, stratumConfiguration.getWeightCategoryTreatments(), this);
    
    410 410
             // get the total weight of the catch stratum
    
    411 411
             float catchStratumWeight = catchStratum.getTotalCatchWeight();
    
    ... ... @@ -430,8 +430,8 @@ public class Level3Action extends T3Action<Level3Configuration> {
    430 430
                     new L3SampleStratum(stratumConfiguration,
    
    431 431
                             inputContext.getSpecies(),
    
    432 432
                             totalCatchWeight,
    
    433
    -                        stratumConfiguration.getConversionHelper(),
    
    434
    -                        inputContext.getSpeciesToFixFilter());
    
    433
    +                        stratumConfiguration.getConversionHelper()
    
    434
    +                );
    
    435 435
             sampleStratum.init(serviceContext, stratumConfiguration.getWeightCategoryTreatments(), this);
    
    436 436
             return sampleStratum;
    
    437 437
         }
    

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/CatchStratum.java
    ... ... @@ -20,12 +20,8 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.stratum;
    
    22 22
     
    
    23
    -import com.google.common.collect.Multimap;
    
    24
    -import com.google.common.collect.Multimaps;
    
    25 23
     import fr.ird.t3.actions.T3Action;
    
    26 24
     import fr.ird.t3.entities.data.Activity;
    
    27
    -import fr.ird.t3.entities.data.CorrectedElementaryCatch;
    
    28
    -import fr.ird.t3.entities.data.WeightCategoryTreatmentAware;
    
    29 25
     import fr.ird.t3.entities.reference.Species;
    
    30 26
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    31 27
     import fr.ird.t3.services.IOCService;
    
    ... ... @@ -33,9 +29,10 @@ import fr.ird.t3.services.T3ServiceContext;
    33 29
     import fr.ird.t3.services.ioc.InjectDAO;
    
    34 30
     
    
    35 31
     import java.util.Collection;
    
    32
    +import java.util.LinkedHashSet;
    
    36 33
     import java.util.List;
    
    37 34
     import java.util.Map;
    
    38
    -import java.util.stream.Collectors;
    
    35
    +import java.util.Set;
    
    39 36
     
    
    40 37
     /**
    
    41 38
      * Base catch stratum.
    
    ... ... @@ -43,12 +40,13 @@ import java.util.stream.Collectors;
    43 40
      * @author Tony Chemit - dev@tchemit.fr
    
    44 41
      * @since 1.3
    
    45 42
      */
    
    46
    -public abstract class CatchStratum<C extends LevelConfigurationWithStratum, A extends T3Action<C>> extends Stratum<C, A> {
    
    43
    +public abstract class CatchStratum<C extends LevelConfigurationWithStratum, A extends T3Action<C>, S extends StratumConfiguration<C, A>> extends Stratum<C, A, S> {
    
    47 44
     
    
    48
    -    private int nbActivitiesWithSample;
    
    45
    +    private final Set<String> activityWithSampleIds;
    
    49 46
     
    
    50
    -    protected CatchStratum(StratumConfiguration<C> configuration, Collection<Species> speciesToFix) {
    
    47
    +    protected CatchStratum(S configuration, Collection<Species> speciesToFix) {
    
    51 48
             super(configuration, speciesToFix);
    
    49
    +        activityWithSampleIds = new LinkedHashSet<>();
    
    52 50
         }
    
    53 51
     
    
    54 52
         /**
    
    ... ... @@ -56,11 +54,11 @@ public abstract class CatchStratum<C extends LevelConfigurationWithStratum, A ex
    56 54
          *
    
    57 55
          * @return new instance of a catch stratum loader
    
    58 56
          */
    
    59
    -    protected abstract CatchStratumLoader<C> newLoader();
    
    57
    +    protected abstract CatchStratumLoader<C, A, S> newLoader();
    
    60 58
     
    
    61 59
         @Override
    
    62 60
         public void init(T3ServiceContext serviceContext, List<WeightCategoryTreatment> weightCategories, A messager) throws Exception {
    
    63
    -        CatchStratumLoader<C> stratumLoader = newLoader();
    
    61
    +        CatchStratumLoader<C, A, S> stratumLoader = newLoader();
    
    64 62
             // inject transaction in loader
    
    65 63
             stratumLoader.setTransaction(serviceContext.getT3TopiaPersistenceContext());
    
    66 64
             // inject dao in loader
    
    ... ... @@ -68,7 +66,13 @@ public abstract class CatchStratum<C extends LevelConfigurationWithStratum, A ex
    68 66
             // get all catches usable in this stratum grouped by their owing activity
    
    69 67
             Map<Activity, Integer> activities = stratumLoader.loadData(getConfiguration());
    
    70 68
             setActivities(activities);
    
    71
    -        nbActivitiesWithSample = (int) activities.keySet().stream().filter(Activity::isSetSpeciesCatWeightNotEmpty).count();
    
    69
    +        //FIXME- Ca doit etre dans SampleStratum ?
    
    70
    +        for (Activity activity : activities.keySet()) {
    
    71
    +            boolean withSample = !getSetSpeciesCatWeight(activity).isEmpty();
    
    72
    +            if (withSample) {
    
    73
    +                activityWithSampleIds.add(activity.getTopiaId());
    
    74
    +            }
    
    75
    +        }
    
    72 76
         }
    
    73 77
     
    
    74 78
         /**
    
    ... ... @@ -81,18 +85,7 @@ public abstract class CatchStratum<C extends LevelConfigurationWithStratum, A ex
    81 85
         }
    
    82 86
     
    
    83 87
         public int getNbActivitiesWithSample() {
    
    84
    -        return nbActivitiesWithSample;
    
    88
    +        return activityWithSampleIds.size();
    
    85 89
         }
    
    86 90
     
    
    87
    -    public Collection<CorrectedElementaryCatch> getCorrectedElementaryCatch(Activity activity) {
    
    88
    -        WeightCategoryTreatment stratumWeightCategoryTreatment = getConfiguration().getWeightCategoryTreatment();
    
    89
    -        if (stratumWeightCategoryTreatment == null) {
    
    90
    -            return activity.getCorrectedElementaryCatch();
    
    91
    -        }
    
    92
    -        return activity.getCorrectedElementaryCatch().stream().filter(c -> stratumWeightCategoryTreatment.equals(c.getWeightCategoryTreatment())).collect(Collectors.toList());
    
    93
    -    }
    
    94
    -
    
    95
    -    public Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> getCorrectedElementaryCatchByCategory(Activity activity) {
    
    96
    -        return Multimaps.index(getCorrectedElementaryCatch(activity), WeightCategoryTreatmentAware::getWeightCategoryTreatment);
    
    97
    -    }
    
    98 91
     }

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/CatchStratumLoader.java
    ... ... @@ -8,24 +8,32 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.stratum;
    
    22 22
     
    
    23
    +import com.google.common.base.Preconditions;
    
    24
    +import fr.ird.t3.actions.T3Action;
    
    23 25
     import fr.ird.t3.entities.T3TopiaPersistenceContext;
    
    24 26
     import fr.ird.t3.entities.data.Activity;
    
    27
    +import fr.ird.t3.entities.data.Trip;
    
    28
    +import fr.ird.t3.entities.reference.Vessel;
    
    29
    +import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    25 30
     import fr.ird.t3.services.T3TopiaPersistenceContextAware;
    
    31
    +import org.nuiton.topia.persistence.TopiaException;
    
    32
    +
    
    33
    +import java.util.HashMap;
    
    26 34
     import java.util.Map;
    
    35
    +import java.util.Set;
    
    27 36
     import java.util.function.Supplier;
    
    28
    -import org.nuiton.topia.persistence.TopiaException;
    
    29 37
     
    
    30 38
     /**
    
    31 39
      * To loader a catch stratum.
    
    ... ... @@ -34,7 +42,7 @@ import org.nuiton.topia.persistence.TopiaException;
    34 42
      * @see CatchStratum
    
    35 43
      * @since 1.3
    
    36 44
      */
    
    37
    -public abstract class CatchStratumLoader<C extends LevelConfigurationWithStratum> implements T3TopiaPersistenceContextAware {
    
    45
    +public abstract class CatchStratumLoader<C extends LevelConfigurationWithStratum, A extends T3Action<C>, S extends StratumConfiguration<C, A>> implements T3TopiaPersistenceContextAware {
    
    38 46
     
    
    39 47
         protected Supplier<T3TopiaPersistenceContext> transaction;
    
    40 48
     
    
    ... ... @@ -42,10 +50,10 @@ public abstract class CatchStratumLoader<C extends LevelConfigurationWithStratum
    42 50
          * To obtain all activities of the catch stratum.
    
    43 51
          *
    
    44 52
          * @param configuration stratum configuration
    
    45
    -     * @return the activites to use for the catch stratum
    
    53
    +     * @return activities to use for the catch stratum
    
    46 54
          * @throws TopiaException if any pb while quering db
    
    47 55
          */
    
    48
    -    public abstract Map<Activity, Integer> loadData(StratumConfiguration<C> configuration) throws TopiaException;
    
    56
    +    public abstract Map<Activity, Integer> loadData(S configuration);
    
    49 57
     
    
    50 58
         @Override
    
    51 59
         public Supplier<T3TopiaPersistenceContext> getT3TopiaPersistenceContext() {
    
    ... ... @@ -55,4 +63,33 @@ public abstract class CatchStratumLoader<C extends LevelConfigurationWithStratum
    55 63
         public void setTransaction(Supplier<T3TopiaPersistenceContext> transaction) {
    
    56 64
             this.transaction = transaction;
    
    57 65
         }
    
    66
    +
    
    67
    +    protected Map<Activity, Integer> filterActivities(S configuration, Map<String, Integer> activityIds) {
    
    68
    +        Map<Activity, Integer> result = new HashMap<>();
    
    69
    +        if (activityIds != null && activityIds.size() > 0) {
    
    70
    +            Set<Vessel> possibleVessels = configuration.getPossibleCatchVessels();
    
    71
    +            WeightCategoryTreatment weightCategoryTreatment = configuration.getWeightCategoryTreatment();
    
    72
    +            for (Map.Entry<String, Integer> e : activityIds.entrySet()) {
    
    73
    +                String activityId = e.getKey();
    
    74
    +                // get activity
    
    75
    +                Activity activity = configuration.getActivity(activityId);
    
    76
    +                // get his trip
    
    77
    +                Trip trip = activity.getTrip();
    
    78
    +                if (!possibleVessels.contains(trip.getVessel())) {
    
    79
    +                    // not a matching boat
    
    80
    +                    continue;
    
    81
    +                }
    
    82
    +                // recheck activity have some catches.
    
    83
    +                Preconditions.checkState(!activity.isCorrectedElementaryCatchEmpty(),
    
    84
    +                        String.format("Can not accept an activity (%s) with no catch", activity.getTopiaId()));
    
    85
    +                // weight category is in stratum, check there is catch using this category
    
    86
    +                if (weightCategoryTreatment != null && !activity.withCorrectedElementaryCatch(weightCategoryTreatment)) {
    
    87
    +                    // reject - the stratum weight category not found for this activity
    
    88
    +                    continue;
    
    89
    +                }
    
    90
    +                result.put(activity, e.getValue());
    
    91
    +            }
    
    92
    +        }
    
    93
    +        return result;
    
    94
    +    }
    
    58 95
     }

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/SampleStratum.java
    ... ... @@ -39,7 +39,7 @@ import java.util.Set;
    39 39
      * @author Tony Chemit - dev@tchemit.fr
    
    40 40
      * @since 1.3
    
    41 41
      */
    
    42
    -public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A extends T3Action<C>, S extends SampleStratum<C, A, S>> extends Stratum<C, A> {
    
    42
    +public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A extends T3Action<C>, T extends StratumConfiguration<C, A>, S extends SampleStratum<C, A, T, S>> extends Stratum<C, A, T> {
    
    43 43
     
    
    44 44
         /**
    
    45 45
          * Number of merged activites (counted when passing through method
    
    ... ... @@ -59,11 +59,11 @@ public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A e
    59 59
          */
    
    60 60
         private Integer substitutionLevel;
    
    61 61
     
    
    62
    -    protected SampleStratum(StratumConfiguration<C> configuration, Collection<Species> speciesToFix) {
    
    62
    +    protected SampleStratum(T configuration, Collection<Species> speciesToFix) {
    
    63 63
             super(configuration, speciesToFix);
    
    64 64
         }
    
    65 65
     
    
    66
    -    protected abstract SampleStratumLoader<C, A, S> newLoader();
    
    66
    +    protected abstract SampleStratumLoader<C, A, T, S> newLoader();
    
    67 67
     
    
    68 68
         protected abstract String logSampleStratumLevel(int substitutionLevel, A messager);
    
    69 69
     
    
    ... ... @@ -93,7 +93,7 @@ public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A e
    93 93
         @Override
    
    94 94
         public void init(T3ServiceContext serviceContext, List<WeightCategoryTreatment> weightCategories, A messager) throws Exception {
    
    95 95
     
    
    96
    -        SampleStratumLoader<C, A, S> stratumLoader = newLoader();
    
    96
    +        SampleStratumLoader<C, A, T, S> stratumLoader = newLoader();
    
    97 97
     
    
    98 98
             // inject transaction in loader
    
    99 99
             stratumLoader.setTransaction(serviceContext.getT3TopiaPersistenceContext());
    
    ... ... @@ -115,4 +115,5 @@ public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A e
    115 115
         public final int getNbMergedActivities() {
    
    116 116
             return nbMergedActivities;
    
    117 117
         }
    
    118
    +
    
    118 119
     }

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/SampleStratumLoader.java
    ... ... @@ -20,9 +20,13 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.stratum;
    
    22 22
     
    
    23
    +import com.google.common.base.Preconditions;
    
    23 24
     import fr.ird.t3.actions.T3Action;
    
    24 25
     import fr.ird.t3.entities.T3TopiaPersistenceContext;
    
    25 26
     import fr.ird.t3.entities.data.Activity;
    
    27
    +import fr.ird.t3.entities.data.Trip;
    
    28
    +import fr.ird.t3.entities.reference.Vessel;
    
    29
    +import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    26 30
     import fr.ird.t3.entities.type.T3Date;
    
    27 31
     import fr.ird.t3.services.T3ServiceContext;
    
    28 32
     import fr.ird.t3.services.T3TopiaPersistenceContextAware;
    
    ... ... @@ -38,13 +42,13 @@ import java.util.Set;
    38 42
     import java.util.function.Supplier;
    
    39 43
     
    
    40 44
     /**
    
    41
    - * To loader a catch stratum.
    
    45
    + * To loader a sample stratum.
    
    42 46
      *
    
    43 47
      * @author Tony Chemit - dev@tchemit.fr
    
    44
    - * @see CatchStratum
    
    48
    + * @see SampleStratum
    
    45 49
      * @since 1.3
    
    46 50
      */
    
    47
    -public abstract class SampleStratumLoader<C extends LevelConfigurationWithStratum, A extends T3Action<C>, S extends SampleStratum<C, A, S>> implements T3TopiaPersistenceContextAware {
    
    51
    +public abstract class SampleStratumLoader<C extends LevelConfigurationWithStratum, A extends T3Action<C>, T extends StratumConfiguration<C, A>, S extends SampleStratum<C, A, T, S>> implements T3TopiaPersistenceContextAware {
    
    48 52
     
    
    49 53
         private static final Log log = LogFactory.getLog(SampleStratumLoader.class);
    
    50 54
         private final C levelConfiguration;
    
    ... ... @@ -60,7 +64,7 @@ public abstract class SampleStratumLoader<C extends LevelConfigurationWithStratu
    60 64
     
    
    61 65
         protected SampleStratumLoader(S sampleStratum) {
    
    62 66
             this.sampleStratum = sampleStratum;
    
    63
    -        levelConfiguration = sampleStratum.getConfiguration().getConfiguration();
    
    67
    +        this.levelConfiguration = sampleStratum.getConfiguration().getConfiguration();
    
    64 68
         }
    
    65 69
     
    
    66 70
         /**
    
    ... ... @@ -77,17 +81,6 @@ public abstract class SampleStratumLoader<C extends LevelConfigurationWithStratu
    77 81
     
    
    78 82
         protected abstract Set<String> findActivityIds(String schoolTypeId, T3Date beginDate, T3Date endDate, String... zoneIds);
    
    79 83
     
    
    80
    -    /**
    
    81
    -     * From a set of activity ids, filter the one that can be use in this
    
    82
    -     * stratum. This mainly means to filter some of them using the stratum
    
    83
    -     * configuration.
    
    84
    -     *
    
    85
    -     * @param activityIds ids of activities to filter
    
    86
    -     * @return the set of usable activities after having
    
    87
    -     * @throws TopiaException if any database problem while loading data
    
    88
    -     */
    
    89
    -    protected abstract Set<Activity> filterActivities(Set<String> activityIds);
    
    90
    -
    
    91 84
         protected abstract boolean isStratumOk();
    
    92 85
     
    
    93 86
         @Override
    
    ... ... @@ -157,4 +150,41 @@ public abstract class SampleStratumLoader<C extends LevelConfigurationWithStratu
    157 150
             return levelConfiguration.getTimeStep();
    
    158 151
         }
    
    159 152
     
    
    153
    +    /**
    
    154
    +     * From a set of activity ids, filter the one that can be use in this
    
    155
    +     * stratum. This mainly means to filter some of them using the stratum
    
    156
    +     * configuration.
    
    157
    +     *
    
    158
    +     * @param activityIds ids of activities to filter
    
    159
    +     * @return the set of usable activities after having
    
    160
    +     * @throws TopiaException if any database problem while loading data
    
    161
    +     */
    
    162
    +    private Set<Activity> filterActivities(Set<String> activityIds) {
    
    163
    +        Set<Activity> result = new HashSet<>();
    
    164
    +        T configuration = getSampleStratum().getConfiguration();
    
    165
    +        Set<Vessel> possibleVessels = configuration.getPossibleSampleVessels();
    
    166
    +        WeightCategoryTreatment weightCategoryTreatment = configuration.getWeightCategoryTreatment();
    
    167
    +        for (String activityId : activityIds) {
    
    168
    +            Activity activity = configuration.getActivity(activityId);
    
    169
    +            // get his trip
    
    170
    +            Trip trip = activity.getTrip();
    
    171
    +            if (!possibleVessels.contains(trip.getVessel())) {
    
    172
    +                // not a matching boat
    
    173
    +                continue;
    
    174
    +            }
    
    175
    +            // recheck activity have some samples.
    
    176
    +            Preconditions.checkState(activity.isSetSpeciesCatWeightNotEmpty(),
    
    177
    +                    String.format("Can not accept an activity (%s) with no sample", activity.getTopiaId()));
    
    178
    +            if (weightCategoryTreatment != null) {
    
    179
    +                // weight category is in stratum, check there is catch using this category
    
    180
    +                boolean foundWeightCategory = activity.withSetSpeciesCatWeight(weightCategoryTreatment);
    
    181
    +                if (!foundWeightCategory) {
    
    182
    +                    // reject - the stratum weight category not found for this activity
    
    183
    +                    continue;
    
    184
    +                }
    
    185
    +            }
    
    186
    +            result.add(activity);
    
    187
    +        }
    
    188
    +        return result;
    
    189
    +    }
    
    160 190
     }

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/Stratum.java
    ... ... @@ -20,21 +20,40 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.stratum;
    
    22 22
     
    
    23
    +import com.google.common.collect.ArrayListMultimap;
    
    23 24
     import com.google.common.collect.ImmutableSet;
    
    25
    +import com.google.common.collect.Multimap;
    
    26
    +import com.google.common.collect.Multimaps;
    
    27
    +import fr.ird.t3.T3IOUtil;
    
    24 28
     import fr.ird.t3.actions.T3Action;
    
    29
    +import fr.ird.t3.entities.cache.LengthWeightConversionWithContextCache;
    
    25 30
     import fr.ird.t3.entities.data.Activity;
    
    31
    +import fr.ird.t3.entities.data.CorrectedElementaryCatch;
    
    32
    +import fr.ird.t3.entities.data.SetSpeciesCatWeight;
    
    33
    +import fr.ird.t3.entities.data.SetSpeciesFrequency;
    
    34
    +import fr.ird.t3.entities.data.SetSpeciesFrequencyTopiaDao;
    
    35
    +import fr.ird.t3.entities.data.WeightCategoryTreatmentAware;
    
    36
    +import fr.ird.t3.entities.reference.LengthWeightConversion;
    
    26 37
     import fr.ird.t3.entities.reference.Species;
    
    38
    +import fr.ird.t3.entities.reference.SpeciesTopiaDao;
    
    27 39
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    40
    +import fr.ird.t3.models.WeightCompositionAggregateModel;
    
    28 41
     import fr.ird.t3.services.T3ServiceContext;
    
    29 42
     import org.nuiton.topia.persistence.TopiaException;
    
    30 43
     
    
    31 44
     import java.io.Closeable;
    
    32 45
     import java.io.IOException;
    
    46
    +import java.util.ArrayList;
    
    33 47
     import java.util.Collection;
    
    48
    +import java.util.Collections;
    
    49
    +import java.util.HashMap;
    
    34 50
     import java.util.Iterator;
    
    51
    +import java.util.LinkedList;
    
    35 52
     import java.util.List;
    
    36 53
     import java.util.Map;
    
    37 54
     import java.util.Set;
    
    55
    +import java.util.function.Function;
    
    56
    +import java.util.stream.Collectors;
    
    38 57
     
    
    39 58
     /**
    
    40 59
      * base class for any stratum.
    
    ... ... @@ -43,14 +62,14 @@ import java.util.Set;
    43 62
      * @see CatchStratum
    
    44 63
      * @since 1.0
    
    45 64
      */
    
    46
    -public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends T3Action<C>> implements Closeable, Iterable<Map.Entry<Activity, Integer>> {
    
    65
    +public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends T3Action<C>, S extends StratumConfiguration<C, A>> implements Closeable, Iterable<Map.Entry<Activity, Integer>> {
    
    47 66
     
    
    48 67
         /**
    
    49 68
          * Stratum configuration of this stratum.
    
    50 69
          *
    
    51 70
          * @see StratumConfiguration
    
    52 71
          */
    
    53
    -    private final StratumConfiguration<C> configuration;
    
    72
    +    private final S configuration;
    
    54 73
         /**
    
    55 74
          * Selected set of species to fix.
    
    56 75
          *
    
    ... ... @@ -67,7 +86,7 @@ public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends
    67 86
          */
    
    68 87
         private Map<Activity, Integer> activities;
    
    69 88
     
    
    70
    -    protected Stratum(StratumConfiguration<C> configuration, Collection<Species> speciesToFix) {
    
    89
    +    protected Stratum(S configuration, Collection<Species> speciesToFix) {
    
    71 90
             this.configuration = configuration;
    
    72 91
             this.speciesToFix = ImmutableSet.copyOf(speciesToFix);
    
    73 92
         }
    
    ... ... @@ -88,7 +107,7 @@ public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends
    88 107
             return activities.entrySet().iterator();
    
    89 108
         }
    
    90 109
     
    
    91
    -    public StratumConfiguration<C> getConfiguration() {
    
    110
    +    public S getConfiguration() {
    
    92 111
             return configuration;
    
    93 112
         }
    
    94 113
     
    
    ... ... @@ -128,4 +147,107 @@ public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends
    128 147
                 throw new IllegalStateException("You must invoke the #init(tx) method before accessing stratum data.");
    
    129 148
             }
    
    130 149
         }
    
    150
    +
    
    151
    +    public Collection<CorrectedElementaryCatch> getCorrectedElementaryCatch(Activity activity) {
    
    152
    +        WeightCategoryTreatment stratumWeightCategoryTreatment = getConfiguration().getWeightCategoryTreatment();
    
    153
    +        if (stratumWeightCategoryTreatment == null) {
    
    154
    +            return activity.getCorrectedElementaryCatch();
    
    155
    +        }
    
    156
    +        return activity.getCorrectedElementaryCatch().stream().filter(c -> stratumWeightCategoryTreatment.equals(c.getWeightCategoryTreatment())).collect(Collectors.toList());
    
    157
    +    }
    
    158
    +
    
    159
    +    public Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> getCorrectedElementaryCatchByCategory(Activity activity) {
    
    160
    +        return Multimaps.index(getCorrectedElementaryCatch(activity), WeightCategoryTreatmentAware::getWeightCategoryTreatment);
    
    161
    +    }
    
    162
    +
    
    163
    +    private Multimap<WeightCategoryTreatment, SetSpeciesCatWeight> getSetSpeciesCatWeightByCategory(Activity activity) {
    
    164
    +        return Multimaps.index(getSetSpeciesCatWeight(activity), WeightCategoryTreatmentAware::getWeightCategoryTreatment);
    
    165
    +    }
    
    166
    +
    
    167
    +    Collection<SetSpeciesCatWeight> getSetSpeciesCatWeight(Activity activity) {
    
    168
    +        WeightCategoryTreatment stratumWeightCategoryTreatment = getConfiguration().getWeightCategoryTreatment();
    
    169
    +        if (stratumWeightCategoryTreatment == null) {
    
    170
    +            return activity.getSetSpeciesCatWeight();
    
    171
    +        }
    
    172
    +        return activity.getSetSpeciesCatWeight().stream().filter(c -> stratumWeightCategoryTreatment.equals(c.getWeightCategoryTreatment())).collect(Collectors.toList());
    
    173
    +    }
    
    174
    +
    
    175
    +    public Collection<SetSpeciesFrequency> getSetSpeciesFrequency(Activity activity) {
    
    176
    +        WeightCategoryTreatment stratumWeightCategoryTreatment = getConfiguration().getWeightCategoryTreatment();
    
    177
    +        if (stratumWeightCategoryTreatment == null) {
    
    178
    +            return activity.getSetSpeciesFrequency();
    
    179
    +        }
    
    180
    +        LengthWeightConversionWithContextCache conversionHelper = getConfiguration().getConversionHelper();
    
    181
    +
    
    182
    +        Multimap<Species, SetSpeciesFrequency> setSpeciesFrequencyBySpecies = SpeciesTopiaDao.groupBySpecies(activity.getSetSpeciesFrequency());
    
    183
    +        Multimap<Species, Integer> lengthClassesBySpecies = ArrayListMultimap.create();
    
    184
    +        // collect all length classes by species
    
    185
    +        SetSpeciesFrequencyTopiaDao.collectLengthClasses(setSpeciesFrequencyBySpecies, lengthClassesBySpecies);
    
    186
    +        List<SetSpeciesFrequency> result = new LinkedList<>();
    
    187
    +        for (Map.Entry<Species, Collection<SetSpeciesFrequency>> entry : setSpeciesFrequencyBySpecies.asMap().entrySet()) {
    
    188
    +            Species species = entry.getKey();
    
    189
    +            LengthWeightConversion conversion = conversionHelper.getConversions(species);
    
    190
    +            Collection<SetSpeciesFrequency> setSizes = entry.getValue();
    
    191
    +            List<Integer> lengthClasses = new ArrayList<>(lengthClassesBySpecies.get(species));
    
    192
    +            Collections.sort(lengthClasses);
    
    193
    +            List<Integer> lengthClassesAccepted = conversionHelper.getLengthClasses(conversion, stratumWeightCategoryTreatment, lengthClasses);
    
    194
    +            result.addAll(setSizes.stream().filter(f -> lengthClassesAccepted.contains(f.getLfLengthClass())).collect(Collectors.toList()));
    
    195
    +        }
    
    196
    +        return result;
    
    197
    +    }
    
    198
    +
    
    199
    +    protected void fillWeightsFromCatchesWeight(Activity activity, WeightCompositionAggregateModel model, int dividerFactor) {
    
    200
    +        Map<WeightCategoryTreatment, Map<Species, Float>> weights = new HashMap<>();
    
    201
    +        Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> data = getCorrectedElementaryCatchByCategory(activity);
    
    202
    +        T3IOUtil.fillMapWithDefaultValue(weights, data.keySet(), HashMap::new);
    
    203
    +        for (WeightCategoryTreatment weightCategory : data.keySet()) {
    
    204
    +            Map<Species, Float> speciesFloatMap = weights.get(weightCategory);
    
    205
    +            Collection<CorrectedElementaryCatch> correctedElementaryCatches = data.get(weightCategory);
    
    206
    +            fillWeights(weightCategory,
    
    207
    +                    correctedElementaryCatches,
    
    208
    +                    speciesFloatMap,
    
    209
    +                    CorrectedElementaryCatch::getCatchWeight,
    
    210
    +                    model,
    
    211
    +                    dividerFactor);
    
    212
    +        }
    
    213
    +    }
    
    214
    +
    
    215
    +    protected void fillWeightsFromSamplesWeight(Activity activity,
    
    216
    +                                                Map<WeightCategoryTreatment, Map<Species, Float>> weights,
    
    217
    +                                                WeightCompositionAggregateModel model) {
    
    218
    +        if (weights == null) {
    
    219
    +            weights = new HashMap<>();
    
    220
    +        }
    
    221
    +        Multimap<WeightCategoryTreatment, SetSpeciesCatWeight> data = getSetSpeciesCatWeightByCategory(activity);
    
    222
    +        T3IOUtil.fillMapWithDefaultValue(weights, data.keySet(), HashMap::new);
    
    223
    +        for (WeightCategoryTreatment weightCategory : data.keySet()) {
    
    224
    +            Map<Species, Float> speciesFloatMap = weights.get(weightCategory);
    
    225
    +            Collection<SetSpeciesCatWeight> setSpeciesCatWeights = data.get(weightCategory);
    
    226
    +            fillWeights(weightCategory, setSpeciesCatWeights, speciesFloatMap, SetSpeciesCatWeight::getWeight, model, 1);
    
    227
    +        }
    
    228
    +    }
    
    229
    +
    
    230
    +    protected <X extends WeightCategoryTreatmentAware> void fillWeights(WeightCategoryTreatment weightCategory,
    
    231
    +                                                                        Collection<X> data,
    
    232
    +                                                                        Map<Species, Float> weights,
    
    233
    +                                                                        Function<X, Float> function,
    
    234
    +                                                                        WeightCompositionAggregateModel model,
    
    235
    +                                                                        int divideFactor) {
    
    236
    +        if (weights == null) {
    
    237
    +            weights = new HashMap<>();
    
    238
    +        }
    
    239
    +        for (X datum : data) {
    
    240
    +            Species species = datum.getSpecies();
    
    241
    +            Float weight = weights.get(species);
    
    242
    +            if (weight == null) {
    
    243
    +                weight = 0f;
    
    244
    +            }
    
    245
    +            weight += function.apply(datum) / divideFactor;
    
    246
    +            weights.put(species, weight);
    
    247
    +        }
    
    248
    +        if (model != null) {
    
    249
    +            model.addModel(weightCategory, weights);
    
    250
    +        }
    
    251
    +    }
    
    252
    +
    
    131 253
     }

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/StratumConfiguration.java
    ... ... @@ -20,11 +20,13 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.actions.stratum;
    
    22 22
     
    
    23
    -import com.google.common.cache.LoadingCache;
    
    24 23
     import com.google.common.collect.ImmutableSet;
    
    24
    +import fr.ird.t3.actions.T3Action;
    
    25
    +import fr.ird.t3.entities.cache.LengthWeightConversionWithContextCache;
    
    25 26
     import fr.ird.t3.entities.data.Activity;
    
    26
    -import fr.ird.t3.entities.reference.AbstractSchoolTypeTopiaDao;
    
    27
    +import fr.ird.t3.entities.data.SpeciesAware;
    
    27 28
     import fr.ird.t3.entities.reference.SchoolType;
    
    29
    +import fr.ird.t3.entities.reference.SchoolTypeTopiaDao;
    
    28 30
     import fr.ird.t3.entities.reference.Vessel;
    
    29 31
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    30 32
     import fr.ird.t3.entities.reference.zone.ZoneStratumAware;
    
    ... ... @@ -33,12 +35,14 @@ import fr.ird.t3.entities.type.T3Date;
    33 35
     
    
    34 36
     import java.util.Collection;
    
    35 37
     import java.util.Iterator;
    
    38
    +import java.util.List;
    
    36 39
     import java.util.Map;
    
    37 40
     import java.util.Objects;
    
    38 41
     import java.util.Set;
    
    39 42
     import java.util.concurrent.ExecutionException;
    
    40 43
     import java.util.function.BiConsumer;
    
    41 44
     import java.util.function.Function;
    
    45
    +import java.util.function.Predicate;
    
    42 46
     
    
    43 47
     /**
    
    44 48
      * Configuration of a stratum.
    
    ... ... @@ -46,57 +50,54 @@ import java.util.function.Function;
    46 50
      * @author Tony Chemit - dev@tchemit.fr
    
    47 51
      * @since 1.0
    
    48 52
      */
    
    49
    -public class StratumConfiguration<C extends LevelConfigurationWithStratum> {
    
    53
    +public class StratumConfiguration<C extends LevelConfigurationWithStratum, A extends T3Action<C>> {
    
    50 54
     
    
    51
    -    private final C configuration;
    
    55
    +    private final LevelInputContext<C, A> inputContext;
    
    52 56
         private final Collection<ZoneStratumAware> zones;
    
    53
    -    private final ZoneStratumAwareMeta zoneMeta;
    
    54 57
         private final ZoneStratumAware zone;
    
    55 58
         private final SchoolType schoolType;
    
    56 59
         private final WeightCategoryTreatment weightCategoryTreatment;
    
    57 60
         private final T3Date beginDate;
    
    58 61
         private final T3Date endDate;
    
    59
    -    private final Set<Vessel> possibleCatchVessels;
    
    60
    -    private final Set<Vessel> possibleSampleVessels;
    
    61 62
         private final Map<String, Integer> stratumMinimumCountBySpecie;
    
    62
    -    private final LoadingCache<String, Activity> activityCache;
    
    63
    +    private final List<WeightCategoryTreatment> weightCategoryTreatments;
    
    63 64
         private final int stratumIndex;
    
    65
    +    private final LengthWeightConversionWithContextCache conversionHelper;
    
    64 66
         private String[] zoneIds;
    
    65 67
     
    
    66
    -    protected StratumConfiguration(C configuration,
    
    67
    -                                   ZoneStratumAwareMeta zoneMeta,
    
    68
    +    protected StratumConfiguration(LevelInputContext<C, A> inputContext,
    
    68 69
                                        ZoneStratumAware zone,
    
    69 70
                                        SchoolType schoolType,
    
    70 71
                                        WeightCategoryTreatment weightCategoryTreatment,
    
    71 72
                                        T3Date beginDate,
    
    72 73
                                        T3Date endDate,
    
    73 74
                                        Collection<ZoneStratumAware> zones,
    
    74
    -                                   Set<Vessel> possibleCatchVessels,
    
    75
    -                                   Set<Vessel> possibleSampleVessels,
    
    76 75
                                        Map<String, Integer> stratumMinimumCountBySpecie,
    
    77
    -                                   LoadingCache<String, Activity> activityCache,
    
    76
    +                                   List<WeightCategoryTreatment> weightCategoryTreatments,
    
    78 77
                                        int stratumIndex) {
    
    79
    -        this.configuration = configuration;
    
    80
    -        this.zoneMeta = zoneMeta;
    
    78
    +        this.inputContext = inputContext;
    
    81 79
             this.zone = zone;
    
    82 80
             this.schoolType = schoolType;
    
    81
    +        this.weightCategoryTreatments = weightCategoryTreatments;
    
    83 82
             this.weightCategoryTreatment = weightCategoryTreatment;
    
    84 83
             this.beginDate = beginDate;
    
    85 84
             this.endDate = endDate;
    
    86 85
             this.zones = zones;
    
    87
    -        this.possibleCatchVessels = possibleCatchVessels;
    
    88
    -        this.possibleSampleVessels = possibleSampleVessels;
    
    89 86
             this.stratumMinimumCountBySpecie = stratumMinimumCountBySpecie;
    
    90
    -        this.activityCache = activityCache;
    
    91 87
             this.stratumIndex = stratumIndex;
    
    88
    +        this.conversionHelper = inputContext.newLengthWeightConversionWithContextCache(zone.getOcean(), beginDate.toBeginDate());
    
    89
    +    }
    
    90
    +
    
    91
    +    public LengthWeightConversionWithContextCache getConversionHelper() {
    
    92
    +        return conversionHelper;
    
    92 93
         }
    
    93 94
     
    
    94 95
         public C getConfiguration() {
    
    95
    -        return configuration;
    
    96
    +        return inputContext.getConfiguration();
    
    96 97
         }
    
    97 98
     
    
    98 99
         private ZoneStratumAwareMeta getZoneMeta() {
    
    99
    -        return zoneMeta;
    
    100
    +        return inputContext.getZoneMeta();
    
    100 101
         }
    
    101 102
     
    
    102 103
         public String getZoneTableName() {
    
    ... ... @@ -113,15 +114,15 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> {
    113 114
     
    
    114 115
         public Set<String> getSchoolTypeIds() {
    
    115 116
             ImmutableSet.Builder<String> builder = ImmutableSet.<String>builder().add(getSchoolType().getTopiaId());
    
    116
    -        switch (configuration.getSchoolTypeIndeterminate()) {
    
    117
    +        switch (getConfiguration().getSchoolTypeIndeterminate()) {
    
    117 118
                 case ALL_IN_BO:
    
    118
    -                if (AbstractSchoolTypeTopiaDao.SCHOOL_TYPE_BO_ID.equals(getSchoolType().getTopiaId())) {
    
    119
    -                    builder.add(AbstractSchoolTypeTopiaDao.SCHOOL_TYPE_INDETERMINATE_ID);
    
    119
    +                if (SchoolTypeTopiaDao.SCHOOL_TYPE_BO_ID.equals(getSchoolType().getTopiaId())) {
    
    120
    +                    builder.add(SchoolTypeTopiaDao.SCHOOL_TYPE_INDETERMINATE_ID);
    
    120 121
                     }
    
    121 122
                     break;
    
    122 123
                 case ALL_IN_BL:
    
    123
    -                if (AbstractSchoolTypeTopiaDao.SCHOOL_TYPE_BL_ID.equals(getSchoolType().getTopiaId())) {
    
    124
    -                    builder.add(AbstractSchoolTypeTopiaDao.SCHOOL_TYPE_INDETERMINATE_ID);
    
    124
    +                if (SchoolTypeTopiaDao.SCHOOL_TYPE_BL_ID.equals(getSchoolType().getTopiaId())) {
    
    125
    +                    builder.add(SchoolTypeTopiaDao.SCHOOL_TYPE_INDETERMINATE_ID);
    
    125 126
                     }
    
    126 127
                     break;
    
    127 128
                 case IGNORE:
    
    ... ... @@ -143,11 +144,11 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> {
    143 144
         }
    
    144 145
     
    
    145 146
         public Set<Vessel> getPossibleCatchVessels() {
    
    146
    -        return possibleCatchVessels;
    
    147
    +        return inputContext.getPossibleCatchVessels();
    
    147 148
         }
    
    148 149
     
    
    149 150
         public Set<Vessel> getPossibleSampleVessels() {
    
    150
    -        return possibleSampleVessels;
    
    151
    +        return inputContext.getPossibleSampleVessels();
    
    151 152
         }
    
    152 153
     
    
    153 154
         public Map<String, Integer> getStratumMinimumCountBySpecie() {
    
    ... ... @@ -162,6 +163,14 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> {
    162 163
             return stratumIndex;
    
    163 164
         }
    
    164 165
     
    
    166
    +    public List<WeightCategoryTreatment> getWeightCategoryTreatments() {
    
    167
    +        return weightCategoryTreatments;
    
    168
    +    }
    
    169
    +
    
    170
    +    public Predicate<? super SpeciesAware> getSpeciesToFixFilter() {
    
    171
    +        return inputContext.getSpeciesToFixFilter();
    
    172
    +    }
    
    173
    +
    
    165 174
         public String[] getZoneIds() {
    
    166 175
             if (zoneIds == null) {
    
    167 176
                 Collection<ZoneStratumAware> allZones = getZones();
    
    ... ... @@ -177,7 +186,7 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> {
    177 186
     
    
    178 187
         public Activity getActivity(String activityId) {
    
    179 188
             try {
    
    180
    -            return activityCache.get(activityId);
    
    189
    +            return inputContext.getActivityCache().get(activityId);
    
    181 190
             } catch (ExecutionException e) {
    
    182 191
                 throw new RuntimeException(String.format("Could not obtain activity %s", activityId), e);
    
    183 192
             }
    
    ... ... @@ -194,7 +203,7 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> {
    194 203
             if (currentLevel == null) {
    
    195 204
                 result = "";
    
    196 205
             }
    
    197
    -        result += String.format("(%s;%s;%d)", zone.getLabel1(), configuration.isUseWeightCategoriesInStratum() ? weightCategoryTreatment.getLabel1() : "NA", level);
    
    206
    +        result += String.format("(%s;%s;%d)", zone.getLabel1(), getConfiguration().isUseWeightCategoriesInStratum() ? weightCategoryTreatment.getLabel1() : "NA", level);
    
    198 207
             Objects.requireNonNull(consumer).accept(activity, result);
    
    199 208
         }
    
    200 209
     }

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/StratumResult.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -32,7 +32,7 @@ import java.io.Closeable;
    32 32
      */
    
    33 33
     public abstract class StratumResult<C extends LevelConfigurationWithStratum> implements Closeable {
    
    34 34
     
    
    35
    -    private final StratumConfiguration<C> configuration;
    
    35
    +    private final StratumConfiguration<C, ?> configuration;
    
    36 36
     
    
    37 37
         private final String label;
    
    38 38
     
    
    ... ... @@ -42,12 +42,12 @@ public abstract class StratumResult<C extends LevelConfigurationWithStratum> imp
    42 42
     
    
    43 43
         private int nbActivitiesWithSample;
    
    44 44
     
    
    45
    -    protected StratumResult(StratumConfiguration<C> configuration, String label) {
    
    45
    +    protected StratumResult(StratumConfiguration<C, ?> configuration, String label) {
    
    46 46
             this.configuration = configuration;
    
    47 47
             this.label = label;
    
    48 48
         }
    
    49 49
     
    
    50
    -    public StratumConfiguration<C> getConfiguration() {
    
    50
    +    public StratumConfiguration<C, ?> getConfiguration() {
    
    51 51
             return configuration;
    
    52 52
         }
    
    53 53
     
    
    ... ... @@ -59,30 +59,30 @@ public abstract class StratumResult<C extends LevelConfigurationWithStratum> imp
    59 59
             return substitutionLevel;
    
    60 60
         }
    
    61 61
     
    
    62
    -    public int getNbActivities() {
    
    63
    -        return nbActivities;
    
    64
    -    }
    
    65
    -
    
    66
    -    public int getNbActivitiesWithSample() {
    
    67
    -        return nbActivitiesWithSample;
    
    68
    -    }
    
    69
    -
    
    70
    -    public int getNbActivitiesWithoutSample() {
    
    71
    -        return nbActivities - nbActivitiesWithSample;
    
    72
    -    }
    
    73
    -
    
    74 62
         public void setSubstitutionLevel(int substitutionLevel) {
    
    75 63
             this.substitutionLevel = substitutionLevel;
    
    76 64
         }
    
    77 65
     
    
    66
    +    public int getNbActivities() {
    
    67
    +        return nbActivities;
    
    68
    +    }
    
    69
    +
    
    78 70
         public void setNbActivities(int nbActivities) {
    
    79 71
             this.nbActivities = nbActivities;
    
    80 72
         }
    
    81 73
     
    
    74
    +    public int getNbActivitiesWithSample() {
    
    75
    +        return nbActivitiesWithSample;
    
    76
    +    }
    
    77
    +
    
    82 78
         public void setNbActivitiesWithSample(int nbActivitiesWithSample) {
    
    83 79
             this.nbActivitiesWithSample = nbActivitiesWithSample;
    
    84 80
         }
    
    85 81
     
    
    82
    +    public int getNbActivitiesWithoutSample() {
    
    83
    +        return nbActivities - nbActivitiesWithSample;
    
    84
    +    }
    
    85
    +
    
    86 86
         public void addNbActivities(int nbActivities) {
    
    87 87
             this.nbActivities += nbActivities;
    
    88 88
         }
    

  • t3-domain/src/main/java/fr/ird/t3/entities/cache/LengthWeightConversionCache.java
    ... ... @@ -25,12 +25,14 @@ import fr.ird.t3.entities.reference.LengthWeightConversionTopiaDao;
    25 25
     import fr.ird.t3.entities.reference.Ocean;
    
    26 26
     import fr.ird.t3.entities.reference.Species;
    
    27 27
     import fr.ird.t3.entities.reference.WeightCategory;
    
    28
    +import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    28 29
     import fr.ird.t3.entities.type.T3Date;
    
    29 30
     import org.apache.commons.logging.Log;
    
    30 31
     import org.apache.commons.logging.LogFactory;
    
    31 32
     
    
    32 33
     import java.util.Date;
    
    33 34
     import java.util.Iterator;
    
    35
    +import java.util.LinkedList;
    
    34 36
     import java.util.List;
    
    35 37
     import java.util.Map;
    
    36 38
     import java.util.TreeMap;
    
    ... ... @@ -133,4 +135,24 @@ public class LengthWeightConversionCache {
    133 135
             return result;
    
    134 136
         }
    
    135 137
     
    
    138
    +    public List<Integer> getLengthClasses(LengthWeightConversion conversion, WeightCategoryTreatment weightCategoryTreatment, List<Integer> lengthClasses) {
    
    139
    +        Integer min = weightCategoryTreatment.getMin();
    
    140
    +        Integer minLengthClass = null;
    
    141
    +        if (min != null) {
    
    142
    +            minLengthClass = getSpecieHighestLengthClass(conversion, min);
    
    143
    +        }
    
    144
    +        Integer max = weightCategoryTreatment.getMax();
    
    145
    +        Integer maxLengthClass = null;
    
    146
    +        if (max != null) {
    
    147
    +            maxLengthClass = getSpecieHighestLengthClass(conversion, max);
    
    148
    +        }
    
    149
    +        List<Integer> result = new LinkedList<>();
    
    150
    +        for (Integer lengthClass : lengthClasses) {
    
    151
    +            if (minLengthClass != null && lengthClass < minLengthClass || maxLengthClass != null && lengthClass > maxLengthClass) {
    
    152
    +                continue;
    
    153
    +            }
    
    154
    +            result.add(lengthClass);
    
    155
    +        }
    
    156
    +        return result;
    
    157
    +    }
    
    136 158
     }

  • t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
    ... ... @@ -222,4 +222,9 @@ public class ActivityImpl extends ActivityAbstract {
    222 222
         public boolean withCorrectedElementaryCatch(WeightCategoryTreatment weightCategoryTreatment) {
    
    223 223
             return isCorrectedElementaryCatchNotEmpty() && getCorrectedElementaryCatch().stream().map(CorrectedElementaryCatch::getWeightCategoryTreatment).anyMatch(c -> c.equals(weightCategoryTreatment));
    
    224 224
         }
    
    225
    +
    
    226
    +    @Override
    
    227
    +    public boolean withSetSpeciesCatWeight(WeightCategoryTreatment weightCategoryTreatment) {
    
    228
    +        return isSetSpeciesCatWeightNotEmpty() && getSetSpeciesCatWeight().stream().map(SetSpeciesCatWeight::getWeightCategoryTreatment).anyMatch(c -> c.equals(weightCategoryTreatment));
    
    229
    +    }
    
    225 230
     }

  • t3-domain/src/main/xmi/t3-persistence.zargo
    No preview for this file type