Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
-
ea4a2e79
by Tony CHEMIT at 2018-02-21T20:14:49+01:00
8 changed files:
- t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratum.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratum.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3CatchStratum.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratum.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level3/Level3Action.java
- t3-domain/src/main/java/fr/ird/t3/actions/stratum/Stratum.java
- t3-domain/src/main/java/fr/ird/t3/actions/stratum/StratumConfiguration.java
Changes:
| ... | ... | @@ -133,9 +133,7 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti |
| 133 | 133 |
Integer nbZones = e.getValue();
|
| 134 | 134 |
|
| 135 | 135 |
if (!activity.isCorrectedElementaryCatchEmpty()) {
|
| 136 |
- for (CorrectedElementaryCatch aCatch :
|
|
| 137 |
- activity.getCorrectedElementaryCatch()) {
|
|
| 138 |
- |
|
| 136 |
+ for (CorrectedElementaryCatch aCatch : activity.getCorrectedElementaryCatch()) {
|
|
| 139 | 137 |
weightCategoriesForSpecies.put(aCatch.getWeightCategoryTreatment(), aCatch.getSpecies());
|
| 140 | 138 |
}
|
| 141 | 139 |
}
|
| ... | ... | @@ -155,8 +153,7 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti |
| 155 | 153 |
}
|
| 156 | 154 |
}
|
| 157 | 155 |
|
| 158 |
- inputModelForSpeciesToFix =
|
|
| 159 |
- inputModelForAllSpecies.extractForSpecies(getSpeciesToFix());
|
|
| 156 |
+ inputModelForSpeciesToFix = inputModelForAllSpecies.extractForSpecies(getSpeciesToFix());
|
|
| 160 | 157 |
}
|
| 161 | 158 |
|
| 162 | 159 |
public int getNbActivitiesWithSample() {
|
| ... | ... | @@ -225,12 +222,10 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti |
| 225 | 222 |
}
|
| 226 | 223 |
|
| 227 | 224 |
public void mergeGlobalCompositionModels(WeightCompositionAggregateModel inputModel, WeightCompositionAggregateModel outputModel) {
|
| 228 |
- |
|
| 229 | 225 |
inputModel.addModel(inputModelForAllSpecies);
|
| 230 | 226 |
outputModel.addModel(outputModelForAllSpecies);
|
| 231 | 227 |
}
|
| 232 | 228 |
|
| 233 |
- |
|
| 234 | 229 |
@Override
|
| 235 | 230 |
protected CatchStratumLoader<Level2Configuration> newLoader() {
|
| 236 | 231 |
return new L2CatchStratumLoader();
|
| ... | ... | @@ -145,8 +145,7 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac |
| 145 | 145 |
ActivityTopiaDao.fillWeightsFromSetSpeciesCatWeight(activity, weights, null);
|
| 146 | 146 |
|
| 147 | 147 |
// obtain the set species frequencies for the current activity
|
| 148 |
- Collection<SetSpeciesFrequency> setSpeciesFrequencies =
|
|
| 149 |
- activity.getSetSpeciesFrequency();
|
|
| 148 |
+ Collection<SetSpeciesFrequency> setSpeciesFrequencies = activity.getSetSpeciesFrequency();
|
|
| 150 | 149 |
|
| 151 | 150 |
if (CollectionUtils.isNotEmpty(setSpeciesFrequencies)) {
|
| 152 | 151 |
|
| ... | ... | @@ -25,7 +25,6 @@ import com.google.common.cache.CacheLoader; |
| 25 | 25 |
import com.google.common.cache.LoadingCache;
|
| 26 | 26 |
import com.google.common.collect.LinkedHashMultimap;
|
| 27 | 27 |
import com.google.common.collect.Multimap;
|
| 28 |
-import com.google.common.collect.Sets;
|
|
| 29 | 28 |
import fr.ird.t3.actions.T3Action;
|
| 30 | 29 |
import fr.ird.t3.actions.stratum.OceanContext;
|
| 31 | 30 |
import fr.ird.t3.actions.stratum.StratumConfiguration;
|
| ... | ... | @@ -54,6 +53,7 @@ import fr.ird.t3.services.ioc.InjectDAO; |
| 54 | 53 |
import fr.ird.t3.services.ioc.InjectEntitiesById;
|
| 55 | 54 |
import fr.ird.t3.services.ioc.InjectFromDAO;
|
| 56 | 55 |
import org.apache.commons.io.IOUtils;
|
| 56 |
+import org.apache.commons.lang3.mutable.MutableInt;
|
|
| 57 | 57 |
import org.apache.commons.logging.Log;
|
| 58 | 58 |
import org.apache.commons.logging.LogFactory;
|
| 59 | 59 |
import org.nuiton.topia.persistence.TopiaException;
|
| ... | ... | @@ -82,7 +82,6 @@ import static org.nuiton.i18n.I18n.l; |
| 82 | 82 |
*/
|
| 83 | 83 |
public class Level2Action extends T3Action<Level2Configuration> {
|
| 84 | 84 |
|
| 85 |
- // public static final String PARAM_LEVEL_CONFIGURATION = "levelConfiguration";
|
|
| 86 | 85 |
private static final Log log = LogFactory.getLog(Level2Action.class);
|
| 87 | 86 |
/**
|
| 88 | 87 |
* Cache of activity (to avoid to reload them for catch and sample stratum).
|
| ... | ... | @@ -211,72 +210,119 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 211 | 210 |
|
| 212 | 211 |
Level2Configuration configuration = getConfiguration();
|
| 213 | 212 |
|
| 214 |
- // get time step
|
|
| 215 |
- int timeStep = configuration.getTimeStep();
|
|
| 213 |
+ // keep a track of already used activity ids (to remove previous level 2 data)
|
|
| 214 |
+ Set<String> usedActivityIds = new HashSet<>();
|
|
| 215 |
+ |
|
| 216 |
+ boolean useWeightCategoriesInStratum = configuration.isUseWeightCategoriesInStratum();
|
|
| 216 | 217 |
|
| 217 |
-// nbStratums = zoneBySchoolType.size() * startDates.size();
|
|
| 218 |
- nbStratums = oceanContext.values().stream().mapToInt(OceanContext::sizeZones).sum() * startDates.size();
|
|
| 218 |
+ if (useWeightCategoriesInStratum) {
|
|
| 219 |
+ executeActionWithCategories(configuration, usedActivityIds);
|
|
| 220 |
+ } else {
|
|
| 221 |
+ executeActionWithoutCategories(configuration, usedActivityIds);
|
|
| 222 |
+ }
|
|
| 223 |
+ return true;
|
|
| 224 |
+ }
|
|
| 225 |
+ |
|
| 226 |
+ private void executeActionWithCategories(Level2Configuration configuration, Set<String> usedActivityIds) throws Exception {
|
|
| 227 |
+ |
|
| 228 |
+ nbStratums = 0;
|
|
| 229 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 230 |
+ List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType);
|
|
| 231 |
+ Collection<ZoneStratumAware> zones = getZones(schoolType);
|
|
| 232 |
+ nbStratums += startDates.size() * zones.size() * weightCategories.size();
|
|
| 233 |
+ }
|
|
| 219 | 234 |
setNbSteps(3 * nbStratums);
|
| 220 | 235 |
|
| 221 |
- // keep a track of alreay used activity ids (to remove previous level 2 data)
|
|
| 222 |
- Set<String> usedActivityIds = new HashSet<>();
|
|
| 236 |
+ int timeStep = configuration.getTimeStep();
|
|
| 223 | 237 |
|
| 224 |
- int stratumIndex = 1;
|
|
| 238 |
+ MutableInt stratumIndex = new MutableInt(1);
|
|
| 225 | 239 |
for (SchoolType schoolType : schoolTypes) {
|
| 240 |
+ List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType);
|
|
| 241 |
+ Collection<ZoneStratumAware> zones = getZones(schoolType);
|
|
| 242 |
+ for (ZoneStratumAware zone : zones) {
|
|
| 243 |
+ for (WeightCategoryTreatment weightCategory : weightCategories) {
|
|
| 244 |
+ doIterateOnDates(timeStep, configuration, schoolType, zones, zone, weightCategories, weightCategory, usedActivityIds, stratumIndex);
|
|
| 245 |
+ }
|
|
| 246 |
+ }
|
|
| 247 |
+ }
|
|
| 248 |
+ }
|
|
| 249 |
+ |
|
| 250 |
+ |
|
| 251 |
+ private void executeActionWithoutCategories(Level2Configuration configuration, Set<String> usedActivityIds) throws Exception {
|
|
| 226 | 252 |
|
| 227 |
- // get all weight categories for this school type
|
|
| 228 |
-// List<WeightCategoryTreatment> weightCategories = Lists.newArrayList(weightCategoriesBySchoolType.get(schoolType));
|
|
| 229 |
- List<WeightCategoryTreatment> weightCategories = oceanContext.values().stream().flatMap(o -> o.getWeightCategories(schoolType).stream()).distinct().collect(Collectors.toList());
|
|
| 230 |
- weightCategoryTreatmentDAO.sort(weightCategories);
|
|
| 253 |
+ nbStratums = 0;
|
|
| 254 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 255 |
+ Collection<ZoneStratumAware> zones = getZones(schoolType);
|
|
| 256 |
+ nbStratums += startDates.size() * zones.size();
|
|
| 257 |
+ }
|
|
| 258 |
+ setNbSteps(3 * nbStratums);
|
|
| 231 | 259 |
|
| 232 |
- // get all zones for this school type
|
|
| 233 |
-// Collection<ZoneStratumAware> zones = zoneBySchoolType.get(schoolType);
|
|
| 234 |
- Collection<ZoneStratumAware> zones = oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList());
|
|
| 260 |
+ int timeStep = configuration.getTimeStep();
|
|
| 235 | 261 |
|
| 262 |
+ MutableInt stratumIndex = new MutableInt(1);
|
|
| 263 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 264 |
+ List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType);
|
|
| 265 |
+ Collection<ZoneStratumAware> zones = getZones(schoolType);
|
|
| 236 | 266 |
for (ZoneStratumAware zone : zones) {
|
| 267 |
+ doIterateOnDates(timeStep, configuration, schoolType, zones, zone, weightCategories, null, usedActivityIds, stratumIndex);
|
|
| 268 |
+ }
|
|
| 269 |
+ }
|
|
| 237 | 270 |
|
| 238 |
- for (T3Date startDate : startDates) {
|
|
| 239 |
- |
|
| 240 |
- // get end date (only increments on timseStep - 1 to have
|
|
| 241 |
- // exactly timstep month from beginDate.toStartDate() to
|
|
| 242 |
- // endDate.toEndDate()
|
|
| 243 |
- T3Date endDate = startDate.incrementsMonths(timeStep - 1);
|
|
| 244 |
- |
|
| 245 |
- StratumConfiguration<Level2Configuration>
|
|
| 246 |
- stratumConfiguration =
|
|
| 247 |
- StratumConfiguration.newStratumConfiguration(
|
|
| 248 |
- configuration,
|
|
| 249 |
- zoneMeta,
|
|
| 250 |
- zone,
|
|
| 251 |
- schoolType,
|
|
| 252 |
- startDate,
|
|
| 253 |
- endDate,
|
|
| 254 |
- zones,
|
|
| 255 |
- possibleCatchVessels,
|
|
| 256 |
- possibleSampleVessels,
|
|
| 257 |
- null,
|
|
| 258 |
- activityCache
|
|
| 259 |
- );
|
|
| 260 |
- |
|
| 261 |
- try {
|
|
| 262 |
- L2StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds);
|
|
| 263 |
- |
|
| 264 |
- stratumsResult.add(result);
|
|
| 265 |
- } finally {
|
|
| 266 |
- flushTransaction("After stratum " + stratumIndex);
|
|
| 267 |
- }
|
|
| 271 |
+ }
|
|
| 268 | 272 |
|
| 269 |
- stratumIndex++;
|
|
| 270 |
- }
|
|
| 273 |
+ private List<WeightCategoryTreatment> getWeightCategoryTreatments(SchoolType schoolType) {
|
|
| 274 |
+ List<WeightCategoryTreatment> weightCategoryTreatments = oceanContext.values().stream().flatMap(o -> o.getWeightCategories(schoolType).stream()).distinct().collect(Collectors.toList());
|
|
| 275 |
+ weightCategoryTreatmentDAO.sort(weightCategoryTreatments);
|
|
| 276 |
+ return weightCategoryTreatments;
|
|
| 277 |
+ }
|
|
| 278 |
+ |
|
| 279 |
+ private Collection<ZoneStratumAware> getZones(SchoolType schoolType) {
|
|
| 280 |
+ return oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList());
|
|
| 281 |
+ }
|
|
| 282 |
+ |
|
| 283 |
+ private void doIterateOnDates(int timeStep, Level2Configuration configuration, SchoolType schoolType, Collection<ZoneStratumAware> zones, ZoneStratumAware zone, List<WeightCategoryTreatment> weightCategories, WeightCategoryTreatment weightCategoryTreatment, Set<String> usedActivityIds, MutableInt stratumIndex) throws Exception {
|
|
| 284 |
+ |
|
| 285 |
+ for (T3Date startDate : startDates) {
|
|
| 286 |
+ |
|
| 287 |
+ // get end date (only increments on timseStep - 1 to have
|
|
| 288 |
+ // exactly timstep month from beginDate.toStartDate() to
|
|
| 289 |
+ // endDate.toEndDate()
|
|
| 290 |
+ T3Date endDate = startDate.incrementsMonths(timeStep - 1);
|
|
| 291 |
+ |
|
| 292 |
+ StratumConfiguration<Level2Configuration>
|
|
| 293 |
+ stratumConfiguration =
|
|
| 294 |
+ StratumConfiguration.newStratumConfiguration(
|
|
| 295 |
+ configuration,
|
|
| 296 |
+ zoneMeta,
|
|
| 297 |
+ zone,
|
|
| 298 |
+ schoolType,
|
|
| 299 |
+ weightCategoryTreatment,
|
|
| 300 |
+ startDate,
|
|
| 301 |
+ endDate,
|
|
| 302 |
+ zones,
|
|
| 303 |
+ possibleCatchVessels,
|
|
| 304 |
+ possibleSampleVessels,
|
|
| 305 |
+ null,
|
|
| 306 |
+ activityCache
|
|
| 307 |
+ );
|
|
| 308 |
+ |
|
| 309 |
+ try {
|
|
| 310 |
+ L2StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds);
|
|
| 311 |
+ |
|
| 312 |
+ stratumsResult.add(result);
|
|
| 313 |
+ } finally {
|
|
| 314 |
+ flushTransaction("After stratum " + stratumIndex);
|
|
| 271 | 315 |
}
|
| 316 |
+ |
|
| 317 |
+ stratumIndex.increment();
|
|
| 272 | 318 |
}
|
| 273 |
- return true;
|
|
| 319 |
+ |
|
| 274 | 320 |
}
|
| 275 | 321 |
|
| 276 |
- protected L2StratumResult doExecuteStratum(
|
|
| 322 |
+ private L2StratumResult doExecuteStratum(
|
|
| 277 | 323 |
StratumConfiguration<Level2Configuration> stratumConfiguration,
|
| 278 | 324 |
List<WeightCategoryTreatment> weightCategories,
|
| 279 |
- int stratumIndex,
|
|
| 325 |
+ MutableInt stratumIndex,
|
|
| 280 | 326 |
Set<String> usedActivityIds) throws Exception {
|
| 281 | 327 |
|
| 282 | 328 |
incrementsProgression();
|
| ... | ... | @@ -353,7 +399,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 353 | 399 |
// Fill back CorrectedElementaryCatch.CatchWeight to CorrectedElementaryCatch.CorrectedCatchWeight
|
| 354 | 400 |
|
| 355 | 401 |
int activityIndex = 1;
|
| 356 |
- int nbActivites = catchStratum.getNbActivities();
|
|
| 402 |
+ int nbActivities = catchStratum.getNbActivities();
|
|
| 357 | 403 |
for (Map.Entry<Activity, Integer> e : catchStratum) {
|
| 358 | 404 |
|
| 359 | 405 |
Activity activity = e.getKey();
|
| ... | ... | @@ -366,7 +412,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 366 | 412 |
doExecuteActivityInCatchStratum(catchStratum,
|
| 367 | 413 |
activity,
|
| 368 | 414 |
activityIndex++,
|
| 369 |
- nbActivites,
|
|
| 415 |
+ nbActivities,
|
|
| 370 | 416 |
newActivity);
|
| 371 | 417 |
|
| 372 | 418 |
// keep the stratum substitution level in the activity
|
| ... | ... | @@ -380,7 +426,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 380 | 426 |
// can use this sampleStratum
|
| 381 | 427 |
|
| 382 | 428 |
int activityIndex = 1;
|
| 383 |
- int nbActivites = catchStratum.getNbActivities();
|
|
| 429 |
+ int nbActivities = catchStratum.getNbActivities();
|
|
| 384 | 430 |
for (Map.Entry<Activity, Integer> e : catchStratum) {
|
| 385 | 431 |
|
| 386 | 432 |
Activity activity = e.getKey();
|
| ... | ... | @@ -395,7 +441,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 395 | 441 |
activity,
|
| 396 | 442 |
nbZones,
|
| 397 | 443 |
activityIndex++,
|
| 398 |
- nbActivites,
|
|
| 444 |
+ nbActivities,
|
|
| 399 | 445 |
newActivity);
|
| 400 | 446 |
|
| 401 | 447 |
// keep the stratum substitution level in the activity
|
| ... | ... | @@ -432,8 +478,8 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 432 | 478 |
return result;
|
| 433 | 479 |
}
|
| 434 | 480 |
|
| 435 |
- protected L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
|
|
| 436 |
- List<WeightCategoryTreatment> weightCategories) throws Exception {
|
|
| 481 |
+ private L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
|
|
| 482 |
+ List<WeightCategoryTreatment> weightCategories) throws Exception {
|
|
| 437 | 483 |
L2CatchStratum catchStratum = new L2CatchStratum(stratumConfiguration, species);
|
| 438 | 484 |
catchStratum.init(serviceContext, weightCategories, this);
|
| 439 | 485 |
|
| ... | ... | @@ -463,26 +509,25 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 463 | 509 |
return catchStratum;
|
| 464 | 510 |
}
|
| 465 | 511 |
|
| 466 |
- protected L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
|
|
| 467 |
- List<WeightCategoryTreatment> weightCategories,
|
|
| 468 |
- float totalCatchWeight) throws Exception {
|
|
| 512 |
+ private L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
|
|
| 513 |
+ List<WeightCategoryTreatment> weightCategories,
|
|
| 514 |
+ float totalCatchWeight) throws Exception {
|
|
| 469 | 515 |
L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, species, totalCatchWeight);
|
| 470 | 516 |
sampleStratum.init(serviceContext, weightCategories, this);
|
| 471 | 517 |
return sampleStratum;
|
| 472 | 518 |
}
|
| 473 | 519 |
|
| 474 |
- protected void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum,
|
|
| 475 |
- L2SampleStratum sampleStratum,
|
|
| 476 |
- Activity activity,
|
|
| 477 |
- int nbZones,
|
|
| 478 |
- int activityIndex,
|
|
| 479 |
- int nbActivites,
|
|
| 480 |
- boolean deleteOldData) throws TopiaException, IOException {
|
|
| 520 |
+ private void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum,
|
|
| 521 |
+ L2SampleStratum sampleStratum,
|
|
| 522 |
+ Activity activity,
|
|
| 523 |
+ int nbZones,
|
|
| 524 |
+ int activityIndex,
|
|
| 525 |
+ int nbActivities,
|
|
| 526 |
+ boolean deleteOldData) throws TopiaException, IOException {
|
|
| 481 | 527 |
|
| 482 |
- String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(),
|
|
| 483 |
- DecoratorService.WITH_ID));
|
|
| 528 |
+ String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID));
|
|
| 484 | 529 |
|
| 485 |
- String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivites, activityStr, nbZones);
|
|
| 530 |
+ String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivities, activityStr, nbZones);
|
|
| 486 | 531 |
if (log.isInfoEnabled()) {
|
| 487 | 532 |
log.info(message);
|
| 488 | 533 |
}
|
| ... | ... | @@ -503,7 +548,6 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 503 | 548 |
|
| 504 | 549 |
WeightCompositionAggregateModel catchWeightModelForSpeciesToFix = catchWeightModelForAllSpecies.extractForSpecies(species);
|
| 505 | 550 |
|
| 506 |
- |
|
| 507 | 551 |
// log catches weight
|
| 508 | 552 |
message = logCatchWeight(getDecoratorService(), catchWeightModelForAllSpecies, catchWeightModelForSpeciesToFix);
|
| 509 | 553 |
if (log.isInfoEnabled()) {
|
| ... | ... | @@ -571,15 +615,15 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 571 | 615 |
|
| 572 | 616 |
}
|
| 573 | 617 |
|
| 574 |
- protected void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum,
|
|
| 575 |
- Activity activity,
|
|
| 576 |
- int activityIndex,
|
|
| 577 |
- int nbActivites,
|
|
| 578 |
- boolean deleteOldData) throws TopiaException, IOException {
|
|
| 618 |
+ private void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum,
|
|
| 619 |
+ Activity activity,
|
|
| 620 |
+ int activityIndex,
|
|
| 621 |
+ int nbActivities,
|
|
| 622 |
+ boolean deleteOldData) throws TopiaException, IOException {
|
|
| 579 | 623 |
|
| 580 | 624 |
String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID));
|
| 581 | 625 |
|
| 582 |
- String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivites, activityStr, 1);
|
|
| 626 |
+ String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivities, activityStr, 1);
|
|
| 583 | 627 |
if (log.isInfoEnabled()) {
|
| 584 | 628 |
log.info(message);
|
| 585 | 629 |
}
|
| ... | ... | @@ -631,7 +675,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 631 | 675 |
compositionModel.close();
|
| 632 | 676 |
}
|
| 633 | 677 |
|
| 634 |
- protected void applySampleSpecificComposition(L2CatchStratum catchStratum, Activity activity) throws TopiaException {
|
|
| 678 |
+ private void applySampleSpecificComposition(L2CatchStratum catchStratum, Activity activity) throws TopiaException {
|
|
| 635 | 679 |
|
| 636 | 680 |
WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel();
|
| 637 | 681 |
|
| ... | ... | @@ -675,11 +719,11 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 675 | 719 |
|
| 676 | 720 |
}
|
| 677 | 721 |
|
| 678 |
- protected void applySampleSpecificComposition(L2CatchStratum catchStratum,
|
|
| 679 |
- Activity activity,
|
|
| 680 |
- int nbZones,
|
|
| 681 |
- WeightCompositionAggregateModel sampleCompositionModel,
|
|
| 682 |
- WeightCompositionAggregateModel correctedCatchesForSpeciesToFix) throws TopiaException {
|
|
| 722 |
+ private void applySampleSpecificComposition(L2CatchStratum catchStratum,
|
|
| 723 |
+ Activity activity,
|
|
| 724 |
+ int nbZones,
|
|
| 725 |
+ WeightCompositionAggregateModel sampleCompositionModel,
|
|
| 726 |
+ WeightCompositionAggregateModel correctedCatchesForSpeciesToFix) throws TopiaException {
|
|
| 683 | 727 |
|
| 684 | 728 |
WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel();
|
| 685 | 729 |
|
| ... | ... | @@ -692,8 +736,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 692 | 736 |
Map<Species, Float> weights = new HashMap<>();
|
| 693 | 737 |
|
| 694 | 738 |
// get composition model to use
|
| 695 |
- WeightCompositionModel model =
|
|
| 696 |
- sampleCompositionModel.getModel(weightCategory);
|
|
| 739 |
+ WeightCompositionModel model = sampleCompositionModel.getModel(weightCategory);
|
|
| 697 | 740 |
|
| 698 | 741 |
// set of species still to fix
|
| 699 | 742 |
Set<Species> speciesToFix;
|
| ... | ... | @@ -721,10 +764,9 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 721 | 764 |
|
| 722 | 765 |
speciesToFix = model.getSpecies();
|
| 723 | 766 |
|
| 724 |
- speciesStillToFix = Sets.newHashSet(speciesToFix);
|
|
| 767 |
+ speciesStillToFix = new HashSet<>(speciesToFix);
|
|
| 725 | 768 |
|
| 726 |
- totalWeight = correctedCatchesForSpeciesToFix.getModel(
|
|
| 727 |
- weightCategory).getTotalWeight();
|
|
| 769 |
+ totalWeight = correctedCatchesForSpeciesToFix.getModel(weightCategory).getTotalWeight();
|
|
| 728 | 770 |
}
|
| 729 | 771 |
|
| 730 | 772 |
// divide the total weight to used by the number of zones of this
|
| ... | ... | @@ -734,8 +776,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 734 | 776 |
|
| 735 | 777 |
// Apply on all existing corrected catch weight
|
| 736 | 778 |
|
| 737 |
- for (CorrectedElementaryCatch aCatch :
|
|
| 738 |
- correctedElementaryCatches.get(weightCategory)) {
|
|
| 779 |
+ for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
|
|
| 739 | 780 |
|
| 740 | 781 |
Species speciesToUse = aCatch.getSpecies();
|
| 741 | 782 |
|
| ... | ... | @@ -789,8 +830,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 789 | 830 |
float correctedCatchWeight = totalWeight * weightRate;
|
| 790 | 831 |
|
| 791 | 832 |
// create new record
|
| 792 |
- CorrectedElementaryCatch aCatch =
|
|
| 793 |
- correctedElementaryCatchDAO.create();
|
|
| 833 |
+ CorrectedElementaryCatch aCatch = correctedElementaryCatchDAO.create();
|
|
| 794 | 834 |
aCatch.setSpecies(speciesToUse);
|
| 795 | 835 |
aCatch.setWeightCategoryTreatment(weightCategory);
|
| 796 | 836 |
aCatch.setCatchWeight(0f);
|
| ... | ... | @@ -809,8 +849,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 809 | 849 |
}
|
| 810 | 850 |
|
| 811 | 851 |
// log corrected catches weight
|
| 812 |
- String message = logCorrectedCatchWeight(correctedCatchWeightModel,
|
|
| 813 |
- getDecoratorService());
|
|
| 852 |
+ String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
|
|
| 814 | 853 |
if (log.isInfoEnabled()) {
|
| 815 | 854 |
log.info(message);
|
| 816 | 855 |
}
|
| ... | ... | @@ -828,10 +867,6 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 828 | 867 |
this.schoolTypes = schoolTypes;
|
| 829 | 868 |
}
|
| 830 | 869 |
|
| 831 |
-// public void setZoneBySchoolType(Multimap<SchoolType, ZoneStratumAware> zoneBySchoolType) {
|
|
| 832 |
-// this.zoneBySchoolType = zoneBySchoolType;
|
|
| 833 |
-// }
|
|
| 834 |
- |
|
| 835 | 870 |
public void setSpecies(Set<Species> species) {
|
| 836 | 871 |
this.species = species;
|
| 837 | 872 |
}
|
| ... | ... | @@ -840,10 +875,6 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 840 | 875 |
this.startDates = startDates;
|
| 841 | 876 |
}
|
| 842 | 877 |
|
| 843 |
-// public void setWeightCategoriesBySchoolType(Multimap<SchoolType, WeightCategoryTreatment> weightCategoriesBySchoolType) {
|
|
| 844 |
-// this.weightCategoriesBySchoolType = weightCategoriesBySchoolType;
|
|
| 845 |
-// }
|
|
| 846 |
- |
|
| 847 | 878 |
public void setPossibleCatchVessels(Set<Vessel> possibleCatchVessels) {
|
| 848 | 879 |
this.possibleCatchVessels = possibleCatchVessels;
|
| 849 | 880 |
}
|
| ... | ... | @@ -921,8 +952,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 921 | 952 |
|
| 922 | 953 |
public String getInputCatchStratumLog() {
|
| 923 | 954 |
|
| 924 |
- WeightCompositionAggregateModel inputCatchModelForSpeciesToFix =
|
|
| 925 |
- inputCatchModelForAllSpecies.extractForSpecies(species);
|
|
| 955 |
+ WeightCompositionAggregateModel inputCatchModelForSpeciesToFix = inputCatchModelForAllSpecies.extractForSpecies(species);
|
|
| 926 | 956 |
|
| 927 | 957 |
String title =
|
| 928 | 958 |
l(locale, "t3.level2.message.strateInputGlobalComposition.resume");
|
| ... | ... | @@ -936,8 +966,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 936 | 966 |
|
| 937 | 967 |
public String getOutputCatchStratumLog() {
|
| 938 | 968 |
|
| 939 |
- WeightCompositionAggregateModel outputCatchModelForSpeciesToFix =
|
|
| 940 |
- outputCatchModelForAllSpecies.extractForSpecies(species);
|
|
| 969 |
+ WeightCompositionAggregateModel outputCatchModelForSpeciesToFix = outputCatchModelForAllSpecies.extractForSpecies(species);
|
|
| 941 | 970 |
|
| 942 | 971 |
String title = l(locale, "t3.level2.message.strateOutputGlobalComposition.resume");
|
| 943 | 972 |
|
| ... | ... | @@ -959,10 +988,6 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 959 | 988 |
protected String logCatchWeight(DecoratorService decoratorService,
|
| 960 | 989 |
WeightCompositionAggregateModel modelForAllSpecies,
|
| 961 | 990 |
WeightCompositionAggregateModel modelForSpeciesToFix) {
|
| 962 |
-//
|
|
| 963 |
-// WeightCompositionAggregateModel modelForAllSpecies = catchesWeightForAllSpecies.get(activity);
|
|
| 964 |
-// WeightCompositionAggregateModel modelForSpeciesToFix =
|
|
| 965 |
-// getCatchesWeightForSpeciesToFix(activity);
|
|
| 966 | 991 |
|
| 967 | 992 |
String title = l(locale, "t3.level2.message.activityCatchWeight.resume",
|
| 968 | 993 |
modelForAllSpecies.getTotalModel().getTotalWeight(),
|
| ... | ... | @@ -978,8 +1003,7 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 978 | 1003 |
public String logCorrectedCatchWeight(WeightCompositionAggregateModel correctedCatchWeightModel,
|
| 979 | 1004 |
DecoratorService decoratorService) {
|
| 980 | 1005 |
|
| 981 |
- WeightCompositionAggregateModel modelForSpeciesToFix =
|
|
| 982 |
- correctedCatchWeightModel.extractForSpecies(species);
|
|
| 1006 |
+ WeightCompositionAggregateModel modelForSpeciesToFix = correctedCatchWeightModel.extractForSpecies(species);
|
|
| 983 | 1007 |
|
| 984 | 1008 |
|
| 985 | 1009 |
String title = l(locale, "t3.level2.message.activityCorrectedCatchWeight.resume",
|
| ... | ... | @@ -997,11 +1021,6 @@ public class Level2Action extends T3Action<Level2Configuration> { |
| 997 | 1021 |
WeightCompositionAggregateModel modelForSpeciestoFix,
|
| 998 | 1022 |
DecoratorService decoratorService) {
|
| 999 | 1023 |
|
| 1000 |
-// WeightCompositionAggregateModel modelForAllSpecies = specificActivityForAllSpeciesModels.get(activity);
|
|
| 1001 |
-//
|
|
| 1002 |
-// WeightCompositionAggregateModel modelForSpeciestoFix =
|
|
| 1003 |
-// getSpecificCompositionForSpeciesToFix(activity);
|
|
| 1004 |
- |
|
| 1005 | 1024 |
String title = l(locale, "t3.level2.message.activityComposition.resume",
|
| 1006 | 1025 |
modelForAllSpecies.getTotalModel().getTotalWeight(),
|
| 1007 | 1026 |
modelForSpeciestoFix.getTotalModel().getTotalWeight());
|
| ... | ... | @@ -53,7 +53,7 @@ public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Acti |
| 53 | 53 |
*
|
| 54 | 54 |
* @since 1.3.1
|
| 55 | 55 |
*/
|
| 56 |
- private float totalCatchtWeight;
|
|
| 56 |
+ private float totalCatchWeight;
|
|
| 57 | 57 |
|
| 58 | 58 |
/**
|
| 59 | 59 |
* Predicate to filter only species selected in configuration.
|
| ... | ... | @@ -85,7 +85,7 @@ public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Acti |
| 85 | 85 |
int nbZones = e.getValue();
|
| 86 | 86 |
|
| 87 | 87 |
// compute total catch weight of the activity (only for species to fix)
|
| 88 |
- totalCatchtWeight +=
|
|
| 88 |
+ totalCatchWeight +=
|
|
| 89 | 89 |
T3EntityHelper.getTotal(
|
| 90 | 90 |
activity.getCorrectedElementaryCatch(),
|
| 91 | 91 |
T3Functions.CORRECTED_ELEMENTARY_CATCH_TO_CORRECTED_CATCH_WEIGHT,
|
| ... | ... | @@ -118,7 +118,7 @@ public class L3CatchStratum extends CatchStratum<Level3Configuration, Level3Acti |
| 118 | 118 |
* @return total catch weight of selected catches for this stratum.
|
| 119 | 119 |
*/
|
| 120 | 120 |
public float getTotalCatchWeight() {
|
| 121 |
- return totalCatchtWeight;
|
|
| 121 |
+ return totalCatchWeight;
|
|
| 122 | 122 |
}
|
| 123 | 123 |
|
| 124 | 124 |
}
|
| ... | ... | @@ -24,7 +24,6 @@ import com.google.common.base.Predicate; |
| 24 | 24 |
import com.google.common.collect.ArrayListMultimap;
|
| 25 | 25 |
import com.google.common.collect.Multimap;
|
| 26 | 26 |
import com.google.common.collect.Multimaps;
|
| 27 |
-import com.google.common.collect.Sets;
|
|
| 28 | 27 |
import fr.ird.t3.T3IOUtil;
|
| 29 | 28 |
import fr.ird.t3.actions.stratum.SampleStratum;
|
| 30 | 29 |
import fr.ird.t3.actions.stratum.StratumConfiguration;
|
| ... | ... | @@ -48,6 +47,7 @@ import org.nuiton.topia.persistence.TopiaException; |
| 48 | 47 |
import java.io.IOException;
|
| 49 | 48 |
import java.util.Collection;
|
| 50 | 49 |
import java.util.HashMap;
|
| 50 |
+import java.util.HashSet;
|
|
| 51 | 51 |
import java.util.List;
|
| 52 | 52 |
import java.util.Locale;
|
| 53 | 53 |
import java.util.Map;
|
| ... | ... | @@ -182,7 +182,7 @@ public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Ac |
| 182 | 182 |
Multimaps.index(activity.getSetSpeciesFrequency(), T3Functions.SPECIES_AWARE_BY_SPECIES);
|
| 183 | 183 |
|
| 184 | 184 |
// get species found (and only the one to use)
|
| 185 |
- Set<Species> speciesFound = Sets.newHashSet(setSpeciesFrequenciesBySpecies.keySet());
|
|
| 185 |
+ Set<Species> speciesFound = new HashSet<>(setSpeciesFrequenciesBySpecies.keySet());
|
|
| 186 | 186 |
speciesFound.retainAll(getSpeciesToFix());
|
| 187 | 187 |
|
| 188 | 188 |
// add missing empty model
|
| ... | ... | @@ -220,8 +220,7 @@ public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Ac |
| 220 | 220 |
allSetSpeciesFrequenciesBySpecies,
|
| 221 | 221 |
compositionModel,
|
| 222 | 222 |
weightCategories,
|
| 223 |
- conversionHelper
|
|
| 224 |
- );
|
|
| 223 |
+ conversionHelper);
|
|
| 225 | 224 |
}
|
| 226 | 225 |
|
| 227 | 226 |
public float getCatchStratumTotalWeight() {
|
| ... | ... | @@ -72,6 +72,7 @@ import fr.ird.t3.services.ioc.InjectEntitiesById; |
| 72 | 72 |
import fr.ird.t3.services.ioc.InjectEntityById;
|
| 73 | 73 |
import fr.ird.t3.services.ioc.InjectFromDAO;
|
| 74 | 74 |
import org.apache.commons.io.IOUtils;
|
| 75 |
+import org.apache.commons.lang3.mutable.MutableInt;
|
|
| 75 | 76 |
import org.apache.commons.logging.Log;
|
| 76 | 77 |
import org.apache.commons.logging.LogFactory;
|
| 77 | 78 |
import org.nuiton.topia.persistence.TopiaException;
|
| ... | ... | @@ -85,6 +86,7 @@ import java.util.Collections; |
| 85 | 86 |
import java.util.Date;
|
| 86 | 87 |
import java.util.HashMap;
|
| 87 | 88 |
import java.util.HashSet;
|
| 89 |
+import java.util.LinkedHashSet;
|
|
| 88 | 90 |
import java.util.List;
|
| 89 | 91 |
import java.util.Map;
|
| 90 | 92 |
import java.util.Set;
|
| ... | ... | @@ -207,32 +209,13 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 207 | 209 |
configuration.setLocale(getLocale());
|
| 208 | 210 |
|
| 209 | 211 |
// get zones type meta to use
|
| 210 |
- setZoneMeta(
|
|
| 211 |
- newService(ZoneStratumService.class).getZoneMetaById(configuration.getZoneTypeId()));
|
|
| 212 |
+ setZoneMeta(newService(ZoneStratumService.class).getZoneMetaById(configuration.getZoneTypeId()));
|
|
| 212 | 213 |
|
| 213 | 214 |
setZoneVersion(zoneMeta.getZoneVersion(configuration.getZoneVersionId(), getT3TopiaPersistenceContext().get()));
|
| 214 | 215 |
|
| 215 |
-// // get all zones by ocean and shcool types
|
|
| 216 |
-// setZoneBySchoolType(
|
|
| 217 |
-// zoneMeta.getZones(
|
|
| 218 |
-// ocean,
|
|
| 219 |
-// schoolTypes,
|
|
| 220 |
-// zoneVersion,
|
|
| 221 |
-// getT3TopiaPersistenceContext().get()
|
|
| 222 |
-// )
|
|
| 223 |
-// );
|
|
| 224 |
- |
|
| 225 | 216 |
// get start dates to use
|
| 226 | 217 |
setStartDates(T3Date.getStartDates(configuration.getBeginDate(), configuration.getEndDate(), configuration.getTimeStep()));
|
| 227 | 218 |
|
| 228 |
-// // get weight categories to use (group by school type)
|
|
| 229 |
-// setWeightCategoriesBySchoolType(
|
|
| 230 |
-// weightCategoryTreatmentDAO.getWeightCategories(
|
|
| 231 |
-// ocean,
|
|
| 232 |
-// schoolTypes
|
|
| 233 |
-// )
|
|
| 234 |
-// );
|
|
| 235 |
- |
|
| 236 | 219 |
Date toBeginDate = configuration.getBeginDate().toBeginDate();
|
| 237 | 220 |
for (Ocean ocean : oceans) {
|
| 238 | 221 |
oceanContext.put(ocean.getTopiaId(), new OceanContext(
|
| ... | ... | @@ -251,9 +234,7 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 251 | 234 |
// get possible vessels for sample stratum
|
| 252 | 235 |
setPossibleSampleVessels(vesselDAO.getPossibleSampleVessels(sampleFleets, sampleFlags));
|
| 253 | 236 |
|
| 254 |
-// conversionHelper = lengthWeightConversionDAO.newConversionHelper(ocean, 0, toBeginDate);
|
|
| 255 |
- |
|
| 256 |
- stratumsResult = Sets.newLinkedHashSet();
|
|
| 237 |
+ stratumsResult = new LinkedHashSet<>();
|
|
| 257 | 238 |
|
| 258 | 239 |
topiaCreateDate = new SimpleDateFormat("yyyy-MM-dd").format(serviceContext.getCurrentDate());
|
| 259 | 240 |
|
| ... | ... | @@ -306,8 +287,6 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 306 | 287 |
super.finalizeAction();
|
| 307 | 288 |
}
|
| 308 | 289 |
|
| 309 |
-// Map<String, Integer> hitActivities = new TreeMap<>();
|
|
| 310 |
- |
|
| 311 | 290 |
@Override
|
| 312 | 291 |
protected boolean executeAction() throws Exception {
|
| 313 | 292 |
|
| ... | ... | @@ -315,88 +294,133 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 315 | 294 |
|
| 316 | 295 |
Level3Configuration configuration = getConfiguration();
|
| 317 | 296 |
|
| 318 |
- // get time step
|
|
| 319 |
- int timeStep = configuration.getTimeStep();
|
|
| 297 |
+ // keep a track of already used activity ids (to remove previous level 2 data)
|
|
| 298 |
+ Set<String> usedActivityIds = new HashSet<>();
|
|
| 320 | 299 |
|
| 321 |
-// nbStratums = zoneBySchoolType.size() * startDates.size();
|
|
| 322 |
- nbStratums = oceanContext.values().stream().mapToInt(OceanContext::sizeZones).sum() * startDates.size();
|
|
| 300 |
+ boolean useWeightCategoriesInStratum = configuration.isUseWeightCategoriesInStratum();
|
|
| 301 |
+ |
|
| 302 |
+ if (useWeightCategoriesInStratum) {
|
|
| 303 |
+ executeActionWithCategories(configuration, usedActivityIds);
|
|
| 304 |
+ } else {
|
|
| 305 |
+ executeActionWithoutCategories(configuration, usedActivityIds);
|
|
| 306 |
+ }
|
|
| 307 |
+ return true;
|
|
| 308 |
+ }
|
|
| 309 |
+ |
|
| 310 |
+ private void executeActionWithCategories(Level3Configuration configuration, Set<String> usedActivityIds) throws Exception {
|
|
| 311 |
+ |
|
| 312 |
+ nbStratums = 0;
|
|
| 313 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 314 |
+ List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType);
|
|
| 315 |
+ Collection<ZoneStratumAware> zones = getZones(schoolType);
|
|
| 316 |
+ nbStratums += startDates.size() * zones.size() * weightCategories.size();
|
|
| 317 |
+ }
|
|
| 323 | 318 |
setNbSteps(3 * nbStratums);
|
| 324 | 319 |
|
| 325 |
- // keep a track of alreay used activity ids (to remove previous level 3 data)
|
|
| 326 |
- Set<String> usedActivityIds = new HashSet<>();
|
|
| 320 |
+ int timeStep = configuration.getTimeStep();
|
|
| 327 | 321 |
|
| 328 |
- int stratumIndex = 0;
|
|
| 322 |
+ MutableInt stratumIndex = new MutableInt(1);
|
|
| 329 | 323 |
for (SchoolType schoolType : schoolTypes) {
|
| 324 |
+ Map<String, Integer> stratumMinimumCountBySpecie = stratumMinimumSampleCountBySchoolType.get(schoolType);
|
|
| 325 |
+ List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType);
|
|
| 326 |
+ Collection<ZoneStratumAware> zones = getZones(schoolType);
|
|
| 327 |
+ for (ZoneStratumAware zone : zones) {
|
|
| 328 |
+ for (WeightCategoryTreatment weightCategory : weightCategories) {
|
|
| 329 |
+ doIterateOnDates(timeStep, configuration, schoolType, zones, zone, weightCategories, weightCategory, usedActivityIds, stratumIndex, stratumMinimumCountBySpecie);
|
|
| 330 |
+ }
|
|
| 331 |
+ }
|
|
| 332 |
+ }
|
|
| 333 |
+ }
|
|
| 330 | 334 |
|
| 331 |
- // get all weight categories for this school type
|
|
| 332 |
-// List<WeightCategoryTreatment> weightCategories = Lists.newArrayList(weightCategoriesBySchoolType.get(schoolType));
|
|
| 333 |
- List<WeightCategoryTreatment> weightCategories = oceanContext.values().stream().flatMap(o -> o.getWeightCategories(schoolType).stream()).distinct().collect(Collectors.toList());
|
|
| 334 |
- weightCategoryTreatmentDAO.sort(weightCategories);
|
|
| 335 |
+ private void executeActionWithoutCategories(Level3Configuration configuration, Set<String> usedActivityIds) throws Exception {
|
|
| 335 | 336 |
|
| 336 |
- // get all zones for this school type
|
|
| 337 |
-// Collection<ZoneStratumAware> zones = zoneBySchoolType.get(schoolType);
|
|
| 338 |
- List<ZoneStratumAware> zones = oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList());
|
|
| 337 |
+ nbStratums = 0;
|
|
| 338 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 339 |
+ Collection<ZoneStratumAware> zones = getZones(schoolType);
|
|
| 340 |
+ nbStratums += startDates.size() * zones.size();
|
|
| 341 |
+ }
|
|
| 342 |
+ setNbSteps(3 * nbStratums);
|
|
| 339 | 343 |
|
| 340 |
- // get minimum stratum count by species
|
|
| 341 |
- Map<String, Integer> stratumMinimumCountBySpecie = stratumMinimumSampleCountBySchoolType.get(schoolType);
|
|
| 344 |
+ int timeStep = configuration.getTimeStep();
|
|
| 342 | 345 |
|
| 346 |
+ MutableInt stratumIndex = new MutableInt(1);
|
|
| 347 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 348 |
+ Map<String, Integer> stratumMinimumCountBySpecie = stratumMinimumSampleCountBySchoolType.get(schoolType);
|
|
| 349 |
+ List<WeightCategoryTreatment> weightCategories = getWeightCategoryTreatments(schoolType);
|
|
| 350 |
+ Collection<ZoneStratumAware> zones = getZones(schoolType);
|
|
| 343 | 351 |
for (ZoneStratumAware zone : zones) {
|
| 352 |
+ doIterateOnDates(timeStep, configuration, schoolType, zones, zone, weightCategories, null, usedActivityIds, stratumIndex, stratumMinimumCountBySpecie);
|
|
| 353 |
+ }
|
|
| 354 |
+ }
|
|
| 355 |
+ }
|
|
| 344 | 356 |
|
| 345 |
- for (T3Date startDate : startDates) {
|
|
| 346 |
- |
|
| 347 |
- // get end date (only increments on timseStep - 1 to have
|
|
| 348 |
- // exactly timstep month from beginDate.toStartDate() to
|
|
| 349 |
- // endDate.toEndDate()
|
|
| 350 |
- T3Date endDate = startDate.incrementsMonths(timeStep - 1);
|
|
| 351 |
- |
|
| 352 |
- // clear query buffer
|
|
| 353 |
- queryBuffer = new StringBuilder();
|
|
| 354 |
- nbQuery = 0;
|
|
| 355 |
- |
|
| 356 |
- StratumConfiguration<Level3Configuration>
|
|
| 357 |
- stratumConfiguration =
|
|
| 358 |
- StratumConfiguration.newStratumConfiguration(
|
|
| 359 |
- configuration,
|
|
| 360 |
- zoneMeta,
|
|
| 361 |
- zone,
|
|
| 362 |
- schoolType,
|
|
| 363 |
- startDate,
|
|
| 364 |
- endDate,
|
|
| 365 |
- zones,
|
|
| 366 |
- possibleCatchVessels,
|
|
| 367 |
- possibleSampleVessels,
|
|
| 368 |
- stratumMinimumCountBySpecie,
|
|
| 369 |
- activityCache);
|
|
| 370 |
- |
|
| 371 |
- try {
|
|
| 372 |
- L3StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds);
|
|
| 373 |
- stratumsResult.add(result);
|
|
| 374 |
- } finally {
|
|
| 375 |
- |
|
| 376 |
- // first flush delete previous level 3 data
|
|
| 377 |
- flushTransaction("Flush delete level 3 data.");
|
|
| 378 |
- |
|
| 379 |
- // flush then new data
|
|
| 380 |
- long s0 = TimeLog.getTime();
|
|
| 381 |
- if (nbQuery > 0) {
|
|
| 382 |
- if (log.isInfoEnabled()) {
|
|
| 383 |
- log.info(String.format("Will flush %d queries.", nbQuery));
|
|
| 384 |
- }
|
|
| 385 |
- getT3TopiaPersistenceContext().get().getSqlSupport().executeSql(queryBuffer.toString());
|
|
| 386 |
- }
|
|
| 387 |
- getTimeLog().log(s0, "Execute queries");
|
|
| 357 |
+ private List<WeightCategoryTreatment> getWeightCategoryTreatments(SchoolType schoolType) {
|
|
| 358 |
+ List<WeightCategoryTreatment> weightCategoryTreatments = oceanContext.values().stream().flatMap(o -> o.getWeightCategories(schoolType).stream()).distinct().collect(Collectors.toList());
|
|
| 359 |
+ weightCategoryTreatmentDAO.sort(weightCategoryTreatments);
|
|
| 360 |
+ return weightCategoryTreatments;
|
|
| 361 |
+ }
|
|
| 362 |
+ |
|
| 363 |
+ private Collection<ZoneStratumAware> getZones(SchoolType schoolType) {
|
|
| 364 |
+ return oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList());
|
|
| 365 |
+ }
|
|
| 366 |
+ |
|
| 367 |
+ private void doIterateOnDates(int timeStep, Level3Configuration configuration, SchoolType schoolType, Collection<ZoneStratumAware> zones, ZoneStratumAware zone, List<WeightCategoryTreatment> weightCategories, WeightCategoryTreatment weightCategoryTreatment, Set<String> usedActivityIds, MutableInt stratumIndex, Map<String, Integer> stratumMinimumCountBySpecie) throws Exception {
|
|
| 368 |
+ |
|
| 369 |
+ for (T3Date startDate : startDates) {
|
|
| 370 |
+ |
|
| 371 |
+ // clear query buffer
|
|
| 372 |
+ queryBuffer = new StringBuilder();
|
|
| 373 |
+ nbQuery = 0;
|
|
| 374 |
+ |
|
| 375 |
+ // get end date (only increments on timeStep - 1 to have
|
|
| 376 |
+ // exactly timeStep month from beginDate.toStartDate() to endDate.toEndDate()
|
|
| 377 |
+ T3Date endDate = startDate.incrementsMonths(timeStep - 1);
|
|
| 378 |
+ |
|
| 379 |
+ StratumConfiguration<Level3Configuration>
|
|
| 380 |
+ stratumConfiguration =
|
|
| 381 |
+ StratumConfiguration.newStratumConfiguration(
|
|
| 382 |
+ configuration,
|
|
| 383 |
+ zoneMeta,
|
|
| 384 |
+ zone,
|
|
| 385 |
+ schoolType,
|
|
| 386 |
+ weightCategoryTreatment,
|
|
| 387 |
+ startDate,
|
|
| 388 |
+ endDate,
|
|
| 389 |
+ zones,
|
|
| 390 |
+ possibleCatchVessels,
|
|
| 391 |
+ possibleSampleVessels,
|
|
| 392 |
+ stratumMinimumCountBySpecie,
|
|
| 393 |
+ activityCache
|
|
| 394 |
+ );
|
|
| 395 |
+ |
|
| 396 |
+ try {
|
|
| 397 |
+ L3StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds);
|
|
| 398 |
+ stratumsResult.add(result);
|
|
| 399 |
+ } finally {
|
|
| 400 |
+ |
|
| 401 |
+ // first flush delete previous level 3 data
|
|
| 402 |
+ flushTransaction("Flush delete level 3 data.");
|
|
| 403 |
+ |
|
| 404 |
+ // flush then new data
|
|
| 405 |
+ long s0 = TimeLog.getTime();
|
|
| 406 |
+ if (nbQuery > 0) {
|
|
| 407 |
+ if (log.isInfoEnabled()) {
|
|
| 408 |
+ log.info(String.format("Will flush %d queries.", nbQuery));
|
|
| 388 | 409 |
}
|
| 389 |
- stratumIndex++;
|
|
| 410 |
+ getT3TopiaPersistenceContext().get().getSqlSupport().executeSql(queryBuffer.toString());
|
|
| 390 | 411 |
}
|
| 412 |
+ getTimeLog().log(s0, "Execute queries");
|
|
| 391 | 413 |
}
|
| 414 |
+ |
|
| 415 |
+ stratumIndex.increment();
|
|
| 392 | 416 |
}
|
| 393 |
- return true;
|
|
| 417 |
+ |
|
| 394 | 418 |
}
|
| 395 | 419 |
|
| 396 |
- protected L3StratumResult doExecuteStratum(StratumConfiguration<Level3Configuration> conf,
|
|
| 397 |
- List<WeightCategoryTreatment> weightCategories,
|
|
| 398 |
- int stratumIndex,
|
|
| 399 |
- Set<String> usedActivityIds) throws Exception {
|
|
| 420 |
+ private L3StratumResult doExecuteStratum(StratumConfiguration<Level3Configuration> conf,
|
|
| 421 |
+ List<WeightCategoryTreatment> weightCategories,
|
|
| 422 |
+ MutableInt stratumIndex,
|
|
| 423 |
+ Set<String> usedActivityIds) throws Exception {
|
|
| 400 | 424 |
|
| 401 | 425 |
incrementsProgression();
|
| 402 | 426 |
|
| ... | ... | @@ -488,7 +512,7 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 488 | 512 |
addInfoMessage(message);
|
| 489 | 513 |
|
| 490 | 514 |
int activityIndex = 1;
|
| 491 |
- int nbActivites = catchStratum.getNbActivities();
|
|
| 515 |
+ int nbActivities = catchStratum.getNbActivities();
|
|
| 492 | 516 |
for (Map.Entry<Activity, Integer> e : catchStratum) {
|
| 493 | 517 |
|
| 494 | 518 |
Activity activity = e.getKey();
|
| ... | ... | @@ -499,13 +523,6 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 499 | 523 |
boolean newActivity = usedActivityIds.add(activity.getTopiaId());
|
| 500 | 524 |
if (!newActivity) {
|
| 501 | 525 |
Preconditions.checkState(nbZones > 1, "Only a multi-zone activity can be seen more tha once!, problem with activity: " + activity.getTopiaId());
|
| 502 |
- |
|
| 503 |
-// // mark it
|
|
| 504 |
-// Integer nb = hitActivities.get(activity.getTopiaId());
|
|
| 505 |
-// if (nb == null) {
|
|
| 506 |
-// nb = 0;
|
|
| 507 |
-// }
|
|
| 508 |
-// hitActivities.put(activity.getTopiaId(), nb + 1);
|
|
| 509 | 526 |
}
|
| 510 | 527 |
|
| 511 | 528 |
OceanContext oceanContext = this.oceanContext.get(activity.getOcean().getTopiaId());
|
| ... | ... | @@ -518,10 +535,9 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 518 | 535 |
nbZones,
|
| 519 | 536 |
activityIndex++,
|
| 520 | 537 |
weightCategories,
|
| 521 |
- nbActivites,
|
|
| 538 |
+ nbActivities,
|
|
| 522 | 539 |
newActivity,
|
| 523 |
- result.getTotalFishesCount()
|
|
| 524 |
- );
|
|
| 540 |
+ result.getTotalFishesCount());
|
|
| 525 | 541 |
|
| 526 | 542 |
// keep the stratum substitution level in the activity
|
| 527 | 543 |
activity.setStratumLevelN3(level);
|
| ... | ... | @@ -554,8 +570,7 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 554 | 570 |
l(locale, "t3.level3.catchStratum.nbFishesResume.title"),
|
| 555 | 571 |
totalFishesCountModel.extractForSpecies(species),
|
| 556 | 572 |
BEFORE_LEVEL3,
|
| 557 |
- AFTER_LEVEL3
|
|
| 558 |
- );
|
|
| 573 |
+ AFTER_LEVEL3);
|
|
| 559 | 574 |
|
| 560 | 575 |
if (log.isInfoEnabled()) {
|
| 561 | 576 |
log.info(message);
|
| ... | ... | @@ -584,42 +599,32 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 584 | 599 |
totalFishesCountModel.addValues(AFTER_LEVEL3, activity.getExtrapolatedAllSetSpeciesFrequency());
|
| 585 | 600 |
}
|
| 586 | 601 |
|
| 587 |
- protected void doExecuteActivityInCatchStratum(L3CatchStratum catchStratum,
|
|
| 588 |
- L3SampleStratum sampleStratum,
|
|
| 589 |
- Activity activity,
|
|
| 590 |
- OceanContext oceanContext,
|
|
| 591 |
- int nbZones,
|
|
| 592 |
- int activityIndex,
|
|
| 593 |
- List<WeightCategoryTreatment> weightCategories,
|
|
| 594 |
- int nbActivites,
|
|
| 595 |
- boolean deleteOldData,
|
|
| 596 |
- SpeciesCountAggregateModel totalFishesCount) throws TopiaException {
|
|
| 602 |
+ private void doExecuteActivityInCatchStratum(L3CatchStratum catchStratum,
|
|
| 603 |
+ L3SampleStratum sampleStratum,
|
|
| 604 |
+ Activity activity,
|
|
| 605 |
+ OceanContext oceanContext,
|
|
| 606 |
+ int nbZones,
|
|
| 607 |
+ int activityIndex,
|
|
| 608 |
+ List<WeightCategoryTreatment> weightCategories,
|
|
| 609 |
+ int nbActivities,
|
|
| 610 |
+ boolean deleteOldData,
|
|
| 611 |
+ SpeciesCountAggregateModel totalFishesCount) throws TopiaException {
|
|
| 597 | 612 |
|
| 598 | 613 |
String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID));
|
| 599 | 614 |
|
| 600 |
- String message = l(locale, "t3.level3.message.start.activity", activityIndex, nbActivites, activityStr, nbZones);
|
|
| 615 |
+ String message = l(locale, "t3.level3.message.start.activity", activityIndex, nbActivities, activityStr, nbZones);
|
|
| 601 | 616 |
if (log.isInfoEnabled()) {
|
| 602 | 617 |
log.info(message);
|
| 603 | 618 |
}
|
| 604 | 619 |
addInfoMessage(message);
|
| 605 | 620 |
|
| 606 |
- // to deal with muli-zone activities (must keep a track of what was
|
|
| 607 |
- // already odne)
|
|
| 621 |
+ // to deal with multiple-zone activities (must keep a track of what was already done)
|
|
| 608 | 622 |
Map<String, String> previousValues;
|
| 609 | 623 |
|
| 610 | 624 |
boolean activityMultiZone = nbZones > 1;
|
| 611 | 625 |
|
| 612 | 626 |
if (activityMultiZone) {
|
| 613 |
- |
|
| 614 |
- // get previous values
|
|
| 615 |
- previousValues = activityWithMultiZones.get(activity.getTopiaId());
|
|
| 616 |
- |
|
| 617 |
- if (previousValues == null) {
|
|
| 618 |
- |
|
| 619 |
- // create previous values
|
|
| 620 |
- activityWithMultiZones.put(activity.getTopiaId(), previousValues = new HashMap<>());
|
|
| 621 |
- }
|
|
| 622 |
- |
|
| 627 |
+ previousValues = activityWithMultiZones.computeIfAbsent(activity.getTopiaId(), k -> new HashMap<>());
|
|
| 623 | 628 |
} else {
|
| 624 | 629 |
previousValues = null;
|
| 625 | 630 |
}
|
| ... | ... | @@ -630,7 +635,6 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 630 | 635 |
if (log.isDebugEnabled()) {
|
| 631 | 636 |
log.debug(String.format("Delete previous level3 data of %s :: %d", activity.getTopiaId(), activity.sizeExtrapolatedAllSetSpeciesFrequency()));
|
| 632 | 637 |
}
|
| 633 |
-// addDeleteQuery(activity);
|
|
| 634 | 638 |
activity.deleteComputedDataLevel3();
|
| 635 | 639 |
}
|
| 636 | 640 |
|
| ... | ... | @@ -673,7 +677,6 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 673 | 677 |
message = l(locale, "t3.level3.message.activity.with.no.sample.useSampleStratum.composition", activityStr);
|
| 674 | 678 |
}
|
| 675 | 679 |
|
| 676 |
- |
|
| 677 | 680 |
if (log.isInfoEnabled()) {
|
| 678 | 681 |
log.info(message);
|
| 679 | 682 |
}
|
| ... | ... | @@ -766,13 +769,13 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 766 | 769 |
}
|
| 767 | 770 |
}
|
| 768 | 771 |
|
| 769 |
- protected void generateFrequencies(Activity activity,
|
|
| 770 |
- Species aSpecies,
|
|
| 771 |
- Map<String, String> previousValues,
|
|
| 772 |
- LengthCompositionModel model,
|
|
| 773 |
- float totalWeight,
|
|
| 774 |
- SpeciesCountModel speciesCountModel,
|
|
| 775 |
- LengthWeightConversion conversions) {
|
|
| 772 |
+ private void generateFrequencies(Activity activity,
|
|
| 773 |
+ Species aSpecies,
|
|
| 774 |
+ Map<String, String> previousValues,
|
|
| 775 |
+ LengthCompositionModel model,
|
|
| 776 |
+ float totalWeight,
|
|
| 777 |
+ SpeciesCountModel speciesCountModel,
|
|
| 778 |
+ LengthWeightConversion conversions) {
|
|
| 776 | 779 |
|
| 777 | 780 |
// get all length classes involved
|
| 778 | 781 |
Set<Integer> lengthClasses = model.getLengthClasses();
|
| ... | ... | @@ -803,8 +806,8 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 803 | 806 |
|
| 804 | 807 |
}
|
| 805 | 808 |
|
| 806 |
- protected L3CatchStratum newCatchStratum(StratumConfiguration<Level3Configuration> stratumConfiguration,
|
|
| 807 |
- List<WeightCategoryTreatment> weightCategories) throws Exception {
|
|
| 809 |
+ private L3CatchStratum newCatchStratum(StratumConfiguration<Level3Configuration> stratumConfiguration,
|
|
| 810 |
+ List<WeightCategoryTreatment> weightCategories) throws Exception {
|
|
| 808 | 811 |
L3CatchStratum catchStratum = new L3CatchStratum(stratumConfiguration, species, speciesToFixFilter);
|
| 809 | 812 |
catchStratum.init(serviceContext, weightCategories, this);
|
| 810 | 813 |
// get the total weight of the catch stratum
|
| ... | ... | @@ -833,10 +836,10 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 833 | 836 |
return catchStratum;
|
| 834 | 837 |
}
|
| 835 | 838 |
|
| 836 |
- protected L3SampleStratum newSampleStratum(StratumConfiguration<Level3Configuration> stratumConfiguration,
|
|
| 837 |
- List<WeightCategoryTreatment> weightCategories,
|
|
| 838 |
- float totalCatchWeight,
|
|
| 839 |
- LengthWeightConversionHelper conversionHelper) throws Exception {
|
|
| 839 |
+ private L3SampleStratum newSampleStratum(StratumConfiguration<Level3Configuration> stratumConfiguration,
|
|
| 840 |
+ List<WeightCategoryTreatment> weightCategories,
|
|
| 841 |
+ float totalCatchWeight,
|
|
| 842 |
+ LengthWeightConversionHelper conversionHelper) throws Exception {
|
|
| 840 | 843 |
L3SampleStratum sampleStratum =
|
| 841 | 844 |
new L3SampleStratum(stratumConfiguration,
|
| 842 | 845 |
species,
|
| ... | ... | @@ -847,26 +850,13 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 847 | 850 |
return sampleStratum;
|
| 848 | 851 |
}
|
| 849 | 852 |
|
| 850 |
- protected void addInsertOrUpdateQuery(Activity activity,
|
|
| 851 |
- Map<String, String> previousValues,
|
|
| 852 |
- Species species,
|
|
| 853 |
- int lengthClass,
|
|
| 854 |
- float number,
|
|
| 855 |
- SpeciesCountModel speciesCountModel) {
|
|
| 853 |
+ private void addInsertOrUpdateQuery(Activity activity, Map<String, String> previousValues, Species species, int lengthClass, float number, SpeciesCountModel speciesCountModel) {
|
|
| 856 | 854 |
|
| 857 | 855 |
String key = species.getTopiaId() + "__" + lengthClass;
|
| 858 | 856 |
String oldId = previousValues == null ? null : previousValues.get(key);
|
| 859 | 857 |
String query;
|
| 860 | 858 |
if (oldId == null) {
|
| 861 | 859 |
|
| 862 |
- // check unique key
|
|
| 863 |
- String uniqueKey = activity.getTopiaId() + "__" + key;
|
|
| 864 |
- |
|
| 865 |
-// if (!insertCache.add(uniqueKey)) {
|
|
| 866 |
-//
|
|
| 867 |
-// // key already used!!!
|
|
| 868 |
-// throw new IllegalStateException("Tuple (" + uniqueKey + ") already used!");
|
|
| 869 |
-// }
|
|
| 870 | 860 |
// insert query
|
| 871 | 861 |
TopiaIdFactory topiaIdFactory = getActionContext().getApplicationContext().getConfiguration().getTopiaIdFactory();
|
| 872 | 862 |
String newId = topiaIdFactory.newTopiaId(ExtrapolatedAllSetSpeciesFrequency.class, "" + System.nanoTime());
|
| ... | ... | @@ -906,10 +896,6 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 906 | 896 |
this.schoolTypes = schoolTypes;
|
| 907 | 897 |
}
|
| 908 | 898 |
|
| 909 |
-// public void setZoneBySchoolType(Multimap<SchoolType, ZoneStratumAware> zoneBySchoolType) {
|
|
| 910 |
-// this.zoneBySchoolType = zoneBySchoolType;
|
|
| 911 |
-// }
|
|
| 912 |
- |
|
| 913 | 899 |
public void setSpecies(Set<Species> species) {
|
| 914 | 900 |
this.species = species;
|
| 915 | 901 |
}
|
| ... | ... | @@ -918,10 +904,6 @@ public class Level3Action extends T3Action<Level3Configuration> { |
| 918 | 904 |
this.startDates = startDates;
|
| 919 | 905 |
}
|
| 920 | 906 |
|
| 921 |
-// public void setWeightCategoriesBySchoolType(Multimap<SchoolType, WeightCategoryTreatment> weightCategoriesBySchoolType) {
|
|
| 922 |
-// this.weightCategoriesBySchoolType = weightCategoriesBySchoolType;
|
|
| 923 |
-// }
|
|
| 924 |
- |
|
| 925 | 907 |
public void setPossibleCatchVessels(Set<Vessel> possibleCatchVessels) {
|
| 926 | 908 |
this.possibleCatchVessels = possibleCatchVessels;
|
| 927 | 909 |
}
|
| ... | ... | @@ -46,13 +46,12 @@ import java.util.Set; |
| 46 | 46 |
public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends T3Action<C>> implements Closeable, Iterable<Map.Entry<Activity, Integer>> {
|
| 47 | 47 |
|
| 48 | 48 |
/**
|
| 49 |
- * All activities selected for this stratum, with for catch satratum the
|
|
| 50 |
- * number of zones where the activty should be used.
|
|
| 49 |
+ * All activities selected for this stratum, with for catch stratum the number of zones where the activity should be used.
|
|
| 51 | 50 |
* <p/>
|
| 52 | 51 |
* see http://forge.codelutin.com/issues/1935
|
| 53 | 52 |
* <p/>
|
| 54 | 53 |
* <strong>Note:</strong> This data are available after invocation of method
|
| 55 |
- * {@link Stratum#init(T3ServiceContext, List, T3Action}.
|
|
| 54 |
+ * {@link Stratum#init(T3ServiceContext, List, T3Action)}.
|
|
| 56 | 55 |
*/
|
| 57 | 56 |
private Map<Activity, Integer> activities;
|
| 58 | 57 |
|
| ... | ... | @@ -85,8 +84,7 @@ public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends |
| 85 | 84 |
return activities.entrySet().iterator();
|
| 86 | 85 |
}
|
| 87 | 86 |
|
| 88 |
- protected Stratum(StratumConfiguration<C> configuration,
|
|
| 89 |
- Collection<Species> speciesToFix) {
|
|
| 87 |
+ protected Stratum(StratumConfiguration<C> configuration, Collection<Species> speciesToFix) {
|
|
| 90 | 88 |
this.configuration = configuration;
|
| 91 | 89 |
this.speciesToFix = ImmutableSet.copyOf(speciesToFix);
|
| 92 | 90 |
}
|
| ... | ... | @@ -130,9 +128,7 @@ public abstract class Stratum<C extends LevelConfigurationWithStratum, A extends |
| 130 | 128 |
|
| 131 | 129 |
protected void checkInitMethodInvoked(Object data) {
|
| 132 | 130 |
if (data == null) {
|
| 133 |
- throw new IllegalStateException(
|
|
| 134 |
- "You must invoke the #init(tx) method before accessing " +
|
|
| 135 |
- "stratum data.");
|
|
| 131 |
+ throw new IllegalStateException("You must invoke the #init(tx) method before accessing stratum data.");
|
|
| 136 | 132 |
}
|
| 137 | 133 |
}
|
| 138 | 134 |
}
|
| ... | ... | @@ -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,9 +24,11 @@ import com.google.common.cache.LoadingCache; |
| 24 | 24 |
import fr.ird.t3.entities.data.Activity;
|
| 25 | 25 |
import fr.ird.t3.entities.reference.SchoolType;
|
| 26 | 26 |
import fr.ird.t3.entities.reference.Vessel;
|
| 27 |
+import fr.ird.t3.entities.reference.WeightCategoryTreatment;
|
|
| 27 | 28 |
import fr.ird.t3.entities.reference.zone.ZoneStratumAware;
|
| 28 | 29 |
import fr.ird.t3.entities.reference.zone.ZoneStratumAwareMeta;
|
| 29 | 30 |
import fr.ird.t3.entities.type.T3Date;
|
| 31 |
+ |
|
| 30 | 32 |
import java.util.Collection;
|
| 31 | 33 |
import java.util.Iterator;
|
| 32 | 34 |
import java.util.Map;
|
| ... | ... | @@ -41,33 +43,68 @@ import java.util.concurrent.ExecutionException; |
| 41 | 43 |
*/
|
| 42 | 44 |
public class StratumConfiguration<C extends LevelConfigurationWithStratum> {
|
| 43 | 45 |
|
| 46 |
+ private final C configuration;
|
|
| 47 |
+ private final Collection<ZoneStratumAware> zones;
|
|
| 48 |
+ private final ZoneStratumAwareMeta zoneMeta;
|
|
| 49 |
+ private final ZoneStratumAware zone;
|
|
| 50 |
+ private final SchoolType schoolType;
|
|
| 51 |
+ private final WeightCategoryTreatment weightCategoryTreatment;
|
|
| 52 |
+ private final T3Date beginDate;
|
|
| 53 |
+ private final T3Date endDate;
|
|
| 54 |
+ private final Set<Vessel> possibleCatchVessels;
|
|
| 55 |
+ private final Set<Vessel> possibleSampleVessels;
|
|
| 56 |
+ private final Map<String, Integer> stratumMinimumCountBySpecie;
|
|
| 57 |
+ private final LoadingCache<String, Activity> activityCache;
|
|
| 58 |
+ private String[] zoneIds;
|
|
| 59 |
+ |
|
| 60 |
+ protected StratumConfiguration(C configuration,
|
|
| 61 |
+ ZoneStratumAwareMeta zoneMeta,
|
|
| 62 |
+ ZoneStratumAware zone,
|
|
| 63 |
+ SchoolType schoolType,
|
|
| 64 |
+ WeightCategoryTreatment weightCategoryTreatment, T3Date beginDate,
|
|
| 65 |
+ T3Date endDate,
|
|
| 66 |
+ Collection<ZoneStratumAware> zones,
|
|
| 67 |
+ Set<Vessel> possibleCatchVessels,
|
|
| 68 |
+ Set<Vessel> possibleSampleVessels,
|
|
| 69 |
+ Map<String, Integer> stratumMinimumCountBySpecie,
|
|
| 70 |
+ LoadingCache<String, Activity> activityCache) {
|
|
| 71 |
+ this.configuration = configuration;
|
|
| 72 |
+ this.zoneMeta = zoneMeta;
|
|
| 73 |
+ this.zone = zone;
|
|
| 74 |
+ this.schoolType = schoolType;
|
|
| 75 |
+ this.weightCategoryTreatment = weightCategoryTreatment;
|
|
| 76 |
+ this.beginDate = beginDate;
|
|
| 77 |
+ this.endDate = endDate;
|
|
| 78 |
+ this.zones = zones;
|
|
| 79 |
+ this.possibleCatchVessels = possibleCatchVessels;
|
|
| 80 |
+ this.possibleSampleVessels = possibleSampleVessels;
|
|
| 81 |
+ this.stratumMinimumCountBySpecie = stratumMinimumCountBySpecie;
|
|
| 82 |
+ this.activityCache = activityCache;
|
|
| 83 |
+ }
|
|
| 84 |
+ |
|
| 44 | 85 |
/**
|
| 45 | 86 |
* Obtain a new stratum configuration given all his parameters.
|
| 46 | 87 |
*
|
| 88 |
+ * @param <C> type of configuration
|
|
| 47 | 89 |
* @param conf the level action configuration
|
| 48 | 90 |
* @param zoneMeta type of zone to use
|
| 49 | 91 |
* @param zone the zone of the stratum
|
| 50 | 92 |
* @param schoolType the school type of the stratum
|
| 93 |
+ * @param weightCategoryTreatment the weight category of the stratum (not nul only if {@link LevelConfigurationWithStratum#isUseWeightCategoriesInStratum()} is {@code true}.
|
|
| 51 | 94 |
* @param startDate the start date of the stratum
|
| 52 | 95 |
* @param endDate the end date of the stratum
|
| 53 |
- * @param zones all the zones useables by the level
|
|
| 54 |
- * action which used this stratum (can
|
|
| 55 |
- * be used for sample stratum substitution)
|
|
| 56 |
- * @param possibleCatchVessels set of possible vessels to use when
|
|
| 57 |
- * selecting data in the catch stratum
|
|
| 58 |
- * @param possibleSampleVessels set of possible vessels to use when
|
|
| 59 |
- * selecting data in the sample stratum
|
|
| 60 |
- * @param stratumMinimumCountBySpecie minimum sample count needed by species
|
|
| 61 |
- * for sample stratum substitution
|
|
| 62 |
- * @param <C> type of configuration
|
|
| 63 |
- * @return the new instanciated stratum configuration
|
|
| 96 |
+ * @param zones all the zones useable by the level action which used this stratum (can be used for sample stratum substitution)
|
|
| 97 |
+ * @param possibleCatchVessels set of possible vessels to use when selecting data in the catch stratum
|
|
| 98 |
+ * @param possibleSampleVessels set of possible vessels to use when selecting data in the sample stratum
|
|
| 99 |
+ * @param stratumMinimumCountBySpecie minimum sample count needed by species for sample stratum substitution
|
|
| 100 |
+ * @return the new instantiated stratum configuration
|
|
| 64 | 101 |
*/
|
| 65 | 102 |
public static <C extends LevelConfigurationWithStratum> StratumConfiguration<C> newStratumConfiguration(
|
| 66 | 103 |
C conf,
|
| 67 | 104 |
ZoneStratumAwareMeta zoneMeta,
|
| 68 | 105 |
ZoneStratumAware zone,
|
| 69 | 106 |
SchoolType schoolType,
|
| 70 |
- T3Date startDate,
|
|
| 107 |
+ WeightCategoryTreatment weightCategoryTreatment, T3Date startDate,
|
|
| 71 | 108 |
T3Date endDate,
|
| 72 | 109 |
Collection<ZoneStratumAware> zones,
|
| 73 | 110 |
Set<Vessel> possibleCatchVessels,
|
| ... | ... | @@ -75,11 +112,12 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { |
| 75 | 112 |
Map<String, Integer> stratumMinimumCountBySpecie,
|
| 76 | 113 |
LoadingCache<String, Activity> activityCache) {
|
| 77 | 114 |
|
| 78 |
- return new StratumConfiguration<C>(
|
|
| 115 |
+ return new StratumConfiguration<>(
|
|
| 79 | 116 |
conf,
|
| 80 | 117 |
zoneMeta,
|
| 81 | 118 |
zone,
|
| 82 | 119 |
schoolType,
|
| 120 |
+ weightCategoryTreatment,
|
|
| 83 | 121 |
startDate,
|
| 84 | 122 |
endDate,
|
| 85 | 123 |
zones,
|
| ... | ... | @@ -89,54 +127,6 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { |
| 89 | 127 |
activityCache);
|
| 90 | 128 |
}
|
| 91 | 129 |
|
| 92 |
- private final C configuration;
|
|
| 93 |
- |
|
| 94 |
- private final ZoneStratumAwareMeta zoneMeta;
|
|
| 95 |
- |
|
| 96 |
- private final ZoneStratumAware zone;
|
|
| 97 |
- |
|
| 98 |
- private final Collection<ZoneStratumAware> zones;
|
|
| 99 |
- |
|
| 100 |
- private String[] zoneIds;
|
|
| 101 |
- |
|
| 102 |
- private final SchoolType schoolType;
|
|
| 103 |
- |
|
| 104 |
- private final T3Date beginDate;
|
|
| 105 |
- |
|
| 106 |
- private final T3Date endDate;
|
|
| 107 |
- |
|
| 108 |
- private final Set<Vessel> possibleCatchVessels;
|
|
| 109 |
- |
|
| 110 |
- private final Set<Vessel> possibleSampleVessels;
|
|
| 111 |
- |
|
| 112 |
- private final Map<String, Integer> stratumMinimumCountBySpecie;
|
|
| 113 |
- |
|
| 114 |
- private final LoadingCache<String, Activity> activityCache;
|
|
| 115 |
- |
|
| 116 |
- protected StratumConfiguration(C configuration,
|
|
| 117 |
- ZoneStratumAwareMeta zoneMeta,
|
|
| 118 |
- ZoneStratumAware zone,
|
|
| 119 |
- SchoolType schoolType,
|
|
| 120 |
- T3Date beginDate,
|
|
| 121 |
- T3Date endDate,
|
|
| 122 |
- Collection<ZoneStratumAware> zones,
|
|
| 123 |
- Set<Vessel> possibleCatchVessels,
|
|
| 124 |
- Set<Vessel> possibleSampleVessels,
|
|
| 125 |
- Map<String, Integer> stratumMinimumCountBySpecie,
|
|
| 126 |
- LoadingCache<String, Activity> activityCache) {
|
|
| 127 |
- this.configuration = configuration;
|
|
| 128 |
- this.zoneMeta = zoneMeta;
|
|
| 129 |
- this.zone = zone;
|
|
| 130 |
- this.schoolType = schoolType;
|
|
| 131 |
- this.beginDate = beginDate;
|
|
| 132 |
- this.endDate = endDate;
|
|
| 133 |
- this.zones = zones;
|
|
| 134 |
- this.possibleCatchVessels = possibleCatchVessels;
|
|
| 135 |
- this.possibleSampleVessels = possibleSampleVessels;
|
|
| 136 |
- this.stratumMinimumCountBySpecie = stratumMinimumCountBySpecie;
|
|
| 137 |
- this.activityCache = activityCache;
|
|
| 138 |
- }
|
|
| 139 |
- |
|
| 140 | 130 |
public C getConfiguration() {
|
| 141 | 131 |
return configuration;
|
| 142 | 132 |
}
|
| ... | ... | @@ -181,6 +171,10 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { |
| 181 | 171 |
return stratumMinimumCountBySpecie;
|
| 182 | 172 |
}
|
| 183 | 173 |
|
| 174 |
+ public WeightCategoryTreatment getWeightCategoryTreatment() {
|
|
| 175 |
+ return weightCategoryTreatment;
|
|
| 176 |
+ }
|
|
| 177 |
+ |
|
| 184 | 178 |
public String[] getZoneIds() {
|
| 185 | 179 |
if (zoneIds == null) {
|
| 186 | 180 |
Collection<ZoneStratumAware> allZones = getZones();
|
| ... | ... | @@ -204,8 +198,6 @@ public class StratumConfiguration<C extends LevelConfigurationWithStratum> { |
| 204 | 198 |
|
| 205 | 199 |
@Override
|
| 206 | 200 |
public String toString() {
|
| 207 |
- return super.toString() + " [schooltype: " + schoolType.getLabel1() +
|
|
| 208 |
- ", zone: " + zone.getTopiaId() + ", startDate:" +
|
|
| 209 |
- beginDate + ", endDate:" + endDate + "]";
|
|
| 201 |
+ return String.format("%s [schoolType: %s, zone: %s, startDate:%s, endDate:%s, weightCategory: %s]", super.toString(), schoolType.getLabel1(), zone.getTopiaId(), beginDate, endDate, weightCategoryTreatment);
|
|
| 210 | 202 |
}
|
| 211 | 203 |
}
|