feat: card in result view
This commit is contained in:
parent
541d3824f3
commit
952300d063
@ -4,16 +4,15 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
@ -46,6 +45,16 @@ 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,17 +1,176 @@
|
||||
package fr.titionfire.ffsaf.domain.entity;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CardModel;
|
||||
import fr.titionfire.ffsaf.data.model.MatchModel;
|
||||
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.List;
|
||||
import java.util.*;
|
||||
|
||||
@RegisterForReflection
|
||||
public class MatchModelExtend{
|
||||
public class MatchModelExtend {
|
||||
final MatchModel match;
|
||||
|
||||
public MatchModelExtend(MatchModel match, List<CardModel> c) {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ 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;
|
||||
@ -45,6 +46,9 @@ public class ResultService {
|
||||
@Inject
|
||||
MatchRepository matchRepository;
|
||||
|
||||
@Inject
|
||||
CardRepository cardRepository;
|
||||
|
||||
@Inject
|
||||
TradService trad;
|
||||
|
||||
@ -123,39 +127,42 @@ public class ResultService {
|
||||
}
|
||||
|
||||
public Uni<ResultCategoryData> getCategory(String uuid, long poule, SecurityCtx securityCtx) {
|
||||
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)));
|
||||
return hasAccess(uuid, securityCtx).chain(membreModel -> getData(uuid, poule, 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()))
|
||||
.map(list -> getData(list, null));
|
||||
.chain(list -> cardRepository.list("competition.uuid = ?1", uuid).invoke(cards::addAll)
|
||||
.map(c -> list.stream().map(m -> new MatchModelExtend(m, c)).toList()))
|
||||
.map(matchModels -> {
|
||||
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.setGenTime(System.currentTimeMillis());
|
||||
|
||||
getArray2(matchModels, membreModel, out);
|
||||
getTree(categoryModel.getTree(), membreModel, cards, out);
|
||||
return out;
|
||||
});
|
||||
}
|
||||
|
||||
private ResultCategoryData getData(List<MatchModel> matchModels, MembreModel membreModel) {
|
||||
ResultCategoryData out = new ResultCategoryData();
|
||||
private void getArray2(List<MatchModelExtend> matchModels_, MembreModel membreModel, ResultCategoryData out) {
|
||||
List<MatchModelExtend> matchModels = matchModels_.stream().filter(o -> o.getCategory_ord() >= 0).toList();
|
||||
|
||||
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.setGenTime(System.currentTimeMillis());
|
||||
|
||||
getArray2(matchModels, membreModel, out);
|
||||
getTree(categoryModel.getTree(), membreModel, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
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<MatchModel>> matchMap = new HashMap<>();
|
||||
for (MatchModel model : matchModels) {
|
||||
HashMap<Character, List<MatchModelExtend>> matchMap = new HashMap<>();
|
||||
for (MatchModelExtend model : matchModels) {
|
||||
char g = model.getPoule();
|
||||
if (!matchMap.containsKey(g))
|
||||
matchMap.put(g, new ArrayList<>());
|
||||
@ -164,7 +171,7 @@ public class ResultService {
|
||||
|
||||
matchMap.forEach((c, matchEntities) -> {
|
||||
List<ResultCategoryData.PouleArrayData> matchs = matchEntities.stream()
|
||||
.sorted(Comparator.comparing(MatchModel::getCategory_ord))
|
||||
.sorted(Comparator.comparing(MatchModelExtend::getCategory_ord))
|
||||
.map(o -> ResultCategoryData.PouleArrayData.fromModel(o, membreModel,
|
||||
ResultPrivacy.REGISTERED_ONLY_NO_DETAILS))
|
||||
.toList();
|
||||
@ -204,26 +211,28 @@ public class ResultService {
|
||||
}
|
||||
|
||||
private static void convertTree(TreeModel src, TreeNode<ResultCategoryData.TreeData> dst, MembreModel membreModel,
|
||||
ResultPrivacy privacy) {
|
||||
dst.setData(ResultCategoryData.TreeData.from(src.getMatch(), membreModel, privacy));
|
||||
ResultPrivacy privacy, List<CardModel> cards) {
|
||||
dst.setData(
|
||||
ResultCategoryData.TreeData.from(new MatchModelExtend(src.getMatch(), cards), membreModel, privacy));
|
||||
if (src.getLeft() != null) {
|
||||
dst.setLeft(new TreeNode<>());
|
||||
convertTree(src.getLeft(), dst.getLeft(), membreModel, privacy);
|
||||
convertTree(src.getLeft(), dst.getLeft(), membreModel, privacy, cards);
|
||||
}
|
||||
if (src.getRight() != null) {
|
||||
dst.setRight(new TreeNode<>());
|
||||
convertTree(src.getRight(), dst.getRight(), membreModel, privacy);
|
||||
convertTree(src.getRight(), dst.getRight(), membreModel, privacy, cards);
|
||||
}
|
||||
}
|
||||
|
||||
private void getTree(List<TreeModel> treeModels, MembreModel membreModel, ResultCategoryData out) {
|
||||
private void getTree(List<TreeModel> treeModels, MembreModel membreModel, List<CardModel> cards,
|
||||
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);
|
||||
convertTree(treeModel, root, membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS, cards);
|
||||
trees.add(root);
|
||||
});
|
||||
out.setTrees(trees);
|
||||
@ -241,10 +250,13 @@ 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)
|
||||
.map(matchModels -> new Pair<>(registers, matchModels)))
|
||||
.chain(matchModels -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(cards -> new Pair<>(registers,
|
||||
matchModels.stream().map(m -> new MatchModelExtend(m, cards)).toList()))))
|
||||
|
||||
.map(pair -> {
|
||||
List<RegisterModel> registers = pair.getKey();
|
||||
List<MatchModel> matchModels = pair.getValue();
|
||||
List<MatchModelExtend> matchModels = pair.getValue();
|
||||
|
||||
CombsArrayData.CombsArrayDataBuilder builder = CombsArrayData.builder();
|
||||
|
||||
@ -290,11 +302,10 @@ public class ResultService {
|
||||
.toList();
|
||||
|
||||
builder.nb_insc(combs.size());
|
||||
builder.tt_match((int) matchModels.stream().filter(MatchModel::isEnd).count());
|
||||
builder.tt_match((int) matchModels.stream().filter(MatchModelExtend::isEnd).count());
|
||||
builder.point(matchModels.stream()
|
||||
.filter(MatchModel::isEnd)
|
||||
.flatMap(m -> m.getScores().stream())
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
.filter(MatchModelExtend::isEnd)
|
||||
.flatMap(m -> m.getScoresToCompute().stream())
|
||||
.mapToInt(s -> s.getS1() + s.getS2()).sum());
|
||||
builder.combs(combs);
|
||||
|
||||
@ -345,7 +356,7 @@ public class ResultService {
|
||||
return Uni.createFrom().failure(new DForbiddenException(trad.t("comb.not.found")));
|
||||
}
|
||||
|
||||
Uni<List<MatchModel>> uni;
|
||||
Uni<List<MatchModelExtend>> uni;
|
||||
if (id >= 0) {
|
||||
uni = registerRepository.find("membre.id = ?1 AND competition.uuid = ?2 AND membre.resultPrivacy <= ?3", id,
|
||||
uuid, privacy).firstResult()
|
||||
@ -360,9 +371,12 @@ public class ResultService {
|
||||
registerModel.getCategorie2().getName(trad));
|
||||
|
||||
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());
|
||||
"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()));
|
||||
}));
|
||||
} else {
|
||||
uni = competitionGuestRepository.find("id = ?1 AND competition.uuid = ?2", -id, uuid).firstResult()
|
||||
@ -373,14 +387,17 @@ public class ResultService {
|
||||
(guestModel.getCategorie() == null) ? "---" : guestModel.getCategorie().getName(trad));
|
||||
|
||||
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);
|
||||
"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()));
|
||||
});
|
||||
}
|
||||
|
||||
return uni.invoke(matchModels -> {
|
||||
List<CategoryModel> pouleModels = matchModels.stream().map(MatchModel::getCategory).distinct()
|
||||
List<CategoryModel> pouleModels = matchModels.stream().map(MatchModelExtend::getCategory).distinct()
|
||||
.toList();
|
||||
List<CombArrayData.MatchsData> matchs = new ArrayList<>();
|
||||
|
||||
@ -388,7 +405,7 @@ public class ResultService {
|
||||
AtomicInteger sumPointMake = new AtomicInteger(0);
|
||||
AtomicInteger sumPointTake = new AtomicInteger(0);
|
||||
|
||||
for (MatchModel matchModel : matchModels) {
|
||||
for (MatchModelExtend matchModel : matchModels) {
|
||||
if ((matchModel.getC1_id() == null && matchModel.getC1_guest() == null) ||
|
||||
(matchModel.getC2_id() == null && matchModel.getC2_guest() == null))
|
||||
continue;
|
||||
@ -405,35 +422,33 @@ public class ResultService {
|
||||
if (matchModel.isC1(id)) {
|
||||
builder2.adv(matchModel.getC2Name());
|
||||
if (matchModel.isEnd()) {
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
matchModel.getScoresToCompute()
|
||||
.forEach(scoreEntity -> {
|
||||
pointMake.addAndGet(scoreEntity.getS1());
|
||||
pointTake.addAndGet(scoreEntity.getS2());
|
||||
});
|
||||
builder2.score(matchModel.getScores().stream()
|
||||
builder2.score(matchModel.getScoresToPrint().stream()
|
||||
.map(s -> new Integer[]{s.getS1(), s.getS2()}).toList());
|
||||
} else {
|
||||
builder2.score(new ArrayList<>());
|
||||
}
|
||||
builder2.win(matchModel.isEnd() && matchModel.win() > 0);
|
||||
builder2.win(matchModel.isEnd() && matchModel.getWin() > 0);
|
||||
} else {
|
||||
builder2.adv(matchModel.getC1Name());
|
||||
if (matchModel.isEnd()) {
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
matchModel.getScoresToCompute()
|
||||
.forEach(scoreEntity -> {
|
||||
pointMake.addAndGet(scoreEntity.getS2());
|
||||
pointTake.addAndGet(scoreEntity.getS1());
|
||||
});
|
||||
builder2.score(matchModel.getScores().stream()
|
||||
builder2.score(matchModel.getScoresToPrint().stream()
|
||||
.map(s -> new Integer[]{s.getS2(), s.getS1()}).toList());
|
||||
} else {
|
||||
builder2.score(new ArrayList<>());
|
||||
}
|
||||
builder2.win(matchModel.isEnd() && matchModel.win() < 0);
|
||||
builder2.win(matchModel.isEnd() && matchModel.getWin() < 0);
|
||||
}
|
||||
builder2.eq(matchModel.isEnd() && matchModel.win() == 0);
|
||||
builder2.eq(matchModel.isEnd() && matchModel.getWin() == 0);
|
||||
builder2.ratio(
|
||||
(pointTake.get() == 0) ? pointMake.get() : (float) pointMake.get() / pointTake.get());
|
||||
|
||||
@ -525,9 +540,13 @@ 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)
|
||||
.map(matchModels ->
|
||||
getClubArray2(clubName, guests.stream().map(o -> (CombModel) o).toList(),
|
||||
matchModels, new ArrayList<>(), membreModel)));
|
||||
|
||||
.chain(mm -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(cards ->
|
||||
getClubArray2(clubName, guests.stream().map(o -> (CombModel) o).toList(),
|
||||
mm.stream().map(m -> new MatchModelExtend(m, cards)).toList(),
|
||||
new ArrayList<>(), membreModel)
|
||||
)));
|
||||
} else {
|
||||
return clubRepository.findById(id).chain(clubModel ->
|
||||
registerRepository.list("competition.uuid = ?1 AND membre.club = ?2", uuid, clubModel)
|
||||
@ -535,14 +554,20 @@ 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())
|
||||
.map(matchModels ->
|
||||
getClubArray2(clubModel.getName(),
|
||||
registers.stream().map(o -> (CombModel) o.getMembre()).toList(),
|
||||
matchModels, registers, membreModel))));
|
||||
.chain(matchModels -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(cards ->
|
||||
getClubArray2(clubModel.getName(),
|
||||
registers.stream().map(o -> (CombModel) o.getMembre())
|
||||
.toList(),
|
||||
matchModels.stream()
|
||||
.map(m -> new MatchModelExtend(m, cards)).toList(),
|
||||
registers, membreModel)
|
||||
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
private ClubArrayData getClubArray2(String name, List<CombModel> combs, List<MatchModel> matchModels,
|
||||
private ClubArrayData getClubArray2(String name, List<CombModel> combs, List<MatchModelExtend> matchModels,
|
||||
List<RegisterModel> registers, MembreModel membreModel) {
|
||||
ClubArrayData.ClubArrayDataBuilder builder = ClubArrayData.builder();
|
||||
builder.name(name);
|
||||
@ -597,14 +622,14 @@ public class ResultService {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static CombStat makeStat(List<MatchModel> matchModels, CombModel comb) {
|
||||
private static CombStat makeStat(List<MatchModelExtend> 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.win();
|
||||
int win = matchModel.getWin();
|
||||
if (win == 0) {
|
||||
stat.score += 1;
|
||||
} else if ((matchModel.isC1(comb) && win > 0) || matchModel.isC2(comb) && win < 0) {
|
||||
@ -615,8 +640,7 @@ public class ResultService {
|
||||
stat.l++;
|
||||
}
|
||||
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
matchModel.getScoresToCompute()
|
||||
.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(MatchModel matchModel, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
public static PouleArrayData fromModel(MatchModelExtend matchModel, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
return new PouleArrayData(
|
||||
matchModel.getC1Name(membreModel, privacy),
|
||||
matchModel.isEnd() && matchModel.win() > 0,
|
||||
matchModel.isEnd() && matchModel.getWin() > 0,
|
||||
matchModel.isEnd() ?
|
||||
matchModel.getScores().stream().map(s -> new Integer[]{s.getS1(), s.getS2()}).toList()
|
||||
matchModel.getScoresToPrint().stream().map(s -> new Integer[]{s.getS1(), s.getS2()}).toList()
|
||||
: new ArrayList<>(),
|
||||
matchModel.isEnd() && matchModel.win() < 0,
|
||||
matchModel.isEnd() && matchModel.getWin() < 0,
|
||||
matchModel.getC2Name(membreModel, privacy),
|
||||
matchModel.isEnd() && matchModel.win() == 0,
|
||||
matchModel.isEnd() && matchModel.getWin() == 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) {
|
||||
public static TreeData from(MatchModel match, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
boolean end, int win) {
|
||||
public static TreeData from(MatchModelExtend match, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
return new TreeData(match.getId(), match.getC1Name(membreModel, privacy),
|
||||
match.getC2Name(membreModel, privacy), match.getScores(), match.isEnd());
|
||||
match.getC2Name(membreModel, privacy), match.getScoresToPrint(), match.isEnd(), match.getWin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,22 +90,21 @@ function stopLoading(loading) {
|
||||
loading['root'].removeChild(loading['element']);
|
||||
}
|
||||
|
||||
function scoreToString(score) {
|
||||
const scorePrint = (s1) => {
|
||||
switch (s1) {
|
||||
case -997:
|
||||
return i18next.t('disc.');
|
||||
case -998:
|
||||
return i18next.t('abs.');
|
||||
case -999:
|
||||
return i18next.t('for.');
|
||||
case -1000:
|
||||
return "";
|
||||
default:
|
||||
return String(s1);
|
||||
}
|
||||
function scorePrint(s1) {
|
||||
switch (s1) {
|
||||
case -997:
|
||||
return i18next.t('disc.');
|
||||
case -998:
|
||||
return i18next.t('abs.');
|
||||
case -999:
|
||||
return i18next.t('for.');
|
||||
case -1000:
|
||||
return "";
|
||||
default:
|
||||
return String(s1);
|
||||
}
|
||||
|
||||
}
|
||||
function scoreToString(score) {
|
||||
return score.map(o => scorePrint(o.at(0)) + "-" + scorePrint(o.at(1))).join(" | ");
|
||||
}
|
||||
|
||||
@ -867,7 +866,7 @@ function drawGraph(root = []) {
|
||||
ctx.textBaseline = 'top';
|
||||
|
||||
for (let i = 0; i < scores.length; i++) {
|
||||
const score = scores[i].s1 + "-" + scores[i].s2;
|
||||
const score = scorePrint(scores[i].s1) + "-" + scorePrint(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;
|
||||
@ -945,20 +944,6 @@ 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
|
||||
@ -971,7 +956,7 @@ function drawGraph(root = []) {
|
||||
for (const node of root) {
|
||||
let win_name = "";
|
||||
if (node.data.end) {
|
||||
if (win(node.data.scores) > 0)
|
||||
if (node.data.win > 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