Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
-
00d3c99d
by Tony CHEMIT at 2018-03-20T14:37:44Z
3 changed files:
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetAction.java
- t3-domain/src/main/java/fr/ird/t3/entities/reference/LengthWeightConversionHelper.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) {
|
| ... | ... | @@ -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));
|
| ... | ... | @@ -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);
|