Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
11 changed files:
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratum.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratumLoader.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratum.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratum.java
- t3-actions/src/test/java/fr/ird/t3/actions/ActionResumeTest.java
- t3-domain/src/main/java/fr/ird/t3/actions/stratum/SampleStratum.java
- t3-domain/src/main/java/fr/ird/t3/entities/reference/LengthWeightConversionHelper.java
- t3-domain/src/main/java/fr/ird/t3/models/WeightCompositionAggregateModel.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/LengthWeightConversionHelperTest.java
Changes:
| ... | ... | @@ -38,7 +38,6 @@ import fr.ird.t3.entities.reference.Species; |
| 38 | 38 |
import fr.ird.t3.entities.reference.SpeciesTopiaDao;
|
| 39 | 39 |
import fr.ird.t3.entities.reference.WeightCategories;
|
| 40 | 40 |
import fr.ird.t3.entities.reference.WeightCategorySample;
|
| 41 |
-import fr.ird.t3.entities.reference.WeightCategorySampleImpl;
|
|
| 42 | 41 |
import fr.ird.t3.services.DecoratorService;
|
| 43 | 42 |
import fr.ird.t3.services.ioc.InjectDAO;
|
| 44 | 43 |
import org.apache.commons.logging.Log;
|
| ... | ... | @@ -46,6 +45,7 @@ import org.apache.commons.logging.LogFactory; |
| 46 | 45 |
import org.nuiton.util.TimeLog;
|
| 47 | 46 |
|
| 48 | 47 |
import java.util.Collection;
|
| 48 |
+import java.util.Date;
|
|
| 49 | 49 |
import java.util.HashMap;
|
| 50 | 50 |
import java.util.HashSet;
|
| 51 | 51 |
import java.util.Map;
|
| ... | ... | @@ -54,7 +54,7 @@ import java.util.Set; |
| 54 | 54 |
import static org.nuiton.i18n.I18n.l;
|
| 55 | 55 |
|
| 56 | 56 |
/**
|
| 57 |
- * Extrapolate weigth from sample to their owing set.
|
|
| 57 |
+ * Extrapolate weight from sample to their owing set.
|
|
| 58 | 58 |
*
|
| 59 | 59 |
* @author Tony Chemit - dev@tchemit.fr
|
| 60 | 60 |
* @since 1.0
|
| ... | ... | @@ -69,16 +69,13 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 69 | 69 |
private LengthWeightConversionTopiaDao lengthWeightConversionDAO;
|
| 70 | 70 |
@InjectDAO(entityType = SetSpeciesFrequency.class)
|
| 71 | 71 |
private SetSpeciesFrequencyTopiaDao setSpeciesFrequencyDAO;
|
| 72 |
- // @InjectDAO(entityType = WeightCategoryWellPlan.class)
|
|
| 73 |
-// private WeightCategoryWellPlanTopiaDao weightCategoryWellPlanDAO;
|
|
| 74 |
- // private WeightCategoryWellPlan categoryM10;
|
|
| 75 |
-// private WeightCategoryWellPlan categoryP10;
|
|
| 76 | 72 |
private LengthWeightConversionHelper conversionHelper;
|
| 77 | 73 |
|
| 78 | 74 |
public ExtrapolateSampleWeightToSetAction() {
|
| 79 | 75 |
super(Level1Step.EXTRAPOLATE_SAMPLE_WEIGHT_TO_SET);
|
| 80 | 76 |
}
|
| 81 | 77 |
|
| 78 |
+ @SuppressWarnings("unused")
|
|
| 82 | 79 |
public int getNbTreatedSets() {
|
| 83 | 80 |
return nbTreatedSets;
|
| 84 | 81 |
}
|
| ... | ... | @@ -87,6 +84,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 87 | 84 |
this.nbTreatedSets = nbTreatedSets;
|
| 88 | 85 |
}
|
| 89 | 86 |
|
| 87 |
+ @SuppressWarnings("unused")
|
|
| 90 | 88 |
public float getNbTreatedFishesInSamples() {
|
| 91 | 89 |
return nbTreatedFishesInSamples;
|
| 92 | 90 |
}
|
| ... | ... | @@ -95,6 +93,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 95 | 93 |
this.nbTreatedFishesInSamples = nbTreatedFishesInSamples;
|
| 96 | 94 |
}
|
| 97 | 95 |
|
| 96 |
+ @SuppressWarnings("unused")
|
|
| 98 | 97 |
public float getNbCreatedFishesInSetSpeciesFrequency() {
|
| 99 | 98 |
return nbCreatedFishesInSetSpeciesFrequency;
|
| 100 | 99 |
}
|
| ... | ... | @@ -106,10 +105,6 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 106 | 105 |
@Override
|
| 107 | 106 |
protected void prepareAction() throws Exception {
|
| 108 | 107 |
super.prepareAction();
|
| 109 |
-// // get the -10Kg category
|
|
| 110 |
-// setCategoryM10(weightCategoryWellPlanDAO.forCodeEquals(1).findUnique());
|
|
| 111 |
-// // get the +10Kg category
|
|
| 112 |
-// setCategoryP10(weightCategoryWellPlanDAO.forCodeEquals(2).findUnique());
|
|
| 113 | 108 |
conversionHelper = lengthWeightConversionDAO.newConversionHelper();
|
| 114 | 109 |
}
|
| 115 | 110 |
|
| ... | ... | @@ -137,21 +132,21 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 137 | 132 |
|
| 138 | 133 |
private void doExecuteTrip(Trip trip, Collection<Sample> samples) {
|
| 139 | 134 |
incrementsProgression();
|
| 140 |
- //FIXME I replace ocean by trip.departureHarbour.ocean, check this is ok (See #260)
|
|
| 141 |
- // get the length class +10kg limit
|
|
| 142 |
- Map<Species, Integer> limitLengthClassBySpecie = getThredHoldPlus10ForSpecies(trip, samples, trip.getDepartureHarbour().getOcean());
|
|
| 143 | 135 |
Set<Activity> tripActivities = new HashSet<>();
|
| 144 | 136 |
// extrapolate for each sample set number to set
|
| 145 | 137 |
for (Sample sample : samples) {
|
| 146 | 138 |
long s0 = TimeLog.getTime();
|
| 147 | 139 |
incrementsProgression();
|
| 148 |
- String sampleStr = l(locale, "t3.level1.extrapolateSampleWeightToSet.sampleStr",
|
|
| 149 |
- decorate(trip), sample.getSampleNumber());
|
|
| 140 |
+ String sampleStr = l(locale, "t3.level1.extrapolateSampleWeightToSet.sampleStr", decorate(trip), sample.getSampleNumber());
|
|
| 150 | 141 |
float nb = sample.getTotalStandardiseSampleSpeciesFrequencyNumber();
|
| 151 | 142 |
addInfoMessage(l(locale, "t3.level1.extrapolateSampleWeightToSet.sample.nbFishes", sampleStr, nb));
|
| 152 | 143 |
nbTreatedFishesInSamples += nb;
|
| 144 |
+ Set<Species> species = SpeciesTopiaDao.getAllSpeciesFromSampleSpecies(samples);
|
|
| 153 | 145 |
for (SampleSet sampleSet : sample.getSampleSet()) {
|
| 154 | 146 |
Activity activity = sampleSet.getActivity();
|
| 147 |
+ Ocean ocean = activity.getOcean();
|
|
| 148 |
+ // get the length class +10kg limit
|
|
| 149 |
+ Map<Species, Integer> limitLengthClassBySpecie = getThresholdPlus10ForSpecies(species, ocean, activity.getRoute().getDate());
|
|
| 155 | 150 |
boolean added = tripActivities.add(activity);
|
| 156 | 151 |
if (added) {
|
| 157 | 152 |
// remove all stuff from activity
|
| ... | ... | @@ -240,7 +235,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 240 | 235 |
}
|
| 241 | 236 |
|
| 242 | 237 |
/**
|
| 243 |
- * Given a sample well, compute the {@link SampleWellSetWeight}, says :
|
|
| 238 |
+ * Given a sample well, compute the {@link SampleWellSetWeight}, says:
|
|
| 244 | 239 |
* <ul>
|
| 245 | 240 |
* <li>his total weight</<li>
|
| 246 | 241 |
* <li>his weight of -10Kg category</<li>
|
| ... | ... | @@ -272,25 +267,25 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 272 | 267 |
*
|
| 273 | 268 |
* @param sampleWellStr sampleSet decorate value
|
| 274 | 269 |
* @param setWeight the sampleSet weight computed
|
| 275 |
- * @param sampletWeight the sampleSet weight computed
|
|
| 270 |
+ * @param sampleWeight the sampleSet weight computed
|
|
| 276 | 271 |
* @param useRfMinus10AndRfPlus10 flag to try to use rf-10 and rf+10
|
| 277 | 272 |
* @return the computed rf context for the given sample set
|
| 278 | 273 |
*/
|
| 279 |
- private RFContext computeRFContext(String sampleWellStr, SampleWellSetWeight setWeight, SampleWellSampleWeight sampletWeight, boolean useRfMinus10AndRfPlus10) {
|
|
| 274 |
+ private RFContext computeRFContext(String sampleWellStr, SampleWellSetWeight setWeight, SampleWellSampleWeight sampleWeight, boolean useRfMinus10AndRfPlus10) {
|
|
| 280 | 275 |
float pondt = setWeight.getTotalWeight();
|
| 281 | 276 |
Float pondp = setWeight.getPlus10Weight();
|
| 282 | 277 |
Float pondm = setWeight.getMinus10Weight();
|
| 283 | 278 |
// compute rftot
|
| 284 |
- float pdecht = sampletWeight.getTotalWeight();
|
|
| 279 |
+ float pdecht = sampleWeight.getTotalWeight();
|
|
| 285 | 280 |
float rftot = pondt / pdecht;
|
| 286 | 281 |
// compute rfMinus10
|
| 287 |
- Float pdechm = sampletWeight.getMinus10Weight();
|
|
| 282 |
+ Float pdechm = sampleWeight.getMinus10Weight();
|
|
| 288 | 283 |
Float rfMinus10 = null;
|
| 289 | 284 |
if (pdechm != null && pdechm > 0 && pondm != null) {
|
| 290 | 285 |
rfMinus10 = pondm / pdechm;
|
| 291 | 286 |
}
|
| 292 | 287 |
// compute rfPlus10
|
| 293 |
- Float pdechp = sampletWeight.getPlus10Weight();
|
|
| 288 |
+ Float pdechp = sampleWeight.getPlus10Weight();
|
|
| 294 | 289 |
Float rfPlus10 = null;
|
| 295 | 290 |
if (pdechp != null && pdechp > 0 && pondp != null) {
|
| 296 | 291 |
rfPlus10 = pondp / pdechp;
|
| ... | ... | @@ -310,7 +305,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 310 | 305 |
rfMinus10Status = RfUsageStatus.REJECTED_RF_NOT_DEFINED;
|
| 311 | 306 |
} else {
|
| 312 | 307 |
int rfMinus10MinNumber = getConfiguration().getRfMinus10MinNumber();
|
| 313 |
- Float sampletWeightMinus10Number = sampletWeight.getMinus10Number();
|
|
| 308 |
+ Float sampletWeightMinus10Number = sampleWeight.getMinus10Number();
|
|
| 314 | 309 |
if (Math.abs(rfMinus10) < 0.001f) {
|
| 315 | 310 |
addWarningMessage(l(locale, "t3.level1.extrapolateSampleWeightToSet.warning.rfMinus10.too.low",
|
| 316 | 311 |
sampleWellStr, rfMinus10, rftot));
|
| ... | ... | @@ -331,7 +326,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 331 | 326 |
rfPlus10Status = RfUsageStatus.REJECTED_RF_NOT_DEFINED;
|
| 332 | 327 |
} else {
|
| 333 | 328 |
int rfPlus10MinNumber = getConfiguration().getRfPlus10MinNumber();
|
| 334 |
- Float sampletWeightPlus10Number = sampletWeight.getPlus10Number();
|
|
| 329 |
+ Float sampletWeightPlus10Number = sampleWeight.getPlus10Number();
|
|
| 335 | 330 |
if (Math.abs(rfPlus10) < 0.001f) {
|
| 336 | 331 |
addWarningMessage(l(locale, "t3.level1.extrapolateSampleWeightToSet.warning.rfPlus10.too.low",
|
| 337 | 332 |
sampleWellStr, rfPlus10, rftot));
|
| ... | ... | @@ -387,25 +382,21 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 387 | 382 |
}
|
| 388 | 383 |
|
| 389 | 384 |
/**
|
| 390 |
- * Obtain for each species used in one of the given sample the first length
|
|
| 391 |
- * class which represents a +10Kg weight.
|
|
| 385 |
+ * Obtain for each species used in one of the given sample the first length class which represents a +10Kg weight.
|
|
| 392 | 386 |
*
|
| 393 |
- * @param trip the trip where samples are done
|
|
| 394 |
- * @param samples the sample to scan
|
|
| 395 |
- * @param ocean ocean where trip happens
|
|
| 387 |
+ * @param species species to scan
|
|
| 388 |
+ * @param ocean where (used to get conversion)
|
|
| 389 |
+ * @param date when (used to get conversion)
|
|
| 396 | 390 |
* @return the universe of length class limits computed indexed by species
|
| 397 | 391 |
*/
|
| 398 |
- private Map<Species, Integer> getThredHoldPlus10ForSpecies(Trip trip, Collection<Sample> samples, Ocean ocean) {
|
|
| 399 |
- Set<Species> species = SpeciesTopiaDao.getAllSpeciesFromSampleSpecies(samples);
|
|
| 392 |
+ private Map<Species, Integer> getThresholdPlus10ForSpecies(Set<Species> species, Ocean ocean, Date date) {
|
|
| 400 | 393 |
// for each of those species, found the length class which matches a weight > 10Kg
|
| 401 | 394 |
Map<Species, Integer> result = new HashMap<>();
|
| 402 | 395 |
for (Species specie : species) {
|
| 403 |
- LengthWeightConversion conversion = conversionHelper.getConversions(specie, ocean, 0, trip.getLandingDate());
|
|
| 396 |
+ LengthWeightConversion conversion = conversionHelper.getConversions(specie, ocean, 0, date);
|
|
| 404 | 397 |
if (conversion != null) {
|
| 405 | 398 |
// only add conversion for species if found
|
| 406 |
- WeightCategorySample fakeCategory = new WeightCategorySampleImpl();
|
|
| 407 |
- fakeCategory.setMax(10);
|
|
| 408 |
- int lengthClass = conversionHelper.getSpecieHighestLengthClass(conversion, fakeCategory);
|
|
| 399 |
+ int lengthClass = conversionHelper.getSpecieHighestLengthClass(conversion, 10);
|
|
| 409 | 400 |
result.put(specie, lengthClass);
|
| 410 | 401 |
}
|
| 411 | 402 |
}
|
| ... | ... | @@ -417,14 +408,6 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 417 | 408 |
return result;
|
| 418 | 409 |
}
|
| 419 | 410 |
|
| 420 |
-// private void setCategoryM10(WeightCategoryWellPlan categoryM10) {
|
|
| 421 |
-// this.categoryM10 = categoryM10;
|
|
| 422 |
-// }
|
|
| 423 |
-//
|
|
| 424 |
-// private void setCategoryP10(WeightCategoryWellPlan categoryP10) {
|
|
| 425 |
-// this.categoryP10 = categoryP10;
|
|
| 426 |
-// }
|
|
| 427 |
- |
|
| 428 | 411 |
/**
|
| 429 | 412 |
* This object contains the sample weights (-10,+10 and total) for sample well.
|
| 430 | 413 |
* <ul>
|
| ... | ... | @@ -436,9 +419,9 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 436 | 419 |
*/
|
| 437 | 420 |
protected static class SampleWellSampleWeight {
|
| 438 | 421 |
|
| 439 |
- /** sum of fishes wieght for length class < +10Kg. */
|
|
| 422 |
+ /** sum of fishes weight for length class < +10Kg. */
|
|
| 440 | 423 |
Float minus10Weight;
|
| 441 |
- /** sum of fishes wieght for length class > +10Kg. */
|
|
| 424 |
+ /** sum of fishes weight for length class > +10Kg. */
|
|
| 442 | 425 |
Float plus10Weight;
|
| 443 | 426 |
/** Number of fishes for length class > -10Kg. */
|
| 444 | 427 |
private Float plus10Number;
|
| ... | ... | @@ -476,8 +459,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 476 | 459 |
}
|
| 477 | 460 |
|
| 478 | 461 |
/**
|
| 479 |
- * This object contains the set weights (-10,+10 and total) for
|
|
| 480 |
- * sample well.
|
|
| 462 |
+ * This object contains the set weights (-10,+10 and total) for sample well.
|
|
| 481 | 463 |
* <ul>
|
| 482 | 464 |
* <li>{@link #getMinus10Weight()} is legacy {@code pondm}</li>
|
| 483 | 465 |
* <li>{@link #getPlus10Weight()}} is legacy {@code pondp}</li>
|
| ... | ... | @@ -486,11 +468,11 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action { |
| 486 | 468 |
*/
|
| 487 | 469 |
protected static class SampleWellSetWeight {
|
| 488 | 470 |
|
| 489 |
- /** sum of fishes wieght for length class < +10Kg. */
|
|
| 471 |
+ /** sum of fishes weight for length class < +10Kg. */
|
|
| 490 | 472 |
Float totalWeight;
|
| 491 |
- /** sum of fishes wieght for length class < +10Kg. */
|
|
| 473 |
+ /** sum of fishes weight for length class < +10Kg. */
|
|
| 492 | 474 |
Float minus10Weight;
|
| 493 |
- /** sum of fishes wieght for length class > +10Kg. */
|
|
| 475 |
+ /** sum of fishes weight for length class > +10Kg. */
|
|
| 494 | 476 |
Float plus10Weight;
|
| 495 | 477 |
|
| 496 | 478 |
protected static SampleWellSetWeight create(Float totalWeight, Float minus10Weight, Float plus10Weight) {
|
| ... | ... | @@ -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%
|
| ... | ... | @@ -37,6 +37,8 @@ import fr.ird.t3.models.WeightCompositionModel; |
| 37 | 37 |
import fr.ird.t3.models.WeightCompositionModelHelper;
|
| 38 | 38 |
import fr.ird.t3.services.DecoratorService;
|
| 39 | 39 |
import fr.ird.t3.services.T3ServiceContext;
|
| 40 |
+import org.apache.commons.logging.Log;
|
|
| 41 |
+import org.apache.commons.logging.LogFactory;
|
|
| 40 | 42 |
|
| 41 | 43 |
import java.io.IOException;
|
| 42 | 44 |
import java.util.Collection;
|
| ... | ... | @@ -55,6 +57,7 @@ import static org.nuiton.i18n.I18n.l; |
| 55 | 57 |
*/
|
| 56 | 58 |
public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Action> {
|
| 57 | 59 |
|
| 60 |
+ private static final Log log = LogFactory.getLog(L2CatchStratum.class);
|
|
| 58 | 61 |
/**
|
| 59 | 62 |
* All species used by all weight categories found in all catches
|
| 60 | 63 |
* for this stratum.
|
| ... | ... | @@ -100,13 +103,38 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti |
| 100 | 103 |
*/
|
| 101 | 104 |
private WeightCompositionAggregateModel inputModelForSpeciesToFix;
|
| 102 | 105 |
|
| 103 |
- L2CatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, Collection<Species> speciesToFix) {
|
|
| 106 |
+ private L2CatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, Collection<Species> speciesToFix) {
|
|
| 104 | 107 |
super(stratumConfiguration, speciesToFix);
|
| 105 | 108 |
weightCategoriesForSpecies = HashMultimap.create();
|
| 106 | 109 |
inputModelForAllSpecies = new WeightCompositionAggregateModel();
|
| 107 | 110 |
outputModelForAllSpecies = new WeightCompositionAggregateModel();
|
| 108 | 111 |
}
|
| 109 | 112 |
|
| 113 |
+ static L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
|
|
| 114 |
+ List<WeightCategoryTreatment> weightCategories,
|
|
| 115 |
+ Collection<Species> species,
|
|
| 116 |
+ Level2Action action) throws Exception {
|
|
| 117 |
+ L2CatchStratum catchStratum = new L2CatchStratum(stratumConfiguration, species);
|
|
| 118 |
+ T3ServiceContext serviceContext = action.getServiceContext();
|
|
| 119 |
+ catchStratum.init(serviceContext, weightCategories, action);
|
|
| 120 |
+ // get the total weight of the catch stratum
|
|
| 121 |
+ float catchStratumWeight = catchStratum.getTotalCatchWeightForSpeciesToFix();
|
|
| 122 |
+ if (catchStratumWeight == 0) {
|
|
| 123 |
+ // no catch in this stratum, skip it
|
|
| 124 |
+ String message = l(serviceContext.getLocale(), "t3.level2.message.noCatch.in.stratum");
|
|
| 125 |
+ log.info(message);
|
|
| 126 |
+ action.addInfoMessage(message);
|
|
| 127 |
+ // let's nullify the catch stratum (make it no more available)
|
|
| 128 |
+ catchStratum = null;
|
|
| 129 |
+ } else {
|
|
| 130 |
+ // log it
|
|
| 131 |
+ String message = catchStratum.logCatchStratum(action.getDecoratorService());
|
|
| 132 |
+ log.info(message);
|
|
| 133 |
+ action.addInfoMessage(message);
|
|
| 134 |
+ }
|
|
| 135 |
+ return catchStratum;
|
|
| 136 |
+ }
|
|
| 137 |
+ |
|
| 110 | 138 |
@Override
|
| 111 | 139 |
public void close() throws IOException {
|
| 112 | 140 |
super.close();
|
| ... | ... | @@ -130,11 +158,13 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti |
| 130 | 158 |
Integer nbZones = e.getValue();
|
| 131 | 159 |
|
| 132 | 160 |
if (activity.isCorrectedElementaryCatchNotEmpty()) {
|
| 161 |
+ //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
|
|
| 133 | 162 |
for (CorrectedElementaryCatch aCatch : activity.getCorrectedElementaryCatch()) {
|
| 134 | 163 |
weightCategoriesForSpecies.put(aCatch.getWeightCategoryTreatment(), aCatch.getSpecies());
|
| 135 | 164 |
}
|
| 136 | 165 |
}
|
| 137 | 166 |
|
| 167 |
+ //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
|
|
| 138 | 168 |
Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatchesByCategory =
|
| 139 | 169 |
ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
|
| 140 | 170 |
|
| ... | ... | @@ -25,8 +25,10 @@ import fr.ird.t3.actions.stratum.CatchStratumLoader; |
| 25 | 25 |
import fr.ird.t3.actions.stratum.StratumConfiguration;
|
| 26 | 26 |
import fr.ird.t3.entities.data.Activity;
|
| 27 | 27 |
import fr.ird.t3.entities.data.ActivityTopiaDao;
|
| 28 |
+import fr.ird.t3.entities.data.CorrectedElementaryCatch;
|
|
| 28 | 29 |
import fr.ird.t3.entities.data.Trip;
|
| 29 | 30 |
import fr.ird.t3.entities.reference.Vessel;
|
| 31 |
+import fr.ird.t3.entities.reference.WeightCategoryTreatment;
|
|
| 30 | 32 |
import fr.ird.t3.services.ioc.InjectDAO;
|
| 31 | 33 |
|
| 32 | 34 |
import java.util.HashMap;
|
| ... | ... | @@ -71,6 +73,7 @@ public class L2CatchStratumLoader extends CatchStratumLoader<Level2Configuration |
| 71 | 73 |
Map<Activity, Integer> result = new HashMap<>();
|
| 72 | 74 |
if (activityIds != null && activityIds.size() > 0) {
|
| 73 | 75 |
Set<Vessel> possibleVessels = configuration.getPossibleCatchVessels();
|
| 76 |
+ WeightCategoryTreatment weightCategoryTreatment = configuration.getWeightCategoryTreatment();
|
|
| 74 | 77 |
for (Map.Entry<String, Integer> e : activityIds.entrySet()) {
|
| 75 | 78 |
String activityId = e.getKey();
|
| 76 | 79 |
// get activity
|
| ... | ... | @@ -84,6 +87,14 @@ public class L2CatchStratumLoader extends CatchStratumLoader<Level2Configuration |
| 84 | 87 |
// recheck activity have some catches.
|
| 85 | 88 |
Preconditions.checkState(activity.isCorrectedElementaryCatchNotEmpty(),
|
| 86 | 89 |
String.format("Can not accept an activity (%s) with no catch", activity.getTopiaId()));
|
| 90 |
+ if (weightCategoryTreatment != null) {
|
|
| 91 |
+ // weight category is in stratum, check there is catch using this category
|
|
| 92 |
+ boolean foundWeightCategory = activity.getCorrectedElementaryCatch().stream().map(CorrectedElementaryCatch::getWeightCategoryTreatment).anyMatch(c -> c.equals(weightCategoryTreatment));
|
|
| 93 |
+ if (!foundWeightCategory) {
|
|
| 94 |
+ // reject - the stratum weight category not found for this activity
|
|
| 95 |
+ continue;
|
|
| 96 |
+ }
|
|
| 97 |
+ }
|
|
| 87 | 98 |
result.put(activity, e.getValue());
|
| 88 | 99 |
}
|
| 89 | 100 |
}
|
| ... | ... | @@ -26,11 +26,12 @@ import fr.ird.t3.entities.data.Activity; |
| 26 | 26 |
import fr.ird.t3.entities.data.ActivityTopiaDao;
|
| 27 | 27 |
import fr.ird.t3.entities.data.SetSpeciesFrequency;
|
| 28 | 28 |
import fr.ird.t3.entities.reference.Species;
|
| 29 |
+import fr.ird.t3.entities.reference.WeightCategory;
|
|
| 29 | 30 |
import fr.ird.t3.entities.reference.WeightCategorySample;
|
| 31 |
+import fr.ird.t3.entities.reference.WeightCategoryTreatment;
|
|
| 30 | 32 |
import fr.ird.t3.models.WeightCompositionAggregateModel;
|
| 31 | 33 |
import fr.ird.t3.models.WeightCompositionModelHelper;
|
| 32 | 34 |
import fr.ird.t3.services.T3ServiceContext;
|
| 33 |
-import org.apache.commons.collections.CollectionUtils;
|
|
| 34 | 35 |
import org.apache.commons.logging.Log;
|
| 35 | 36 |
import org.apache.commons.logging.LogFactory;
|
| 36 | 37 |
import org.nuiton.topia.persistence.TopiaException;
|
| ... | ... | @@ -38,6 +39,7 @@ import org.nuiton.topia.persistence.TopiaException; |
| 38 | 39 |
import java.io.IOException;
|
| 39 | 40 |
import java.util.Collection;
|
| 40 | 41 |
import java.util.HashMap;
|
| 42 |
+import java.util.List;
|
|
| 41 | 43 |
import java.util.Locale;
|
| 42 | 44 |
import java.util.Map;
|
| 43 | 45 |
import java.util.Set;
|
| ... | ... | @@ -81,12 +83,22 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac |
| 81 | 83 |
*/
|
| 82 | 84 |
private float sampleStratumTotalWeight;
|
| 83 | 85 |
|
| 84 |
- L2SampleStratum(StratumConfiguration<Level2Configuration> configuration, Collection<Species> speciesToFix, float catchStratumTotalWeight) {
|
|
| 86 |
+ private L2SampleStratum(StratumConfiguration<Level2Configuration> configuration, Collection<Species> speciesToFix, float catchStratumTotalWeight) {
|
|
| 85 | 87 |
super(configuration, speciesToFix);
|
| 86 | 88 |
this.catchStratumTotalWeight = catchStratumTotalWeight;
|
| 87 | 89 |
modelsForAllSpecies = new WeightCompositionAggregateModel();
|
| 88 | 90 |
}
|
| 89 | 91 |
|
| 92 |
+ static L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
|
|
| 93 |
+ List<WeightCategoryTreatment> weightCategories,
|
|
| 94 |
+ float totalCatchWeight,
|
|
| 95 |
+ Collection<Species> species,
|
|
| 96 |
+ Level2Action action) throws Exception {
|
|
| 97 |
+ L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, species, totalCatchWeight);
|
|
| 98 |
+ sampleStratum.init(action.getServiceContext(), weightCategories, action);
|
|
| 99 |
+ return sampleStratum;
|
|
| 100 |
+ }
|
|
| 101 |
+ |
|
| 90 | 102 |
@Override
|
| 91 | 103 |
public void close() throws IOException {
|
| 92 | 104 |
super.close();
|
| ... | ... | @@ -97,18 +109,14 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac |
| 97 | 109 |
@Override
|
| 98 | 110 |
protected L2SampleStratumLoader newLoader() {
|
| 99 | 111 |
int oceanCode = getConfiguration().getZone().getOcean().getCode();
|
| 100 |
- L2SampleStratumLoader result;
|
|
| 101 | 112 |
switch (oceanCode) {
|
| 102 | 113 |
case 1:
|
| 103 |
- result = new L2SampleStratumLoaderAtlantic(this);
|
|
| 104 |
- break;
|
|
| 114 |
+ return new L2SampleStratumLoaderAtlantic(this);
|
|
| 105 | 115 |
case 2:
|
| 106 |
- result = new L2SampleStratumLoaderIndian(this);
|
|
| 107 |
- break;
|
|
| 116 |
+ return new L2SampleStratumLoaderIndian(this);
|
|
| 108 | 117 |
default:
|
| 109 | 118 |
throw new IllegalStateException("Not implemented for ocean with code " + oceanCode);
|
| 110 | 119 |
}
|
| 111 |
- return result;
|
|
| 112 | 120 |
}
|
| 113 | 121 |
|
| 114 | 122 |
public WeightCompositionAggregateModel getModelsForSpeciesToFix() {
|
| ... | ... | @@ -137,7 +145,7 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac |
| 137 | 145 |
ActivityTopiaDao.fillWeightsFromSetSpeciesCatWeight(activity, weights, null);
|
| 138 | 146 |
// obtain the set species frequencies for the current activity
|
| 139 | 147 |
Collection<SetSpeciesFrequency> setSpeciesFrequencies = activity.getSetSpeciesFrequency();
|
| 140 |
- if (CollectionUtils.isNotEmpty(setSpeciesFrequencies)) {
|
|
| 148 |
+ if (activity.isSetSpeciesFrequencyNotEmpty()) {
|
|
| 141 | 149 |
// compute sample count for this activity
|
| 142 | 150 |
int newCount = computeSampleCount(setSpeciesFrequencies, species);
|
| 143 | 151 |
// merge it with final total count
|
| ... | ... | @@ -145,24 +153,25 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac |
| 145 | 153 |
}
|
| 146 | 154 |
}
|
| 147 | 155 |
// add all weights to model
|
| 148 |
- for (WeightCategorySample weightCategoryTreatment : weights.keySet()) {
|
|
| 149 |
- Map<Species, Float> speciesFloatMap = weights.get(weightCategoryTreatment);
|
|
| 150 |
- modelsForAllSpecies.addModel(weightCategoryTreatment, speciesFloatMap);
|
|
| 156 |
+ for (Map.Entry<WeightCategorySample, Map<Species, Float>> e : weights.entrySet()) {
|
|
| 157 |
+ Map<Species, Float> speciesFloatMap = e.getValue();
|
|
| 158 |
+ WeightCategory weightCategorySample = e.getKey();
|
|
| 159 |
+ modelsForAllSpecies.addModel(weightCategorySample, speciesFloatMap);
|
|
| 151 | 160 |
}
|
| 152 | 161 |
// recompute the weight model for species to fix
|
| 153 | 162 |
modelsForSpeciesToFix = modelsForAllSpecies.extractForSpecies(species);
|
| 154 | 163 |
// recompute the total sample weight (for species to fix)
|
| 155 | 164 |
sampleStratumTotalWeight = modelsForSpeciesToFix.getTotalModel().getTotalWeight();
|
| 156 |
- addMergedActivitesCount(activities.size());
|
|
| 165 |
+ addMergedActivitiesCount(activities.size());
|
|
| 157 | 166 |
log.info(String.format("sampleStratumTotalCount = %d / sampleStratumTotalWeight = %f", getSampleStratumTotalCount(), getSampleStratumTotalWeight()));
|
| 158 | 167 |
}
|
| 159 | 168 |
|
| 160 |
- private int computeSampleCount(Collection<SetSpeciesFrequency> newDatas, Collection<Species> speciesToFix) {
|
|
| 169 |
+ private int computeSampleCount(Collection<SetSpeciesFrequency> setSpeciesFrequencies, Collection<Species> speciesToFix) {
|
|
| 161 | 170 |
int newCount = 0;
|
| 162 |
- for (SetSpeciesFrequency newData : newDatas) {
|
|
| 163 |
- Species species = newData.getSpecies();
|
|
| 171 |
+ for (SetSpeciesFrequency setSpeciesFrequency : setSpeciesFrequencies) {
|
|
| 172 |
+ Species species = setSpeciesFrequency.getSpecies();
|
|
| 164 | 173 |
if (speciesToFix.contains(species)) {
|
| 165 |
- newCount += newData.getNumber();
|
|
| 174 |
+ newCount += setSpeciesFrequency.getNumber();
|
|
| 166 | 175 |
}
|
| 167 | 176 |
}
|
| 168 | 177 |
return newCount;
|
| ... | ... | @@ -51,6 +51,7 @@ import fr.ird.t3.models.WeightCompositionAggregateModel; |
| 51 | 51 |
import fr.ird.t3.models.WeightCompositionModel;
|
| 52 | 52 |
import fr.ird.t3.models.WeightCompositionModelHelper;
|
| 53 | 53 |
import fr.ird.t3.services.DecoratorService;
|
| 54 |
+import fr.ird.t3.services.T3ServiceContext;
|
|
| 54 | 55 |
import fr.ird.t3.services.ZoneStratumService;
|
| 55 | 56 |
import fr.ird.t3.services.ioc.InjectDAO;
|
| 56 | 57 |
import fr.ird.t3.services.ioc.InjectEntitiesById;
|
| ... | ... | @@ -113,7 +114,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 113 | 114 |
*
|
| 114 | 115 |
* @since 1.3
|
| 115 | 116 |
*/
|
| 116 |
- private Collection<L2StratumResult> stratumsResult;
|
|
| 117 |
+ private Collection<L2StratumResult> stratumResultSet;
|
|
| 117 | 118 |
@InjectDAO(entityType = Activity.class)
|
| 118 | 119 |
private ActivityTopiaDao activityDAO;
|
| 119 | 120 |
@InjectDAO(entityType = WeightCategoryTreatment.class)
|
| ... | ... | @@ -179,7 +180,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 179 | 180 |
this.possibleCatchVessels = vesselDAO.getPossibleCatchVessels(catchFleets);
|
| 180 | 181 |
// get possible vessels for sample stratum
|
| 181 | 182 |
this.possibleSampleVessels = vesselDAO.getPossibleSampleVessels(sampleFleets, sampleFlags);
|
| 182 |
- this.stratumsResult = new LinkedHashSet<>();
|
|
| 183 |
+ this.stratumResultSet = new LinkedHashSet<>();
|
|
| 183 | 184 |
this.inputCatchModelForAllSpecies = new WeightCompositionAggregateModel();
|
| 184 | 185 |
this.outputCatchModelForAllSpecies = new WeightCompositionAggregateModel();
|
| 185 | 186 |
}
|
| ... | ... | @@ -278,7 +279,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 278 | 279 |
activityCache);
|
| 279 | 280 |
try {
|
| 280 | 281 |
L2StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds);
|
| 281 |
- stratumsResult.add(result);
|
|
| 282 |
+ stratumResultSet.add(result);
|
|
| 282 | 283 |
} finally {
|
| 283 | 284 |
flushTransaction("After stratum " + stratumIndex);
|
| 284 | 285 |
}
|
| ... | ... | @@ -319,7 +320,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 319 | 320 |
addInfoMessage(message);
|
| 320 | 321 |
addInfoMessage("==============================================================================================");
|
| 321 | 322 |
// compute the catch stratum
|
| 322 |
- try (L2CatchStratum catchStratum = newCatchStratum(stratumConfiguration, weightCategories)) {
|
|
| 323 |
+ try (L2CatchStratum catchStratum = L2CatchStratum.newCatchStratum(stratumConfiguration, weightCategories, species, this)) {
|
|
| 323 | 324 |
incrementsProgression();
|
| 324 | 325 |
if (catchStratum == null) {
|
| 325 | 326 |
// no catch in this stratum
|
| ... | ... | @@ -328,7 +329,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 328 | 329 |
incrementsProgression();
|
| 329 | 330 |
} else {
|
| 330 | 331 |
// compute sample stratum
|
| 331 |
- try (L2SampleStratum sampleStratum = newSampleStratum(stratumConfiguration, weightCategories, catchStratum.getTotalCatchWeightForSpeciesToFix())) {
|
|
| 332 |
+ try (L2SampleStratum sampleStratum = L2SampleStratum.newSampleStratum(stratumConfiguration, weightCategories, catchStratum.getTotalCatchWeightForSpeciesToFix(), species, this)) {
|
|
| 332 | 333 |
incrementsProgression();
|
| 333 | 334 |
// get the substitution level for the sample stratum
|
| 334 | 335 |
Integer level = sampleStratum.getSubstitutionLevel();
|
| ... | ... | @@ -349,7 +350,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 349 | 350 |
// int nbZones = e.getValue();
|
| 350 | 351 |
// is activity was already treated ?
|
| 351 | 352 |
boolean newActivity = usedActivityIds.add(activity.getTopiaId());
|
| 352 |
- doExecuteActivityInCatchStratum(catchStratum,
|
|
| 353 |
+ doExecuteActivityInCatchStratumWithoutSampleStratum(catchStratum,
|
|
| 353 | 354 |
activity,
|
| 354 | 355 |
activityIndex++,
|
| 355 | 356 |
nbActivities,
|
| ... | ... | @@ -409,34 +410,73 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 409 | 410 |
return oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList());
|
| 410 | 411 |
}
|
| 411 | 412 |
|
| 412 |
- private L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
|
|
| 413 |
- List<WeightCategoryTreatment> weightCategories) throws Exception {
|
|
| 414 |
- L2CatchStratum catchStratum = new L2CatchStratum(stratumConfiguration, species);
|
|
| 415 |
- catchStratum.init(serviceContext, weightCategories, this);
|
|
| 416 |
- // get the total weight of the catch stratum
|
|
| 417 |
- float catchStratumWeight = catchStratum.getTotalCatchWeightForSpeciesToFix();
|
|
| 418 |
- if (catchStratumWeight == 0) {
|
|
| 419 |
- // no catch in this stratum, skip it
|
|
| 420 |
- String message = l(locale, "t3.level2.message.noCatch.in.stratum");
|
|
| 421 |
- log.info(message);
|
|
| 422 |
- addInfoMessage(message);
|
|
| 423 |
- // let's nullify the catch stratum (make it no more available)
|
|
| 424 |
- catchStratum = null;
|
|
| 425 |
- } else {
|
|
| 426 |
- // log it
|
|
| 427 |
- String message = catchStratum.logCatchStratum(getDecoratorService());
|
|
| 428 |
- log.info(message);
|
|
| 429 |
- addInfoMessage(message);
|
|
| 413 |
+ private void doExecuteActivityInCatchStratumWithoutSampleStratum(L2CatchStratum catchStratum,
|
|
| 414 |
+ Activity activity,
|
|
| 415 |
+ int activityIndex,
|
|
| 416 |
+ int nbActivities,
|
|
| 417 |
+ boolean deleteOldData) {
|
|
| 418 |
+ |
|
| 419 |
+ String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID));
|
|
| 420 |
+ String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivities, activityStr, 1);
|
|
| 421 |
+ log.info(message);
|
|
| 422 |
+ addInfoMessage(message);
|
|
| 423 |
+ if (deleteOldData) {
|
|
| 424 |
+ // delete old data for this activity
|
|
| 425 |
+ log.info(String.format("Delete previous level2 data of %s", activityStr));
|
|
| 426 |
+ activity.deleteComputedDataLevel2();
|
|
| 427 |
+ }
|
|
| 428 |
+ // build a model for getting total of each weight category
|
|
| 429 |
+ try (WeightCompositionAggregateModel catchWeightModelForAllSpecies = new WeightCompositionAggregateModel()) {
|
|
| 430 |
+ //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
|
|
| 431 |
+ ActivityTopiaDao.fillWeightsFromCatchesWeight(activity, catchWeightModelForAllSpecies, 1);
|
|
| 432 |
+ try (WeightCompositionAggregateModel catchWeightModelForSpeciesToFix = catchWeightModelForAllSpecies.extractForSpecies(species)) {
|
|
| 433 |
+ // log catches weight
|
|
| 434 |
+ message = logCatchWeight(getDecoratorService(), catchWeightModelForAllSpecies, catchWeightModelForSpeciesToFix);
|
|
| 435 |
+ log.info(message);
|
|
| 436 |
+ addInfoMessage(message);
|
|
| 437 |
+ }
|
|
| 438 |
+ try (WeightCompositionAggregateModel model = new WeightCompositionAggregateModel()) {
|
|
| 439 |
+ ActivityTopiaDao.fillWeightsFromSetSpeciesCatWeight(activity, null, model);
|
|
| 440 |
+ try (WeightCompositionAggregateModel compositionModel = model.extractForSpecies(species)) {
|
|
| 441 |
+ String activityResume = logActivityCatchStratum(model, compositionModel, getDecoratorService());
|
|
| 442 |
+ message = l(locale, "t3.level2.message.activity.with.sample.useOwn.composition", activityResume);
|
|
| 443 |
+ log.info(message);
|
|
| 444 |
+ addInfoMessage(message);
|
|
| 445 |
+ }
|
|
| 446 |
+ }
|
|
| 447 |
+ // apply composition model to activity catches
|
|
| 448 |
+ applySampleSpecificCompositionWithoutSampleStratum(catchStratum, activity);
|
|
| 430 | 449 |
}
|
| 431 |
- return catchStratum;
|
|
| 432 | 450 |
}
|
| 433 | 451 |
|
| 434 |
- private L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
|
|
| 435 |
- List<WeightCategoryTreatment> weightCategories,
|
|
| 436 |
- float totalCatchWeight) throws Exception {
|
|
| 437 |
- L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, species, totalCatchWeight);
|
|
| 438 |
- sampleStratum.init(serviceContext, weightCategories, this);
|
|
| 439 |
- return sampleStratum;
|
|
| 452 |
+ private void applySampleSpecificCompositionWithoutSampleStratum(L2CatchStratum catchStratum, Activity activity) {
|
|
| 453 |
+ try (WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel()) {
|
|
| 454 |
+ // Get all corrected catch group by weight category
|
|
| 455 |
+ Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatches =
|
|
| 456 |
+ ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
|
|
| 457 |
+ //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
|
|
| 458 |
+ for (WeightCategoryTreatment weightCategory : correctedElementaryCatches.keySet()) {
|
|
| 459 |
+ Map<Species, Float> weights = new HashMap<>();
|
|
| 460 |
+ // Apply on all existing corrected catch weight
|
|
| 461 |
+ for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
|
|
| 462 |
+ Species speciesToUse = aCatch.getSpecies();
|
|
| 463 |
+ // the corrected catch weight to add to the row
|
|
| 464 |
+ float correctedCatchWeight = aCatch.getCatchWeight();
|
|
| 465 |
+ // hold added value (for logs)
|
|
| 466 |
+ weights.put(speciesToUse, correctedCatchWeight);
|
|
| 467 |
+ aCatch.setCorrectedCatchWeight(correctedCatchWeight);
|
|
| 468 |
+ aCatch.setCorrectedFlag(false);
|
|
| 469 |
+ }
|
|
| 470 |
+ // add corrected weights used for this category
|
|
| 471 |
+ correctedCatchWeightModel.addModel(weightCategory, weights);
|
|
| 472 |
+ }
|
|
| 473 |
+ // log corrected catches weight
|
|
| 474 |
+ String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
|
|
| 475 |
+ log.info(message);
|
|
| 476 |
+ addInfoMessage(message);
|
|
| 477 |
+ // add corrected catch weight done for this activity in stratum output model
|
|
| 478 |
+ catchStratum.addActivityOutputModel(correctedCatchWeightModel);
|
|
| 479 |
+ }
|
|
| 440 | 480 |
}
|
| 441 | 481 |
|
| 442 | 482 |
private void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum,
|
| ... | ... | @@ -457,14 +497,14 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 457 | 497 |
}
|
| 458 | 498 |
// build a model for getting total of each weight category
|
| 459 | 499 |
WeightCompositionAggregateModel catchWeightModelForAllSpecies = new WeightCompositionAggregateModel();
|
| 500 |
+ //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
|
|
| 460 | 501 |
ActivityTopiaDao.fillWeightsFromCatchesWeight(activity, catchWeightModelForAllSpecies, nbZones);
|
| 461 | 502 |
WeightCompositionAggregateModel catchWeightModelForSpeciesToFix = catchWeightModelForAllSpecies.extractForSpecies(species);
|
| 462 | 503 |
// log catches weight
|
| 463 | 504 |
message = logCatchWeight(getDecoratorService(), catchWeightModelForAllSpecies, catchWeightModelForSpeciesToFix);
|
| 464 | 505 |
log.info(message);
|
| 465 | 506 |
addInfoMessage(message);
|
| 466 |
- // obtain the sample composition model to use for the activity (can come from catch if it has some samples,
|
|
| 467 |
- // otherwise use the catch stratum one)
|
|
| 507 |
+ // obtain the sample composition model to use for the activity (can come from catch if it has some samples, otherwise use the catch stratum one)
|
|
| 468 | 508 |
boolean activityWithSample = catchStratum.isActivityWithSample(activity);
|
| 469 | 509 |
boolean useAllSamplesOfStratum = getConfiguration().isUseAllSamplesOfStratum();
|
| 470 | 510 |
WeightCompositionAggregateModel compositionModel;
|
| ... | ... | @@ -498,161 +538,98 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 498 | 538 |
}
|
| 499 | 539 |
}
|
| 500 | 540 |
|
| 501 |
- private void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum,
|
|
| 502 |
- Activity activity,
|
|
| 503 |
- int activityIndex,
|
|
| 504 |
- int nbActivities,
|
|
| 505 |
- boolean deleteOldData) {
|
|
| 506 |
- |
|
| 507 |
- String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID));
|
|
| 508 |
- String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivities, activityStr, 1);
|
|
| 509 |
- log.info(message);
|
|
| 510 |
- addInfoMessage(message);
|
|
| 511 |
- if (deleteOldData) {
|
|
| 512 |
- // delete old data for this activity
|
|
| 513 |
- log.info(String.format("Delete previous level2 data of %s", activityStr));
|
|
| 514 |
- activity.deleteComputedDataLevel2();
|
|
| 515 |
- }
|
|
| 516 |
- // build a model for getting total of each weight category
|
|
| 517 |
- WeightCompositionAggregateModel catchWeightModelForAllSpecies = new WeightCompositionAggregateModel();
|
|
| 518 |
- ActivityTopiaDao.fillWeightsFromCatchesWeight(activity, catchWeightModelForAllSpecies, 1);
|
|
| 519 |
- WeightCompositionAggregateModel catchWeightModelForSpeciesToFix = catchWeightModelForAllSpecies.extractForSpecies(species);
|
|
| 520 |
- // log catches weight
|
|
| 521 |
- message = logCatchWeight(getDecoratorService(), catchWeightModelForAllSpecies, catchWeightModelForSpeciesToFix);
|
|
| 522 |
- log.info(message);
|
|
| 523 |
- addInfoMessage(message);
|
|
| 524 |
- WeightCompositionAggregateModel model = new WeightCompositionAggregateModel();
|
|
| 525 |
- ActivityTopiaDao.fillWeightsFromSetSpeciesCatWeight(activity, null, model);
|
|
| 526 |
- WeightCompositionAggregateModel compositionModel = model.extractForSpecies(species);
|
|
| 527 |
- String activityResume = logActivityCatchStratum(model, compositionModel, getDecoratorService());
|
|
| 528 |
- message = l(locale, "t3.level2.message.activity.with.sample.useOwn.composition", activityResume);
|
|
| 529 |
- log.info(message);
|
|
| 530 |
- addInfoMessage(message);
|
|
| 531 |
- // apply composition model to activity catches
|
|
| 532 |
- applySampleSpecificComposition(catchStratum, activity);
|
|
| 533 |
- catchWeightModelForAllSpecies.close();
|
|
| 534 |
- catchWeightModelForSpeciesToFix.close();
|
|
| 535 |
- compositionModel.close();
|
|
| 536 |
- }
|
|
| 537 |
- |
|
| 538 |
- private void applySampleSpecificComposition(L2CatchStratum catchStratum, Activity activity) {
|
|
| 539 |
- WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel();
|
|
| 540 |
- // Get all corrected catch group by weight category
|
|
| 541 |
- Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatches =
|
|
| 542 |
- ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
|
|
| 543 |
- for (WeightCategoryTreatment weightCategory : correctedElementaryCatches.keySet()) {
|
|
| 544 |
- Map<Species, Float> weights = new HashMap<>();
|
|
| 545 |
- // Apply on all existing corrected catch weight
|
|
| 546 |
- for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
|
|
| 547 |
- Species speciesToUse = aCatch.getSpecies();
|
|
| 548 |
- // the corrected catch weight to add to the row
|
|
| 549 |
- float correctedCatchWeight = aCatch.getCatchWeight();
|
|
| 550 |
- // hold added value (for logs)
|
|
| 551 |
- weights.put(speciesToUse, correctedCatchWeight);
|
|
| 552 |
- aCatch.setCorrectedCatchWeight(correctedCatchWeight);
|
|
| 553 |
- aCatch.setCorrectedFlag(false);
|
|
| 554 |
- }
|
|
| 555 |
- // add corrected weights used for this category
|
|
| 556 |
- correctedCatchWeightModel.addModel(weightCategory, weights);
|
|
| 557 |
- }
|
|
| 558 |
- // log corrected catches weight
|
|
| 559 |
- String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
|
|
| 560 |
- log.info(message);
|
|
| 561 |
- addInfoMessage(message);
|
|
| 562 |
- // add corrected catch weight done for this activity in stratum output model
|
|
| 563 |
- catchStratum.addActivityOutputModel(correctedCatchWeightModel);
|
|
| 564 |
- }
|
|
| 565 |
- |
|
| 566 | 541 |
private void applySampleSpecificComposition(L2CatchStratum catchStratum,
|
| 567 | 542 |
Activity activity,
|
| 568 | 543 |
int nbZones,
|
| 569 | 544 |
WeightCompositionAggregateModel sampleCompositionModel,
|
| 570 | 545 |
WeightCompositionAggregateModel correctedCatchesForSpeciesToFix) {
|
| 571 |
- WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel();
|
|
| 572 |
- // Get all corrected catch group by weight category
|
|
| 573 |
- Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatches =
|
|
| 574 |
- ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
|
|
| 575 |
- for (WeightCategoryTreatment weightCategory : correctedElementaryCatches.keySet()) {
|
|
| 576 |
- Map<Species, Float> weights = new HashMap<>();
|
|
| 577 |
- // get composition model to use
|
|
| 578 |
- WeightCompositionModel model = sampleCompositionModel.getModel(weightCategory);
|
|
| 579 |
- // set of species still to fix
|
|
| 580 |
- Set<Species> speciesToFix;
|
|
| 581 |
- // set of species still to fix
|
|
| 582 |
- Set<Species> speciesStillToFix;
|
|
| 583 |
- // get total weight for species to fix from correctedCatches
|
|
| 584 |
- float totalWeight;
|
|
| 585 |
- if (model == null) {
|
|
| 586 |
- // this means there is no specific composition for this weight category to apply for species to fix
|
|
| 587 |
- // says there is no species to fix (so all catches will be copied to correctedCatchWeight (with no fixedFlag)
|
|
| 588 |
- speciesToFix = speciesStillToFix = Collections.emptySet();
|
|
| 589 |
- totalWeight = 0f;
|
|
| 590 |
- } else {
|
|
| 591 |
- // found a specific composition to apply for this weight category
|
|
| 592 |
- speciesToFix = model.getSpecies();
|
|
| 593 |
- speciesStillToFix = new HashSet<>(speciesToFix);
|
|
| 594 |
- totalWeight = correctedCatchesForSpeciesToFix.getModel(weightCategory).getTotalWeight();
|
|
| 595 |
- }
|
|
| 596 |
- // divide the total weight to used by the number of zones of this activity
|
|
| 597 |
- totalWeight = totalWeight / nbZones;
|
|
| 598 |
- // Apply on all existing corrected catch weight
|
|
| 599 |
- for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
|
|
| 600 |
- Species speciesToUse = Objects.requireNonNull(aCatch.getSpecies());
|
|
| 601 |
- // flag (was fixed or not)
|
|
| 602 |
- boolean toFix;
|
|
| 603 |
- // the corrected catch weight to add to the row
|
|
| 604 |
- float correctedCatchWeight;
|
|
| 605 |
- if (model != null && speciesToFix.contains(speciesToUse)) {
|
|
| 606 |
- // species to fix
|
|
| 607 |
- toFix = true;
|
|
| 608 |
- float weightRate = model.getWeightRate(speciesToUse);
|
|
| 609 |
- // new corrected catch weight
|
|
| 610 |
- correctedCatchWeight = totalWeight * weightRate;
|
|
| 611 |
- // species no more to treat
|
|
| 612 |
- speciesStillToFix.remove(speciesToUse);
|
|
| 546 |
+ try (WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel()) {
|
|
| 547 |
+ //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
|
|
| 548 |
+ // Get all corrected catch group by weight category
|
|
| 549 |
+ Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatches =
|
|
| 550 |
+ ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
|
|
| 551 |
+ for (WeightCategoryTreatment weightCategory : correctedElementaryCatches.keySet()) {
|
|
| 552 |
+ Map<Species, Float> weights = new HashMap<>();
|
|
| 553 |
+ // get composition model to use
|
|
| 554 |
+ WeightCompositionModel model = sampleCompositionModel.getModel(weightCategory);
|
|
| 555 |
+ // set of species still to fix
|
|
| 556 |
+ Set<Species> speciesToFix;
|
|
| 557 |
+ // set of species still to fix
|
|
| 558 |
+ Set<Species> speciesStillToFix;
|
|
| 559 |
+ // get total weight for species to fix from correctedCatches
|
|
| 560 |
+ float totalWeight;
|
|
| 561 |
+ if (model == null) {
|
|
| 562 |
+ // this means there is no specific composition for this weight category to apply for species to fix
|
|
| 563 |
+ // says there is no species to fix (so all catches will be copied to correctedCatchWeight (with no fixedFlag)
|
|
| 564 |
+ speciesToFix = speciesStillToFix = Collections.emptySet();
|
|
| 565 |
+ totalWeight = 0f;
|
|
| 613 | 566 |
} else {
|
| 614 |
- // nothing to fix, just propagate old value
|
|
| 615 |
- toFix = false;
|
|
| 616 |
- correctedCatchWeight = aCatch.getCatchWeight();
|
|
| 567 |
+ // found a specific composition to apply for this weight category
|
|
| 568 |
+ speciesToFix = model.getSpecies();
|
|
| 569 |
+ speciesStillToFix = new HashSet<>(speciesToFix);
|
|
| 570 |
+ totalWeight = correctedCatchesForSpeciesToFix.getModel(weightCategory).getTotalWeight();
|
|
| 571 |
+ }
|
|
| 572 |
+ // divide the total weight to used by the number of zones of this activity
|
|
| 573 |
+ totalWeight = totalWeight / nbZones;
|
|
| 574 |
+ // Apply on all existing corrected catch weight
|
|
| 575 |
+ for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
|
|
| 576 |
+ Species speciesToUse = Objects.requireNonNull(aCatch.getSpecies());
|
|
| 577 |
+ // flag (was fixed or not)
|
|
| 578 |
+ boolean toFix;
|
|
| 579 |
+ // the corrected catch weight to add to the row
|
|
| 580 |
+ float correctedCatchWeight;
|
|
| 581 |
+ if (model != null && speciesToFix.contains(speciesToUse)) {
|
|
| 582 |
+ // species to fix
|
|
| 583 |
+ toFix = true;
|
|
| 584 |
+ float weightRate = model.getWeightRate(speciesToUse);
|
|
| 585 |
+ // new corrected catch weight
|
|
| 586 |
+ correctedCatchWeight = totalWeight * weightRate;
|
|
| 587 |
+ // species no more to treat
|
|
| 588 |
+ speciesStillToFix.remove(speciesToUse);
|
|
| 589 |
+ } else {
|
|
| 590 |
+ // nothing to fix, just propagate old value
|
|
| 591 |
+ toFix = false;
|
|
| 592 |
+ correctedCatchWeight = aCatch.getCatchWeight();
|
|
| 593 |
+ }
|
|
| 594 |
+ // hold added value (for logs)
|
|
| 595 |
+ weights.put(speciesToUse, correctedCatchWeight);
|
|
| 596 |
+ // Add to old value (if any)
|
|
| 597 |
+ Float oldCorrectedCatchWeight = aCatch.getCorrectedCatchWeight();
|
|
| 598 |
+ if (oldCorrectedCatchWeight == null) {
|
|
| 599 |
+ oldCorrectedCatchWeight = 0f;
|
|
| 600 |
+ }
|
|
| 601 |
+ aCatch.setCorrectedCatchWeight(oldCorrectedCatchWeight + correctedCatchWeight);
|
|
| 602 |
+ aCatch.setCorrectedFlag(toFix);
|
|
| 617 | 603 |
}
|
| 618 |
- // hold added value (for logs)
|
|
| 619 |
- weights.put(speciesToUse, correctedCatchWeight);
|
|
| 620 |
- // Add to old value (if any)
|
|
| 621 |
- Float oldCorrectedCatchWeight = aCatch.getCorrectedCatchWeight();
|
|
| 622 |
- if (oldCorrectedCatchWeight == null) {
|
|
| 623 |
- oldCorrectedCatchWeight = 0f;
|
|
| 604 |
+ // Creates new corrected catch weight records for all species still to fix
|
|
| 605 |
+ // Means they are in samples but not in catches
|
|
| 606 |
+ for (Species speciesToUse : speciesStillToFix) {
|
|
| 607 |
+ // weight rate of the species
|
|
| 608 |
+ float weightRate = model == null ? 1f : model.getWeightRate(speciesToUse);
|
|
| 609 |
+ // corrected catch weight
|
|
| 610 |
+ float correctedCatchWeight = totalWeight * weightRate;
|
|
| 611 |
+ // create new record
|
|
| 612 |
+ CorrectedElementaryCatch aCatch = correctedElementaryCatchDAO.create();
|
|
| 613 |
+ aCatch.setSpecies(speciesToUse);
|
|
| 614 |
+ aCatch.setWeightCategoryTreatment(weightCategory);
|
|
| 615 |
+ aCatch.setCatchWeight(0f);
|
|
| 616 |
+ aCatch.setCorrectedFlag(true);
|
|
| 617 |
+ aCatch.setCorrectedCatchWeight(correctedCatchWeight);
|
|
| 618 |
+ // hold added value (for logs)
|
|
| 619 |
+ weights.put(speciesToUse, correctedCatchWeight);
|
|
| 620 |
+ // add it to activity
|
|
| 621 |
+ activity.addCorrectedElementaryCatch(aCatch);
|
|
| 624 | 622 |
}
|
| 625 |
- aCatch.setCorrectedCatchWeight(oldCorrectedCatchWeight + correctedCatchWeight);
|
|
| 626 |
- aCatch.setCorrectedFlag(toFix);
|
|
| 627 |
- }
|
|
| 628 |
- // Creates new corrected catch weight records for all species still to fix
|
|
| 629 |
- // Means they are in samples but not in catches
|
|
| 630 |
- for (Species speciesToUse : speciesStillToFix) {
|
|
| 631 |
- // weight rate of the species
|
|
| 632 |
- float weightRate = model == null ? 1f : model.getWeightRate(speciesToUse);
|
|
| 633 |
- // corrected catch weight
|
|
| 634 |
- float correctedCatchWeight = totalWeight * weightRate;
|
|
| 635 |
- // create new record
|
|
| 636 |
- CorrectedElementaryCatch aCatch = correctedElementaryCatchDAO.create();
|
|
| 637 |
- aCatch.setSpecies(speciesToUse);
|
|
| 638 |
- aCatch.setWeightCategoryTreatment(weightCategory);
|
|
| 639 |
- aCatch.setCatchWeight(0f);
|
|
| 640 |
- aCatch.setCorrectedFlag(true);
|
|
| 641 |
- aCatch.setCorrectedCatchWeight(correctedCatchWeight);
|
|
| 642 |
- // hold added value (for logs)
|
|
| 643 |
- weights.put(speciesToUse, correctedCatchWeight);
|
|
| 644 |
- // add it to activity
|
|
| 645 |
- activity.addCorrectedElementaryCatch(aCatch);
|
|
| 623 |
+ // add corrected weights used for this category
|
|
| 624 |
+ correctedCatchWeightModel.addModel(weightCategory, weights);
|
|
| 646 | 625 |
}
|
| 647 |
- // add corrected weights used for this category
|
|
| 648 |
- correctedCatchWeightModel.addModel(weightCategory, weights);
|
|
| 626 |
+ // log corrected catches weight
|
|
| 627 |
+ String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
|
|
| 628 |
+ log.info(message);
|
|
| 629 |
+ addInfoMessage(message);
|
|
| 630 |
+ // add corrected catch weight done for this activity in stratum output model
|
|
| 631 |
+ catchStratum.addActivityOutputModel(correctedCatchWeightModel);
|
|
| 649 | 632 |
}
|
| 650 |
- // log corrected catches weight
|
|
| 651 |
- String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
|
|
| 652 |
- log.info(message);
|
|
| 653 |
- addInfoMessage(message);
|
|
| 654 |
- // add corrected catch weight done for this activity in stratum output model
|
|
| 655 |
- catchStratum.addActivityOutputModel(correctedCatchWeightModel);
|
|
| 656 | 633 |
}
|
| 657 | 634 |
|
| 658 | 635 |
// -------------------------------------------------------------------------
|
| ... | ... | @@ -681,13 +658,13 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 681 | 658 |
|
| 682 | 659 |
@SuppressWarnings("unused")
|
| 683 | 660 |
public int getNbStrataFixed() {
|
| 684 |
- return stratumsResult.size();
|
|
| 661 |
+ return stratumResultSet.size();
|
|
| 685 | 662 |
}
|
| 686 | 663 |
|
| 687 | 664 |
@SuppressWarnings({"unused", "WeakerAccess"})
|
| 688 | 665 |
public Integer[] getAllSubstitutionLevels() {
|
| 689 | 666 |
Set<Integer> levels = new HashSet<>();
|
| 690 |
- for (L2StratumResult stratumResult : stratumsResult) {
|
|
| 667 |
+ for (L2StratumResult stratumResult : stratumResultSet) {
|
|
| 691 | 668 |
levels.add(stratumResult.getSubstitutionLevel());
|
| 692 | 669 |
}
|
| 693 | 670 |
List<Integer> result = new ArrayList<>(levels);
|
| ... | ... | @@ -703,7 +680,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 703 | 680 |
@SuppressWarnings("unused")
|
| 704 | 681 |
public Collection<L2StratumResult> getStratumResult(int level) {
|
| 705 | 682 |
Set<L2StratumResult> singleResult = new LinkedHashSet<>();
|
| 706 |
- for (L2StratumResult stratumResult : stratumsResult) {
|
|
| 683 |
+ for (L2StratumResult stratumResult : stratumResultSet) {
|
|
| 707 | 684 |
if (level == stratumResult.getSubstitutionLevel()) {
|
| 708 | 685 |
singleResult.add(stratumResult);
|
| 709 | 686 |
}
|
| ... | ... | @@ -717,7 +694,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 717 | 694 |
Integer[] levels = getAllSubstitutionLevels();
|
| 718 | 695 |
for (Integer level : levels) {
|
| 719 | 696 |
Set<L2StratumResult> singleResult = new LinkedHashSet<>();
|
| 720 |
- for (L2StratumResult stratumResult : stratumsResult) {
|
|
| 697 |
+ for (L2StratumResult stratumResult : stratumResultSet) {
|
|
| 721 | 698 |
if (level == stratumResult.getSubstitutionLevel()) {
|
| 722 | 699 |
singleResult.add(stratumResult);
|
| 723 | 700 |
}
|
| ... | ... | @@ -752,7 +729,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 752 | 729 |
@SuppressWarnings("unused")
|
| 753 | 730 |
public int getMaximumSizeForStratum() {
|
| 754 | 731 |
int result = 0;
|
| 755 |
- for (L2StratumResult stratumResult : stratumsResult) {
|
|
| 732 |
+ for (L2StratumResult stratumResult : stratumResultSet) {
|
|
| 756 | 733 |
result = Math.max(result, stratumResult.getLibelle().length() + 1);
|
| 757 | 734 |
}
|
| 758 | 735 |
return result;
|
| ... | ... | @@ -796,8 +773,8 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 796 | 773 |
modelForSpeciestoFix);
|
| 797 | 774 |
}
|
| 798 | 775 |
|
| 799 |
- public void setStratumsResult(Set<L2StratumResult> stratumsResult) {
|
|
| 800 |
- this.stratumsResult = stratumsResult;
|
|
| 776 |
+ public void setStratumResultSet(Set<L2StratumResult> stratumResultSet) {
|
|
| 777 |
+ this.stratumResultSet = stratumResultSet;
|
|
| 801 | 778 |
}
|
| 802 | 779 |
|
| 803 | 780 |
public void setInputCatchModelForAllSpecies(WeightCompositionAggregateModel inputCatchModelForAllSpecies) {
|
| ... | ... | @@ -807,4 +784,8 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 807 | 784 |
public void setOutputCatchModelForAllSpecies(WeightCompositionAggregateModel outputCatchModelForAllSpecies) {
|
| 808 | 785 |
this.outputCatchModelForAllSpecies = outputCatchModelForAllSpecies;
|
| 809 | 786 |
}
|
| 787 |
+ |
|
| 788 |
+ T3ServiceContext getServiceContext() {
|
|
| 789 |
+ return serviceContext;
|
|
| 790 |
+ }
|
|
| 810 | 791 |
}
|
| ... | ... | @@ -181,7 +181,7 @@ public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Ac |
| 181 | 181 |
speciesCount.put(species, oldCount + newCount);
|
| 182 | 182 |
}
|
| 183 | 183 |
}
|
| 184 |
- addMergedActivitesCount(activities.size());
|
|
| 184 |
+ addMergedActivitiesCount(activities.size());
|
|
| 185 | 185 |
|
| 186 | 186 |
if (log.isInfoEnabled()) {
|
| 187 | 187 |
log.info(String.format("sampleStratumTotalWeight = %s", getSampleStratumTotalWeight()));
|
| ... | ... | @@ -746,7 +746,7 @@ public class ActionResumeTest<C extends T3ActionConfiguration, A extends T3Actio |
| 746 | 746 |
stratumResult.setNbActivities(5);
|
| 747 | 747 |
|
| 748 | 748 |
stratumsResult.add(stratumResult);
|
| 749 |
- action.setStratumsResult(stratumsResult);
|
|
| 749 |
+ action.setStratumResultSet(stratumsResult);
|
|
| 750 | 750 |
|
| 751 | 751 |
action.setInputCatchModelForAllSpecies(new WeightCompositionAggregateModel());
|
| 752 | 752 |
action.setOutputCatchModelForAllSpecies(new WeightCompositionAggregateModel());
|
| ... | ... | @@ -27,7 +27,6 @@ import fr.ird.t3.entities.reference.WeightCategoryTreatment; |
| 27 | 27 |
import fr.ird.t3.services.IOCService;
|
| 28 | 28 |
import fr.ird.t3.services.T3ServiceContext;
|
| 29 | 29 |
import fr.ird.t3.services.ioc.InjectDAO;
|
| 30 |
-import org.nuiton.topia.persistence.TopiaException;
|
|
| 31 | 30 |
|
| 32 | 31 |
import java.util.Collection;
|
| 33 | 32 |
import java.util.List;
|
| ... | ... | @@ -60,10 +59,13 @@ public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A e |
| 60 | 59 |
*/
|
| 61 | 60 |
private Integer substitutionLevel;
|
| 62 | 61 |
|
| 62 |
+ protected SampleStratum(StratumConfiguration<C> configuration, Collection<Species> speciesToFix) {
|
|
| 63 |
+ super(configuration, speciesToFix);
|
|
| 64 |
+ }
|
|
| 65 |
+ |
|
| 63 | 66 |
protected abstract SampleStratumLoader<C, A, S> newLoader();
|
| 64 | 67 |
|
| 65 |
- protected abstract String logSampleStratumLevel(int substitutionLevel,
|
|
| 66 |
- A messager);
|
|
| 68 |
+ protected abstract String logSampleStratumLevel(int substitutionLevel, A messager);
|
|
| 67 | 69 |
|
| 68 | 70 |
/**
|
| 69 | 71 |
* Merge the given {@code activities} sample data in the stratum result.
|
| ... | ... | @@ -81,24 +83,15 @@ public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A e |
| 81 | 83 |
*
|
| 82 | 84 |
* @param serviceContext service context
|
| 83 | 85 |
* @param activities the activities to merge
|
| 84 |
- * @throws TopiaException if any database problem while loading data
|
|
| 85 | 86 |
*/
|
| 86 |
- protected abstract void mergeNewActivities(T3ServiceContext serviceContext,
|
|
| 87 |
- Set<Activity> activities) throws TopiaException;
|
|
| 88 |
- |
|
| 89 |
- protected SampleStratum(StratumConfiguration<C> configuration,
|
|
| 90 |
- Collection<Species> speciesToFix) {
|
|
| 91 |
- super(configuration, speciesToFix);
|
|
| 92 |
- }
|
|
| 87 |
+ protected abstract void mergeNewActivities(T3ServiceContext serviceContext, Set<Activity> activities);
|
|
| 93 | 88 |
|
| 94 |
- protected final void addMergedActivitesCount(int nb) {
|
|
| 89 |
+ protected final void addMergedActivitiesCount(int nb) {
|
|
| 95 | 90 |
nbMergedActivities += nb;
|
| 96 | 91 |
}
|
| 97 | 92 |
|
| 98 | 93 |
@Override
|
| 99 |
- public void init(T3ServiceContext serviceContext,
|
|
| 100 |
- List<WeightCategoryTreatment> weightCategories,
|
|
| 101 |
- A messager) throws Exception {
|
|
| 94 |
+ public void init(T3ServiceContext serviceContext, List<WeightCategoryTreatment> weightCategories, A messager) throws Exception {
|
|
| 102 | 95 |
|
| 103 | 96 |
SampleStratumLoader<C, A, S> stratumLoader = newLoader();
|
| 104 | 97 |
|
| ... | ... | @@ -40,28 +40,25 @@ import java.util.TreeMap; |
| 40 | 40 |
*/
|
| 41 | 41 |
public class LengthWeightConversionHelper {
|
| 42 | 42 |
|
| 43 |
- /** Logger. */
|
|
| 44 |
- private static final Log log =
|
|
| 45 |
- LogFactory.getLog(LengthWeightConversionHelper.class);
|
|
| 43 |
+ private static final Log log = LogFactory.getLog(LengthWeightConversionHelper.class);
|
|
| 46 | 44 |
|
| 47 |
- protected final LengthWeightConversionTopiaDao dao;
|
|
| 45 |
+ private final LengthWeightConversionTopiaDao dao;
|
|
| 48 | 46 |
private final Map<String, LengthWeightConversion> lengthWeightConversions;
|
| 49 | 47 |
private final Map<String, Integer> lengthClassMap;
|
| 50 |
- |
|
| 51 | 48 |
private final ConversionContext conversionContext;
|
| 52 | 49 |
|
| 53 | 50 |
LengthWeightConversionHelper(LengthWeightConversionTopiaDao dao, Ocean ocean, int sex, Date date) {
|
| 54 | 51 |
this.dao = dao;
|
| 55 | 52 |
this.conversionContext = new ConversionContext(ocean, sex, date);
|
| 56 |
- lengthWeightConversions = new TreeMap<>();
|
|
| 57 |
- lengthClassMap = new TreeMap<>();
|
|
| 53 |
+ this.lengthWeightConversions = new TreeMap<>();
|
|
| 54 |
+ this.lengthClassMap = new TreeMap<>();
|
|
| 58 | 55 |
}
|
| 59 | 56 |
|
| 60 | 57 |
LengthWeightConversionHelper(LengthWeightConversionTopiaDao dao) {
|
| 61 | 58 |
this.dao = dao;
|
| 62 | 59 |
this.conversionContext = null;
|
| 63 |
- lengthWeightConversions = new TreeMap<>();
|
|
| 64 |
- lengthClassMap = new TreeMap<>();
|
|
| 60 |
+ this.lengthWeightConversions = new TreeMap<>();
|
|
| 61 |
+ this.lengthClassMap = new TreeMap<>();
|
|
| 65 | 62 |
}
|
| 66 | 63 |
|
| 67 | 64 |
private <W extends WeightCategory> W getNextCategory(LengthWeightConversion conversion, int lengthClass, Iterator<W> itr) {
|
| ... | ... | @@ -77,7 +74,7 @@ public class LengthWeightConversionHelper { |
| 77 | 74 |
} else {
|
| 78 | 75 |
|
| 79 | 76 |
// get max lengthClass
|
| 80 |
- int nextLengthClass = getSpecieHighestLengthClass(conversion, result);
|
|
| 77 |
+ int nextLengthClass = getSpecieHighestLengthClass(conversion, result.getMax());
|
|
| 81 | 78 |
|
| 82 | 79 |
if (nextLengthClass < lengthClass) {
|
| 83 | 80 |
|
| ... | ... | @@ -89,10 +86,9 @@ public class LengthWeightConversionHelper { |
| 89 | 86 |
return result;
|
| 90 | 87 |
}
|
| 91 | 88 |
|
| 92 |
- public <W extends WeightCategory> Map<Integer, W> getWeightCategoriesDistribution(
|
|
| 93 |
- LengthWeightConversion conversion,
|
|
| 94 |
- List<W> weightCategories,
|
|
| 95 |
- List<Integer> lengthClasses) {
|
|
| 89 |
+ public <W extends WeightCategory> Map<Integer, W> getWeightCategoriesDistribution(LengthWeightConversion conversion,
|
|
| 90 |
+ List<W> weightCategories,
|
|
| 91 |
+ List<Integer> lengthClasses) {
|
|
| 96 | 92 |
Map<Integer, W> result = new TreeMap<>();
|
| 97 | 93 |
W currentWeightCategory = null;
|
| 98 | 94 |
int currentMaxLengthClass = -1;
|
| ... | ... | @@ -105,7 +101,7 @@ public class LengthWeightConversionHelper { |
| 105 | 101 |
if (currentWeightCategory == null) {
|
| 106 | 102 |
// get the correct weight category
|
| 107 | 103 |
currentWeightCategory = getNextCategory(conversion, lengthClass, itr);
|
| 108 |
- currentMaxLengthClass = getSpecieHighestLengthClass(conversion, currentWeightCategory);
|
|
| 104 |
+ currentMaxLengthClass = getSpecieHighestLengthClass(conversion, currentWeightCategory.getMax());
|
|
| 109 | 105 |
}
|
| 110 | 106 |
result.put(lengthClass, currentWeightCategory);
|
| 111 | 107 |
}
|
| ... | ... | @@ -113,7 +109,7 @@ public class LengthWeightConversionHelper { |
| 113 | 109 |
}
|
| 114 | 110 |
|
| 115 | 111 |
/**
|
| 116 |
- * Get the convertor for the given parameters from the cache.
|
|
| 112 |
+ * Get the converter for the given parameters from the cache.
|
|
| 117 | 113 |
* <p/>
|
| 118 | 114 |
* If not found, then load it from db.
|
| 119 | 115 |
*
|
| ... | ... | @@ -122,13 +118,10 @@ public class LengthWeightConversionHelper { |
| 122 | 118 |
* @param sex sex to use
|
| 123 | 119 |
* @param date min date to use
|
| 124 | 120 |
* @return convertor found
|
| 125 |
- * @throws TopiaException if any db while querying db
|
|
| 126 | 121 |
*/
|
| 127 | 122 |
public LengthWeightConversion getConversions(Species species, Ocean ocean, int sex, Date date) {
|
| 128 |
- LengthWeightConversion result;
|
|
| 129 |
- String key = species.getCode() + "-" + ocean.getCode() +
|
|
| 130 |
- "-" + sex + "-" + T3Date.newDate(date);
|
|
| 131 |
- result = lengthWeightConversions.get(key);
|
|
| 123 |
+ String key = species.getCode() + "-" + ocean.getCode() + "-" + sex + "-" + T3Date.newDate(date);
|
|
| 124 |
+ LengthWeightConversion result = lengthWeightConversions.get(key);
|
|
| 132 | 125 |
if (result == null && !lengthWeightConversions.containsKey(key)) {
|
| 133 | 126 |
// load it from db
|
| 134 | 127 |
result = dao.findLengthWeightConversion(species, ocean, 0, date);
|
| ... | ... | @@ -140,17 +133,16 @@ public class LengthWeightConversionHelper { |
| 140 | 133 |
}
|
| 141 | 134 |
|
| 142 | 135 |
/**
|
| 143 |
- * Get the convertor for the given parameters from the cache.
|
|
| 136 |
+ * Get the converter for the given parameters from the cache.
|
|
| 144 | 137 |
* <p/>
|
| 145 | 138 |
* If not found, then load it from db.
|
| 146 | 139 |
*
|
| 147 | 140 |
* @param species species to use
|
| 148 | 141 |
* @return convertor found
|
| 149 |
- * @throws TopiaException if any db while querying db
|
|
| 150 | 142 |
*/
|
| 151 | 143 |
public LengthWeightConversion getConversions(Species species) {
|
| 152 | 144 |
Objects.requireNonNull(conversionContext,
|
| 153 |
- "No conversion context, must specify all parameters to obtain a convertor.");
|
|
| 145 |
+ "No conversion context, must specify all parameters to obtain a converter.");
|
|
| 154 | 146 |
LengthWeightConversion result;
|
| 155 | 147 |
String key = species.getCode() + conversionContext.getKey();
|
| 156 | 148 |
result = lengthWeightConversions.get(key);
|
| ... | ... | @@ -163,24 +155,24 @@ public class LengthWeightConversionHelper { |
| 163 | 155 |
}
|
| 164 | 156 |
return result;
|
| 165 | 157 |
}
|
| 166 |
- |
|
| 167 |
- public Integer getSpecieHighestLengthClass(Species species, WeightCategory weightCategory) {
|
|
| 168 |
- LengthWeightConversion conversions = getConversions(species);
|
|
| 169 |
- Integer result;
|
|
| 170 |
- if (conversions == null) {
|
|
| 171 |
- result = null;
|
|
| 172 |
- } else {
|
|
| 173 |
- result = getSpecieHighestLengthClass(conversions, weightCategory);
|
|
| 174 |
- }
|
|
| 175 |
- return result;
|
|
| 176 |
- }
|
|
| 177 |
- |
|
| 178 |
- public int getSpecieHighestLengthClass(LengthWeightConversion conversion, WeightCategory weightCategory) {
|
|
| 179 |
- String key = conversion.getTopiaId() + "-" + weightCategory.getTopiaId();
|
|
| 158 |
+//
|
|
| 159 |
+// public Integer getSpecieHighestLengthClass(Species species, WeightCategory weightCategory) {
|
|
| 160 |
+// LengthWeightConversion conversions = getConversions(species);
|
|
| 161 |
+// Integer result;
|
|
| 162 |
+// if (conversions == null) {
|
|
| 163 |
+// result = null;
|
|
| 164 |
+// } else {
|
|
| 165 |
+// result = getSpecieHighestLengthClass(conversions, weightCategory);
|
|
| 166 |
+// }
|
|
| 167 |
+// return result;
|
|
| 168 |
+// }
|
|
| 169 |
+ |
|
| 170 |
+ public int getSpecieHighestLengthClass(LengthWeightConversion conversion, Integer max) {
|
|
| 171 |
+ String key = conversion.getTopiaId() + "-" + max/*weightCategory.getTopiaId()*/;
|
|
| 180 | 172 |
Integer result = lengthClassMap.get(key);
|
| 181 | 173 |
if (result == null) {
|
| 182 | 174 |
// load it once for all
|
| 183 |
- result = conversion.getSpecieHighestLengthClass(weightCategory.getMax());
|
|
| 175 |
+ result = conversion.getSpecieHighestLengthClass(max /*weightCategory.getMax()*/);
|
|
| 184 | 176 |
// store it once for all
|
| 185 | 177 |
lengthClassMap.put(key, result);
|
| 186 | 178 |
log.info(String.format("Cache lengthClassMap [%d] for %s", lengthClassMap.size(), key));
|
| ... | ... | @@ -85,8 +85,7 @@ public class WeightCompositionAggregateModel implements Closeable { |
| 85 | 85 |
}
|
| 86 | 86 |
|
| 87 | 87 |
public void addModel(WeightCompositionAggregateModel modelToMerge) {
|
| 88 |
- for (WeightCompositionModel compositionModel :
|
|
| 89 |
- modelToMerge.getModel().values()) {
|
|
| 88 |
+ for (WeightCompositionModel compositionModel : modelToMerge.getModel().values()) {
|
|
| 90 | 89 |
addModel(compositionModel);
|
| 91 | 90 |
}
|
| 92 | 91 |
}
|
| ... | ... | @@ -127,7 +127,7 @@ public class LengthWeightConversionHelperTest extends AbstractDatabaseTest { |
| 127 | 127 |
Assert.assertFalse(allCategories.isEmpty());
|
| 128 | 128 |
|
| 129 | 129 |
for (WeightCategoryTreatment category : allCategories) {
|
| 130 |
- conversionHelper.getSpecieHighestLengthClass(conversion, category);
|
|
| 130 |
+ conversionHelper.getSpecieHighestLengthClass(conversion, category.getMax());
|
|
| 131 | 131 |
}
|
| 132 | 132 |
|
| 133 | 133 |
Range<Integer> open = Range.open(0, 1000);
|