Compare commits
No commits in common. "952300d063a7902725ce762c0e385dd61772e1be" and "4c260b86b9c15e3aaa11dab9e7886bac6a9008ba" have entirely different histories.
952300d063
...
4c260b86b9
@ -1,18 +1,17 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
@ -28,14 +27,7 @@ public class CardModel {
|
||||
Long comb;
|
||||
Long match;
|
||||
Long category;
|
||||
|
||||
@JsonIgnore
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "competition", referencedColumnName = "id")
|
||||
CompetitionModel competition;
|
||||
|
||||
@JsonProperty("competition")
|
||||
Long competitionId;
|
||||
Long competition;
|
||||
|
||||
CardType type;
|
||||
String reason;
|
||||
@ -45,16 +37,6 @@ public class CardModel {
|
||||
@Column(nullable = false, columnDefinition = "boolean default false")
|
||||
boolean teamCard = false;
|
||||
|
||||
public boolean hasEffect(MatchModel match) {
|
||||
return switch (this.type) {
|
||||
case BLUE -> false;
|
||||
case YELLOW -> Objects.equals(this.match, match.getId());
|
||||
case RED -> Objects.equals(this.category, match.getCategory().getId())
|
||||
|| Objects.equals(this.match, match.getId());
|
||||
case BLACK -> true;
|
||||
};
|
||||
}
|
||||
|
||||
public enum CardType {
|
||||
BLUE,
|
||||
YELLOW,
|
||||
|
||||
@ -1,176 +0,0 @@
|
||||
package fr.titionfire.ffsaf.domain.entity;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.*;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RegisterForReflection
|
||||
public class MatchModelExtend {
|
||||
final MatchModel match;
|
||||
|
||||
@Getter
|
||||
boolean isEnd = false;
|
||||
@Getter
|
||||
List<ScoreEmbeddable> scoresToPrint = new ArrayList<>();
|
||||
@Getter
|
||||
List<ScoreEmbeddable> scoresToCompute = new ArrayList<>();
|
||||
@Getter
|
||||
int win = 0;
|
||||
|
||||
|
||||
public MatchModelExtend(MatchModel match, List<CardModel> cards) {
|
||||
this.match = match;
|
||||
|
||||
List<Long> combIds = extractCombIds(match);
|
||||
List<CardModel> cards2 = cards.stream().filter(c -> combIds.contains(c.getComb()) && c.hasEffect(match))
|
||||
.sorted(Comparator.comparing(CardModel::getType).reversed()).toList();
|
||||
|
||||
|
||||
for (ScoreEmbeddable score : match.getScores()) {
|
||||
if (score.getS1() == -1000 || score.getS2() == -1000)
|
||||
continue;
|
||||
this.scoresToCompute.add(virtualScore(score, cards2, false));
|
||||
}
|
||||
|
||||
calc_win_end(cards2);
|
||||
|
||||
for (ScoreEmbeddable score : match.getScores()) {
|
||||
if (score.getS1() == -1000 || score.getS2() == -1000)
|
||||
continue;
|
||||
this.scoresToPrint.add(virtualScore(score, cards2, true));
|
||||
}
|
||||
if (this.isEnd && this.scoresToPrint.isEmpty()) {
|
||||
this.scoresToPrint.add(virtualScore(new ScoreEmbeddable(0, 0, 0), cards2, true));
|
||||
}
|
||||
}
|
||||
|
||||
private ScoreEmbeddable virtualScore(ScoreEmbeddable score, List<CardModel> cards2, boolean toPrint) {
|
||||
if (cards2.size() > 1) {
|
||||
if (!Objects.equals(cards2.get(0).getComb(), cards2.get(1).getComb()))
|
||||
return new ScoreEmbeddable(score.getN_round(), toPrint ? -997 : 0, toPrint ? -997 : 0);
|
||||
}
|
||||
if (!cards2.isEmpty()) {
|
||||
if (isC1(cards2.get(0).getComb()))
|
||||
return new ScoreEmbeddable(score.getN_round(), toPrint ? -997 : 0, 10);
|
||||
else
|
||||
return new ScoreEmbeddable(score.getN_round(), 10, toPrint ? -997 : 0);
|
||||
}
|
||||
|
||||
if (score.getS1() < -900 && score.getS2() < -900)
|
||||
return new ScoreEmbeddable(score.getN_round(), toPrint ? score.getS1() : 0, toPrint ? score.getS2() : 0);
|
||||
else if (score.getS1() < -900)
|
||||
return new ScoreEmbeddable(score.getN_round(), toPrint ? score.getS1() : 0, 10);
|
||||
else if (score.getS2() < -900)
|
||||
return new ScoreEmbeddable(score.getN_round(), 10, toPrint ? score.getS2() : 0);
|
||||
|
||||
return new ScoreEmbeddable(score.getN_round(), score.getS1(), score.getS2());
|
||||
}
|
||||
|
||||
private void calc_win_end(List<CardModel> cards2) {
|
||||
if (cards2.size() > 1) {
|
||||
if (!Objects.equals(cards2.get(0).getComb(), cards2.get(1).getComb())) {
|
||||
this.win = 0;
|
||||
this.isEnd = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cards2.isEmpty()) {
|
||||
if (match.isC1(cards2.get(0).getComb())) {
|
||||
this.win = -1;
|
||||
} else if (match.isC2(cards2.get(0).getComb())) {
|
||||
this.win = 1;
|
||||
}
|
||||
this.isEnd = true;
|
||||
return;
|
||||
}
|
||||
|
||||
for (ScoreEmbeddable score : this.scoresToCompute) {
|
||||
if (score.getS1() > score.getS2())
|
||||
win++;
|
||||
else if (score.getS1() < score.getS2())
|
||||
win--;
|
||||
}
|
||||
this.isEnd = match.isEnd();
|
||||
}
|
||||
|
||||
|
||||
private List<Long> extractCombIds(MatchModel match) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
if (match.getC1_id() != null)
|
||||
ids.add(match.getC1_id().getId());
|
||||
if (match.getC2_id() != null)
|
||||
ids.add(match.getC2_id().getId());
|
||||
if (match.getC1_guest() != null)
|
||||
ids.add(match.getC1_guest().getId() * -1);
|
||||
if (match.getC2_guest() != null)
|
||||
ids.add(match.getC2_guest().getId() * -1);
|
||||
return ids;
|
||||
}
|
||||
|
||||
//--------------- Delegation methods to MatchModel ---------------
|
||||
|
||||
public Long getId() {
|
||||
return match.getId();
|
||||
}
|
||||
|
||||
public MembreModel getC1_id() {
|
||||
return match.getC1_id();
|
||||
}
|
||||
|
||||
public CompetitionGuestModel getC1_guest() {
|
||||
return match.getC1_guest();
|
||||
}
|
||||
|
||||
public MembreModel getC2_id() {
|
||||
return match.getC2_id();
|
||||
}
|
||||
|
||||
public CompetitionGuestModel getC2_guest() {
|
||||
return match.getC2_guest();
|
||||
}
|
||||
|
||||
public CategoryModel getCategory() {
|
||||
return match.getCategory();
|
||||
}
|
||||
|
||||
public long getCategory_ord() {
|
||||
return match.getCategory_ord();
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return match.getDate();
|
||||
}
|
||||
|
||||
public char getPoule() {
|
||||
return match.getPoule();
|
||||
}
|
||||
|
||||
public String getC1Name(MembreModel model, ResultPrivacy privacy) {
|
||||
return match.getC1Name(model, privacy);
|
||||
}
|
||||
|
||||
public String getC2Name(MembreModel model, ResultPrivacy privacy) {
|
||||
return match.getC2Name(model, privacy);
|
||||
}
|
||||
|
||||
public String getC2Name() {
|
||||
return match.getC2Name();
|
||||
}
|
||||
|
||||
public String getC1Name() {
|
||||
return match.getC1Name();
|
||||
}
|
||||
|
||||
public boolean isC1(Object comb) {
|
||||
return match.isC1(comb);
|
||||
}
|
||||
|
||||
public boolean isC2(Object comb) {
|
||||
return match.isC2(comb);
|
||||
}
|
||||
}
|
||||
@ -62,18 +62,18 @@ public class CardService {
|
||||
public Uni<List<CardModel>> getForMatch(MatchModel match) {
|
||||
return cardRepository.list(
|
||||
"competition = ?1 AND (type IN ?2 OR (type = CardType.BLUE AND category = ?4)) AND comb IN ?3",
|
||||
match.getCategory().getCompet(), COMPETITION_LEVEL_CARDS,
|
||||
match.getCategory().getCompet().getId(), COMPETITION_LEVEL_CARDS,
|
||||
extractCombIds(match), match.getCategory().getId());
|
||||
}
|
||||
|
||||
public Uni<List<CardModel>> getAll(CompetitionModel competition) {
|
||||
return cardRepository.list("competition = ?1", competition);
|
||||
public Uni<List<CardModel>> getAll(Long competitionId) {
|
||||
return cardRepository.list("competition = ?1", competitionId);
|
||||
}
|
||||
|
||||
public Uni<RCard.SendCardAdd> checkCanBeAdded(RCard.SendCardAdd card, MatchModel matchModel) {
|
||||
return cardRepository.find("competition = ?1 AND comb = ?2",
|
||||
Sort.descending("type"),
|
||||
matchModel.getCategory().getCompet(), card.combId())
|
||||
matchModel.getCategory().getCompet().getId(), card.combId())
|
||||
.firstResult()
|
||||
.map(card_ -> {
|
||||
if (card.type() == CardModel.CardType.BLUE) {
|
||||
@ -119,7 +119,7 @@ public class CardService {
|
||||
.map(l -> l.stream().map(r -> r.getId() * -1).toList());
|
||||
}
|
||||
})
|
||||
.chain(combIds -> cardRepository.list("competition = ?1 AND comb IN ?2", competition, combIds)
|
||||
.chain(combIds -> cardRepository.list("competition = ?1 AND comb IN ?2", competition.getId(), combIds)
|
||||
.map(cards -> {
|
||||
List<CardModel> newCards = new ArrayList<>();
|
||||
for (Long id : combIds) {
|
||||
@ -127,8 +127,7 @@ public class CardService {
|
||||
.filter(c -> id.equals(c.getComb()) && c.getType() == type).findAny();
|
||||
|
||||
CardModel model = new CardModel();
|
||||
model.setCompetition(competition);
|
||||
model.setCompetitionId(competition.getId());
|
||||
model.setCompetition(competition.getId());
|
||||
model.setComb(id);
|
||||
model.setTeamCard(true);
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.*;
|
||||
import fr.titionfire.ffsaf.data.repository.*;
|
||||
import fr.titionfire.ffsaf.domain.entity.MatchModelExtend;
|
||||
import fr.titionfire.ffsaf.rest.data.ResultCategoryData;
|
||||
import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
@ -46,9 +45,6 @@ public class ResultService {
|
||||
@Inject
|
||||
MatchRepository matchRepository;
|
||||
|
||||
@Inject
|
||||
CardRepository cardRepository;
|
||||
|
||||
@Inject
|
||||
TradService trad;
|
||||
|
||||
@ -127,42 +123,39 @@ public class ResultService {
|
||||
}
|
||||
|
||||
public Uni<ResultCategoryData> getCategory(String uuid, long poule, SecurityCtx securityCtx) {
|
||||
return hasAccess(uuid, securityCtx).chain(membreModel -> getData(uuid, poule, membreModel));
|
||||
return hasAccess(uuid, securityCtx).chain(membreModel ->
|
||||
matchRepository.list("category.compet.uuid = ?1 AND category.id = ?2", uuid, poule)
|
||||
.call(list -> list.isEmpty() ? Uni.createFrom().voidItem() :
|
||||
Mutiny.fetch(list.get(0).getCategory().getTree()))
|
||||
.map(list -> getData(list, membreModel)));
|
||||
}
|
||||
|
||||
public Uni<ResultCategoryData> getCategory(String uuid, long poule) {
|
||||
return getData(uuid, poule, null);
|
||||
}
|
||||
|
||||
private Uni<ResultCategoryData> getData(String uuid, long poule, MembreModel membreModel) {
|
||||
List<CardModel> cards = new ArrayList<>();
|
||||
|
||||
return matchRepository.list("category.compet.uuid = ?1 AND category.id = ?2", uuid, poule)
|
||||
.call(list -> list.isEmpty() ? Uni.createFrom().voidItem() :
|
||||
Mutiny.fetch(list.get(0).getCategory().getTree()))
|
||||
.chain(list -> cardRepository.list("competition.uuid = ?1", uuid).invoke(cards::addAll)
|
||||
.map(c -> list.stream().map(m -> new MatchModelExtend(m, c)).toList()))
|
||||
.map(matchModels -> {
|
||||
.map(list -> getData(list, null));
|
||||
}
|
||||
|
||||
private ResultCategoryData getData(List<MatchModel> matchModels, MembreModel membreModel) {
|
||||
ResultCategoryData out = new ResultCategoryData();
|
||||
|
||||
CategoryModel categoryModel = matchModels.get(0).getCategory();
|
||||
out.setName(categoryModel.getName());
|
||||
out.setType(categoryModel.getType());
|
||||
out.setLiceName(categoryModel.getLiceName() == null ? new String[]{} : categoryModel.getLiceName()
|
||||
.split(";"));
|
||||
out.setLiceName(categoryModel.getLiceName() == null ? new String[]{} : categoryModel.getLiceName().split(";"));
|
||||
out.setGenTime(System.currentTimeMillis());
|
||||
|
||||
getArray2(matchModels, membreModel, out);
|
||||
getTree(categoryModel.getTree(), membreModel, cards, out);
|
||||
getTree(categoryModel.getTree(), membreModel, out);
|
||||
return out;
|
||||
});
|
||||
}
|
||||
|
||||
private void getArray2(List<MatchModelExtend> matchModels_, MembreModel membreModel, ResultCategoryData out) {
|
||||
List<MatchModelExtend> matchModels = matchModels_.stream().filter(o -> o.getCategory_ord() >= 0).toList();
|
||||
private void getArray2(List<MatchModel> matchModels_, MembreModel membreModel, ResultCategoryData out) {
|
||||
List<MatchModel> matchModels = matchModels_.stream().filter(o -> o.getCategory_ord() >= 0).toList();
|
||||
|
||||
HashMap<Character, List<MatchModelExtend>> matchMap = new HashMap<>();
|
||||
for (MatchModelExtend model : matchModels) {
|
||||
HashMap<Character, List<MatchModel>> matchMap = new HashMap<>();
|
||||
for (MatchModel model : matchModels) {
|
||||
char g = model.getPoule();
|
||||
if (!matchMap.containsKey(g))
|
||||
matchMap.put(g, new ArrayList<>());
|
||||
@ -171,7 +164,7 @@ public class ResultService {
|
||||
|
||||
matchMap.forEach((c, matchEntities) -> {
|
||||
List<ResultCategoryData.PouleArrayData> matchs = matchEntities.stream()
|
||||
.sorted(Comparator.comparing(MatchModelExtend::getCategory_ord))
|
||||
.sorted(Comparator.comparing(MatchModel::getCategory_ord))
|
||||
.map(o -> ResultCategoryData.PouleArrayData.fromModel(o, membreModel,
|
||||
ResultPrivacy.REGISTERED_ONLY_NO_DETAILS))
|
||||
.toList();
|
||||
@ -211,28 +204,26 @@ public class ResultService {
|
||||
}
|
||||
|
||||
private static void convertTree(TreeModel src, TreeNode<ResultCategoryData.TreeData> dst, MembreModel membreModel,
|
||||
ResultPrivacy privacy, List<CardModel> cards) {
|
||||
dst.setData(
|
||||
ResultCategoryData.TreeData.from(new MatchModelExtend(src.getMatch(), cards), membreModel, privacy));
|
||||
ResultPrivacy privacy) {
|
||||
dst.setData(ResultCategoryData.TreeData.from(src.getMatch(), membreModel, privacy));
|
||||
if (src.getLeft() != null) {
|
||||
dst.setLeft(new TreeNode<>());
|
||||
convertTree(src.getLeft(), dst.getLeft(), membreModel, privacy, cards);
|
||||
convertTree(src.getLeft(), dst.getLeft(), membreModel, privacy);
|
||||
}
|
||||
if (src.getRight() != null) {
|
||||
dst.setRight(new TreeNode<>());
|
||||
convertTree(src.getRight(), dst.getRight(), membreModel, privacy, cards);
|
||||
convertTree(src.getRight(), dst.getRight(), membreModel, privacy);
|
||||
}
|
||||
}
|
||||
|
||||
private void getTree(List<TreeModel> treeModels, MembreModel membreModel, List<CardModel> cards,
|
||||
ResultCategoryData out) {
|
||||
private void getTree(List<TreeModel> treeModels, MembreModel membreModel, ResultCategoryData out) {
|
||||
ArrayList<TreeNode<ResultCategoryData.TreeData>> trees = new ArrayList<>();
|
||||
treeModels.stream()
|
||||
.filter(t -> t.getLevel() != 0)
|
||||
.sorted(Comparator.comparing(TreeModel::getLevel))
|
||||
.forEach(treeModel -> {
|
||||
TreeNode<ResultCategoryData.TreeData> root = new TreeNode<>();
|
||||
convertTree(treeModel, root, membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS, cards);
|
||||
convertTree(treeModel, root, membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS);
|
||||
trees.add(root);
|
||||
});
|
||||
out.setTrees(trees);
|
||||
@ -250,13 +241,10 @@ public class ResultService {
|
||||
private Uni<CombsArrayData> getAllCombArray_(String uuid, MembreModel membreModel) {
|
||||
return registerRepository.list("competition.uuid = ?1", uuid)
|
||||
.chain(registers -> matchRepository.list("category.compet.uuid = ?1", uuid)
|
||||
.chain(matchModels -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(cards -> new Pair<>(registers,
|
||||
matchModels.stream().map(m -> new MatchModelExtend(m, cards)).toList()))))
|
||||
|
||||
.map(matchModels -> new Pair<>(registers, matchModels)))
|
||||
.map(pair -> {
|
||||
List<RegisterModel> registers = pair.getKey();
|
||||
List<MatchModelExtend> matchModels = pair.getValue();
|
||||
List<MatchModel> matchModels = pair.getValue();
|
||||
|
||||
CombsArrayData.CombsArrayDataBuilder builder = CombsArrayData.builder();
|
||||
|
||||
@ -302,10 +290,11 @@ public class ResultService {
|
||||
.toList();
|
||||
|
||||
builder.nb_insc(combs.size());
|
||||
builder.tt_match((int) matchModels.stream().filter(MatchModelExtend::isEnd).count());
|
||||
builder.tt_match((int) matchModels.stream().filter(MatchModel::isEnd).count());
|
||||
builder.point(matchModels.stream()
|
||||
.filter(MatchModelExtend::isEnd)
|
||||
.flatMap(m -> m.getScoresToCompute().stream())
|
||||
.filter(MatchModel::isEnd)
|
||||
.flatMap(m -> m.getScores().stream())
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
.mapToInt(s -> s.getS1() + s.getS2()).sum());
|
||||
builder.combs(combs);
|
||||
|
||||
@ -356,7 +345,7 @@ public class ResultService {
|
||||
return Uni.createFrom().failure(new DForbiddenException(trad.t("comb.not.found")));
|
||||
}
|
||||
|
||||
Uni<List<MatchModelExtend>> uni;
|
||||
Uni<List<MatchModel>> uni;
|
||||
if (id >= 0) {
|
||||
uni = registerRepository.find("membre.id = ?1 AND competition.uuid = ?2 AND membre.resultPrivacy <= ?3", id,
|
||||
uuid, privacy).firstResult()
|
||||
@ -373,10 +362,7 @@ public class ResultService {
|
||||
return matchRepository.list(
|
||||
"SELECT DISTINCT m FROM MatchModel m LEFT JOIN m.c1_guest.comb c1g LEFT JOIN m.c2_guest.comb c2g " +
|
||||
"WHERE m.category.compet.uuid = ?1 AND (m.c1_id = ?2 OR m.c2_id = ?2 OR c1g = ?2 OR c2g = ?2)",
|
||||
uuid, registerModel.getMembre())
|
||||
.chain(matchModels -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(cards -> matchModels.stream().map(m -> new MatchModelExtend(m, cards))
|
||||
.toList()));
|
||||
uuid, registerModel.getMembre());
|
||||
}));
|
||||
} else {
|
||||
uni = competitionGuestRepository.find("id = ?1 AND competition.uuid = ?2", -id, uuid).firstResult()
|
||||
@ -389,15 +375,12 @@ public class ResultService {
|
||||
return matchRepository.list(
|
||||
"SELECT DISTINCT m FROM MatchModel m LEFT JOIN m.c1_guest.guest c1g LEFT JOIN m.c2_guest.guest c2g " +
|
||||
"WHERE m.category.compet.uuid = ?1 AND (m.c1_guest = ?2 OR m.c2_guest = ?2 OR c1g = ?2 OR c2g = ?2)",
|
||||
uuid, guestModel)
|
||||
.chain(matchModels -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(cards -> matchModels.stream().map(m -> new MatchModelExtend(m, cards))
|
||||
.toList()));
|
||||
uuid, guestModel);
|
||||
});
|
||||
}
|
||||
|
||||
return uni.invoke(matchModels -> {
|
||||
List<CategoryModel> pouleModels = matchModels.stream().map(MatchModelExtend::getCategory).distinct()
|
||||
List<CategoryModel> pouleModels = matchModels.stream().map(MatchModel::getCategory).distinct()
|
||||
.toList();
|
||||
List<CombArrayData.MatchsData> matchs = new ArrayList<>();
|
||||
|
||||
@ -405,7 +388,7 @@ public class ResultService {
|
||||
AtomicInteger sumPointMake = new AtomicInteger(0);
|
||||
AtomicInteger sumPointTake = new AtomicInteger(0);
|
||||
|
||||
for (MatchModelExtend matchModel : matchModels) {
|
||||
for (MatchModel matchModel : matchModels) {
|
||||
if ((matchModel.getC1_id() == null && matchModel.getC1_guest() == null) ||
|
||||
(matchModel.getC2_id() == null && matchModel.getC2_guest() == null))
|
||||
continue;
|
||||
@ -422,33 +405,35 @@ public class ResultService {
|
||||
if (matchModel.isC1(id)) {
|
||||
builder2.adv(matchModel.getC2Name());
|
||||
if (matchModel.isEnd()) {
|
||||
matchModel.getScoresToCompute()
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
.forEach(scoreEntity -> {
|
||||
pointMake.addAndGet(scoreEntity.getS1());
|
||||
pointTake.addAndGet(scoreEntity.getS2());
|
||||
});
|
||||
builder2.score(matchModel.getScoresToPrint().stream()
|
||||
builder2.score(matchModel.getScores().stream()
|
||||
.map(s -> new Integer[]{s.getS1(), s.getS2()}).toList());
|
||||
} else {
|
||||
builder2.score(new ArrayList<>());
|
||||
}
|
||||
builder2.win(matchModel.isEnd() && matchModel.getWin() > 0);
|
||||
builder2.win(matchModel.isEnd() && matchModel.win() > 0);
|
||||
} else {
|
||||
builder2.adv(matchModel.getC1Name());
|
||||
if (matchModel.isEnd()) {
|
||||
matchModel.getScoresToCompute()
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
.forEach(scoreEntity -> {
|
||||
pointMake.addAndGet(scoreEntity.getS2());
|
||||
pointTake.addAndGet(scoreEntity.getS1());
|
||||
});
|
||||
builder2.score(matchModel.getScoresToPrint().stream()
|
||||
builder2.score(matchModel.getScores().stream()
|
||||
.map(s -> new Integer[]{s.getS2(), s.getS1()}).toList());
|
||||
} else {
|
||||
builder2.score(new ArrayList<>());
|
||||
}
|
||||
builder2.win(matchModel.isEnd() && matchModel.getWin() < 0);
|
||||
builder2.win(matchModel.isEnd() && matchModel.win() < 0);
|
||||
}
|
||||
builder2.eq(matchModel.isEnd() && matchModel.getWin() == 0);
|
||||
builder2.eq(matchModel.isEnd() && matchModel.win() == 0);
|
||||
builder2.ratio(
|
||||
(pointTake.get() == 0) ? pointMake.get() : (float) pointMake.get() / pointTake.get());
|
||||
|
||||
@ -540,13 +525,9 @@ public class ResultService {
|
||||
"SELECT DISTINCT m FROM MatchModel m LEFT JOIN m.c1_guest.guest c1g LEFT JOIN m.c2_guest.guest c2g " +
|
||||
"WHERE m.category.compet.uuid = ?1 AND (m.c1_guest IN ?2 OR m.c2_guest IN ?2 OR c1g IN ?2 OR c2g IN ?2)",
|
||||
uuid, guests)
|
||||
|
||||
.chain(mm -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(cards ->
|
||||
.map(matchModels ->
|
||||
getClubArray2(clubName, guests.stream().map(o -> (CombModel) o).toList(),
|
||||
mm.stream().map(m -> new MatchModelExtend(m, cards)).toList(),
|
||||
new ArrayList<>(), membreModel)
|
||||
)));
|
||||
matchModels, new ArrayList<>(), membreModel)));
|
||||
} else {
|
||||
return clubRepository.findById(id).chain(clubModel ->
|
||||
registerRepository.list("competition.uuid = ?1 AND membre.club = ?2", uuid, clubModel)
|
||||
@ -554,20 +535,14 @@ public class ResultService {
|
||||
"SELECT DISTINCT m FROM MatchModel m LEFT JOIN m.c1_guest.comb c1g LEFT JOIN m.c2_guest.comb c2g " +
|
||||
"WHERE m.category.compet.uuid = ?1 AND (m.c1_id IN ?2 OR m.c2_id IN ?2 OR c1g IN ?2 OR c2g IN ?2)",
|
||||
uuid, registers.stream().map(RegisterModel::getMembre).toList())
|
||||
.chain(matchModels -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(cards ->
|
||||
.map(matchModels ->
|
||||
getClubArray2(clubModel.getName(),
|
||||
registers.stream().map(o -> (CombModel) o.getMembre())
|
||||
.toList(),
|
||||
matchModels.stream()
|
||||
.map(m -> new MatchModelExtend(m, cards)).toList(),
|
||||
registers, membreModel)
|
||||
|
||||
))));
|
||||
registers.stream().map(o -> (CombModel) o.getMembre()).toList(),
|
||||
matchModels, registers, membreModel))));
|
||||
}
|
||||
}
|
||||
|
||||
private ClubArrayData getClubArray2(String name, List<CombModel> combs, List<MatchModelExtend> matchModels,
|
||||
private ClubArrayData getClubArray2(String name, List<CombModel> combs, List<MatchModel> matchModels,
|
||||
List<RegisterModel> registers, MembreModel membreModel) {
|
||||
ClubArrayData.ClubArrayDataBuilder builder = ClubArrayData.builder();
|
||||
builder.name(name);
|
||||
@ -622,14 +597,14 @@ public class ResultService {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static CombStat makeStat(List<MatchModelExtend> matchModels, CombModel comb) {
|
||||
private static CombStat makeStat(List<MatchModel> matchModels, CombModel comb) {
|
||||
CombStat stat = new CombStat();
|
||||
matchModels.stream()
|
||||
.filter(m -> m.isEnd() && (m.isC1(comb) || m.isC2(comb)))
|
||||
.forEach(matchModel -> {
|
||||
stat.match_ids.add(matchModel.getId());
|
||||
|
||||
int win = matchModel.getWin();
|
||||
int win = matchModel.win();
|
||||
if (win == 0) {
|
||||
stat.score += 1;
|
||||
} else if ((matchModel.isC1(comb) && win > 0) || matchModel.isC2(comb) && win < 0) {
|
||||
@ -640,7 +615,8 @@ public class ResultService {
|
||||
stat.l++;
|
||||
}
|
||||
|
||||
matchModel.getScoresToCompute()
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
.forEach(score -> {
|
||||
if (matchModel.isC1(comb)) {
|
||||
stat.pointMake += score.getS1();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MatchModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.domain.entity.MatchModelExtend;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
|
||||
import fr.titionfire.ffsaf.utils.TreeNode;
|
||||
@ -43,16 +43,16 @@ public class ResultCategoryData {
|
||||
@RegisterForReflection
|
||||
public record PouleArrayData(String red, boolean red_w, List<Integer[]> score, boolean blue_w, String blue,
|
||||
boolean eq, boolean end, Date date) {
|
||||
public static PouleArrayData fromModel(MatchModelExtend matchModel, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
public static PouleArrayData fromModel(MatchModel matchModel, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
return new PouleArrayData(
|
||||
matchModel.getC1Name(membreModel, privacy),
|
||||
matchModel.isEnd() && matchModel.getWin() > 0,
|
||||
matchModel.isEnd() && matchModel.win() > 0,
|
||||
matchModel.isEnd() ?
|
||||
matchModel.getScoresToPrint().stream().map(s -> new Integer[]{s.getS1(), s.getS2()}).toList()
|
||||
matchModel.getScores().stream().map(s -> new Integer[]{s.getS1(), s.getS2()}).toList()
|
||||
: new ArrayList<>(),
|
||||
matchModel.isEnd() && matchModel.getWin() < 0,
|
||||
matchModel.isEnd() && matchModel.win() < 0,
|
||||
matchModel.getC2Name(membreModel, privacy),
|
||||
matchModel.isEnd() && matchModel.getWin() == 0,
|
||||
matchModel.isEnd() && matchModel.win() == 0,
|
||||
matchModel.isEnd(),
|
||||
matchModel.getDate());
|
||||
}
|
||||
@ -60,10 +60,10 @@ public class ResultCategoryData {
|
||||
|
||||
@RegisterForReflection
|
||||
public static record TreeData(long id, String c1FullName, String c2FullName, List<ScoreEmbeddable> scores,
|
||||
boolean end, int win) {
|
||||
public static TreeData from(MatchModelExtend match, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
boolean end) {
|
||||
public static TreeData from(MatchModel match, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
return new TreeData(match.getId(), match.getC1Name(membreModel, privacy),
|
||||
match.getC2Name(membreModel, privacy), match.getScoresToPrint(), match.isEnd(), match.getWin());
|
||||
match.getC2Name(membreModel, privacy), match.getScores(), match.isEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,8 +83,7 @@ public class RCard {
|
||||
model.setComb(card.combId());
|
||||
model.setMatch(card.matchId());
|
||||
model.setCategory(matchModel.getCategory().getId());
|
||||
model.setCompetition(matchModel.getCategory().getCompet());
|
||||
model.setCompetitionId(matchModel.getCategory().getCompet().getId());
|
||||
model.setCompetition(matchModel.getCategory().getCompet().getId());
|
||||
model.setType(card.type());
|
||||
model.setReason(card.reason());
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ public class RCategorie {
|
||||
.call(cat -> treeRepository.list("category = ?1 AND level != 0", cat.getId())
|
||||
.map(treeModels -> treeModels.stream().map(TreeEntity::fromModel).toList())
|
||||
.invoke(fullCategory::setTrees))
|
||||
.call(cat -> cardService.getAll(cat.getCompet())
|
||||
.call(cat -> cardService.getAll(cat.getCompet().getId())
|
||||
.invoke(fullCategory::setCards))
|
||||
.map(__ -> fullCategory);
|
||||
}
|
||||
|
||||
@ -90,7 +90,8 @@ function stopLoading(loading) {
|
||||
loading['root'].removeChild(loading['element']);
|
||||
}
|
||||
|
||||
function scorePrint(s1) {
|
||||
function scoreToString(score) {
|
||||
const scorePrint = (s1) => {
|
||||
switch (s1) {
|
||||
case -997:
|
||||
return i18next.t('disc.');
|
||||
@ -103,8 +104,8 @@ function scorePrint(s1) {
|
||||
default:
|
||||
return String(s1);
|
||||
}
|
||||
}
|
||||
function scoreToString(score) {
|
||||
}
|
||||
|
||||
return score.map(o => scorePrint(o.at(0)) + "-" + scorePrint(o.at(1))).join(" | ");
|
||||
}
|
||||
|
||||
@ -866,7 +867,7 @@ function drawGraph(root = []) {
|
||||
ctx.textBaseline = 'top';
|
||||
|
||||
for (let i = 0; i < scores.length; i++) {
|
||||
const score = scorePrint(scores[i].s1) + "-" + scorePrint(scores[i].s2);
|
||||
const score = scores[i].s1 + "-" + scores[i].s2;
|
||||
const div = (scores.length <= 2) ? 2 : (scores.length >= 4) ? 4 : 3;
|
||||
const text = ctx.measureText(score);
|
||||
let dx = (size * 2 - text.width) / 2;
|
||||
@ -944,6 +945,20 @@ function drawGraph(root = []) {
|
||||
if (tree.right != null) drawNode(tree.right, px - size * 2 - size * 8, py + size * 2 * death);
|
||||
}
|
||||
|
||||
function win(scores) {
|
||||
let sum = 0;
|
||||
for (const score of scores) {
|
||||
if (score.s1 === -1000 || score.s2 === -1000)
|
||||
continue;
|
||||
|
||||
if (score.s1 > score.s2)
|
||||
sum++;
|
||||
else if (score.s1 < score.s2)
|
||||
sum--;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
let px = max_x;
|
||||
let py;
|
||||
let max_y
|
||||
@ -956,7 +971,7 @@ function drawGraph(root = []) {
|
||||
for (const node of root) {
|
||||
let win_name = "";
|
||||
if (node.data.end) {
|
||||
if (node.data.win > 0)
|
||||
if (win(node.data.scores) > 0)
|
||||
win_name = (node.data.c1FullName === null) ? "???" : node.data.c1FullName;
|
||||
else
|
||||
win_name = (node.data.c2FullName === null) ? "???" : node.data.c2FullName;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user