Skip to content

Commit

Permalink
Fix U17F >81 vs U20F 87 || U20F >87
Browse files Browse the repository at this point in the history
  • Loading branch information
jflamy committed Jul 21, 2023
1 parent 5a84820 commit 7ef3db5
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 1,121 deletions.
43 changes: 19 additions & 24 deletions owlcms/src/main/java/app/owlcms/data/athlete/Athlete.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,46 +546,37 @@ public void computeMainAndEligibleCategories() {
Double weight = this.getBodyWeight();
Integer age = this.getAge();
if (weight == null || weight < 0.01) {
// logger.trace("no weight {}", this.getShortName());
Double presumedBodyWeight = this.getPresumedBodyWeight();
// logger.trace("presumed weight {} {} {}",this.getShortName(), presumedBodyWeight, this.getCategory());
if (presumedBodyWeight != null) {
weight = presumedBodyWeight - 0.01D;
if (age == null || age == 0) {

// try to set category to match sheet, with coherent eligibles
if (this.category != null) {
age = category.getAgeGroup().getMaxAge();
}
}

List<Category> categories = CategoryRepository.findByGenderAgeBW(
this.getGender(), age, weight);

categories = categories.stream()
.filter(c -> this.getQualifyingTotal() >= c.getQualifyingTotal()).collect(Collectors.toList());
// logger.trace("{} presumed weight {} age {} {} {}",this.getShortName(), presumedBodyWeight, age, this.getCategory(), categories);
// List<Category> categories = CategoryRepository.findByGenderAgeBW(
// this.getGender(), age, weight);
// categories = categories.stream()
// .filter(c -> this.getQualifyingTotal() >= c.getQualifyingTotal()).collect(Collectors.toList());
List<Category> categories = CategoryRepository.doFindEligibleCategories(this, gender, age, weight, qualifyingTotal);
setEligibles(this, categories);
logger.warn("&&&&1 {} {} {}",this.getShortName(), weight, categories);
this.setCategory(bestMatch(categories));

// logger.trace("{} {} gender {} age {} weight {} category *{}* categories {}", this.getId(), this.getShortName(), this.getGender(), this.getAge(), weight, this.getCategory(), categories);

}
} else {
// logger.trace("weight {}", this.getShortName());
List<Category> categories = CategoryRepository.findByGenderAgeBW(
this.getGender(), age, weight);
categories = categories.stream()
// .peek((c) -> {
// logger.trace("a {} aq {} cq {}", this.getShortName(), this.getQualifyingTotal(),
// c.getQualifyingTotal());
// })
.filter(c -> this.getQualifyingTotal() >= c.getQualifyingTotal()).collect(Collectors.toList());
// List<Category> categories = CategoryRepository.findByGenderAgeBW(
// this.getGender(), age, weight);
// categories = categories.stream()
// .filter(c -> this.getQualifyingTotal() >= c.getQualifyingTotal()).collect(Collectors.toList());
List<Category> categories = CategoryRepository.doFindEligibleCategories(this, gender, age, weight, qualifyingTotal);
setEligibles(this, categories);
logger.warn("&&&&2 {} {} {}",this.getShortName(), weight, categories);
this.setCategory(bestMatch(categories));
}
}


/**
* used for jury overrides and for testing
*
Expand Down Expand Up @@ -3353,13 +3344,16 @@ public void setCustomScore(Double customScore) {
}

public void setEligibleCategories(Set<Category> newEligibles) {


List<Participation> participations2 = getParticipations();

Set<String> membershipCategories = participations2.stream().filter(p -> p.getTeamMember())
.map(p -> p.getCategory().getCode()).collect(Collectors.toSet());
logger.trace("athlete memberships {}", membershipCategories);
logger.warn("athlete memberships {}", membershipCategories);

Set<Category> oldEligibles = getEligibleCategories();
logger.trace("setting eligible before:{} target:{}", oldEligibles, newEligibles);
logger.warn("setting eligible before:{} target:{}", oldEligibles, newEligibles);
if (oldEligibles != null) {
for (Category cat : oldEligibles) {
removeEligibleCategory(cat);
Expand Down Expand Up @@ -3504,6 +3498,7 @@ public void setNextAttemptRequestedWeight(Integer i) {
}

public void setParticipations(List<Participation> participations) {
logger.warn("setParticipations {}",LoggerUtils.stackTrace());
this.participations = participations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
package app.owlcms.data.category;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.slf4j.LoggerFactory;

import app.owlcms.data.agegroup.AgeGroup;
import app.owlcms.data.athlete.Athlete;
import app.owlcms.data.athlete.Gender;
import app.owlcms.data.jpa.JPAService;
import app.owlcms.utils.LoggerUtils;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;

Expand Down Expand Up @@ -171,6 +175,7 @@ public static List<Category> findByGenderAgeBW(Gender gender, Integer age, Doubl
// also before SR (MASTERS, then
// U, then IWF/other)
findFiltered.sort(new RegistrationPreferenceComparator());
logger.warn("calling findByGenderAgeBW from {}",LoggerUtils.whereFrom());
return findFiltered;
}

Expand Down Expand Up @@ -358,4 +363,28 @@ private static void setFilteringParameters(String name, Gender gender, AgeDivisi
}
}

public static List<Category> doFindEligibleCategories(Athlete a, Gender gender, Integer ageFromFields, Double bw,
int qualifyingTotal) {
List<Category> allEligible = CategoryRepository.findByGenderAgeBW(gender, ageFromFields, bw);

// if youth F >81, athlete may be jr87 or jr>87
if ((bw == null || bw > 998) && !allEligible.isEmpty()) {
double bodyWeight = allEligible.get(0).getMinimumWeight() + 1;
List<Category> otherEligibles = CategoryRepository.findByGenderAgeBW(gender, ageFromFields, bodyWeight);
HashSet<Category> allEligibleSet = new HashSet<Category>(allEligible);
for (Category otherEligible : otherEligibles) {
if (!otherEligible.sameAsAny(allEligibleSet)) {
allEligible.add(otherEligible);
}
}
allEligible.sort(new RegistrationPreferenceComparator());
}
logger.warn("****A {} bw={} {}", a, bw, allEligible);
allEligible = allEligible.stream()
.filter(c -> (qualifyingTotal >= c.getQualifyingTotal())
|| bw == null || (bw > c.getMinimumWeight() && bw <= c.getMaximumWeight()))
.collect(Collectors.toList());
logger.warn("****B {} bw={} {}", a, bw, allEligible);
return allEligible;
}
}
11 changes: 5 additions & 6 deletions owlcms/src/main/java/app/owlcms/nui/lifting/WeighinContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import app.owlcms.nui.crudui.OwlcmsCrudFormFactory;
import app.owlcms.nui.crudui.OwlcmsCrudGrid;
import app.owlcms.nui.crudui.OwlcmsGridLayout;
import app.owlcms.nui.shared.AthleteRegistrationFormFactory;
import app.owlcms.nui.shared.NAthleteRegistrationFormFactory;
import app.owlcms.nui.shared.OwlcmsContent;
import app.owlcms.nui.shared.OwlcmsLayout;
Expand Down Expand Up @@ -610,14 +609,14 @@ private void updateURLLocation(UI ui, Location location, Group newGroup) {
*/
protected OwlcmsCrudFormFactory<Athlete> createFormFactory() {
OwlcmsCrudFormFactory<Athlete> athleteEditingFormFactory;
if (Config.getCurrent().featureSwitch("oldAthleteForm")) {
athleteEditingFormFactory = new AthleteRegistrationFormFactory(Athlete.class,
currentGroup);
} else {
// if (Config.getCurrent().featureSwitch("oldAthleteForm")) {
// athleteEditingFormFactory = new AthleteRegistrationFormFactory(Athlete.class,
// currentGroup);
// } else {
athleteEditingFormFactory = new NAthleteRegistrationFormFactory(Athlete.class,
currentGroup);

}
// }
// logger.trace("created form factory {} {}",
// System.identityHashCode(athleteEditingFormFactory), currentGroup);
createFormLayout(athleteEditingFormFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import app.owlcms.nui.crudui.OwlcmsCrudFormFactory;
import app.owlcms.nui.crudui.OwlcmsCrudGrid;
import app.owlcms.nui.crudui.OwlcmsGridLayout;
import app.owlcms.nui.shared.AthleteRegistrationFormFactory;
import app.owlcms.nui.shared.NAthleteRegistrationFormFactory;
import app.owlcms.nui.shared.OwlcmsContent;
import app.owlcms.nui.shared.OwlcmsLayout;
Expand Down Expand Up @@ -584,13 +583,13 @@ private void updateURLLocation(UI ui, Location location, Group newGroup) {
*/
protected OwlcmsCrudFormFactory<Athlete> createFormFactory() {
OwlcmsCrudFormFactory<Athlete> athleteEditingFormFactory;
if (Config.getCurrent().featureSwitch("oldAthleteForm")) {
athleteEditingFormFactory = new AthleteRegistrationFormFactory(Athlete.class,
currentGroup);
} else {
// if (Config.getCurrent().featureSwitch("oldAthleteForm")) {
// athleteEditingFormFactory = new AthleteRegistrationFormFactory(Athlete.class,
// currentGroup);
// } else {
athleteEditingFormFactory = new NAthleteRegistrationFormFactory(Athlete.class,
currentGroup);
}
// }
createFormLayout(athleteEditingFormFactory);
return athleteEditingFormFactory;
}
Expand Down
Loading

0 comments on commit 7ef3db5

Please sign in to comment.