Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![GitHub last commit](https://img.shields.io/github/last-commit/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![Issues](https://img.shields.io/github/issues/softwaremagico/KendoTournamentManager.svg)](https://github.com/softwaremagico/KendoTournamentManager/issues)
[![CircleCI](https://circleci.com/gh/softwaremagico/KendoTournamentManager.svg?style=shield)](https://circleci.com/gh/softwaremagico/KendoTournamentManager)
[![Time](https://img.shields.io/badge/development-708.5h-blueviolet.svg)]()
[![Time](https://img.shields.io/badge/development-710h-blueviolet.svg)]()

[![Powered by](https://img.shields.io/badge/powered%20by%20java-orange.svg?logo=OpenJDK&logoColor=white)]()
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=kendo-tournament-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=kendo-tournament-backend)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ScoreOfCompetitorDTO {
private Integer drawDuels = null;
private Integer untieDuels = null;
private Integer hits = null;
private Integer hitsLost = null;
private Integer untieHits = null;
private Integer duelsDone = null;
private Integer wonFights = null;
Expand Down Expand Up @@ -92,6 +93,14 @@ public void setHits(Integer hits) {
this.hits = hits;
}

public Integer getHitsLost() {
return hitsLost;
}

public void setHitsLost(Integer hitsLost) {
this.hitsLost = hitsLost;
}

public Integer getUntieHits() {
return untieHits;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ScoreOfTeamDTO extends ElementDTO {
private Integer drawDuels = null;
private Integer untieDuels = null;
private Integer hits = null;
private Integer hitsLost = null;
private Integer level = null;
private Integer sortingIndex = null;

Expand Down Expand Up @@ -213,6 +214,14 @@ public void setHits(Integer hits) {
this.hits = hits;
}

public Integer getHitsLost() {
return hitsLost;
}

public void setHitsLost(Integer hitsLost) {
this.hitsLost = hitsLost;
}

public Integer getLevel() {
return level;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ScoreOfCompetitor {
private Integer drawDuels = null;
private Integer untieDuels = null;
private Integer hits = null;
private Integer hitsLost = null;
private Integer untieHits = null;
private Integer duelsDone = null;
private Integer wonFights = null;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void update() {
wonDuels = null;
drawDuels = null;
hits = null;
hitsLost = null;
totalFights = null;
setDuelsWon();
setDuelsDraw();
Expand All @@ -93,6 +95,7 @@ public void update() {
setUntieDuels();
setUntieHits();
setHits();
setHitsLost();
setTotalFights();
}

Expand Down Expand Up @@ -170,6 +173,15 @@ public void setHits() {
}
}

public void setHitsLost() {
hitsLost = 0;
for (final Fight fight : fights) {
if (fight != null) {
hitsLost += fight.getScoreAgainst(competitor);
}
}
}

public void setUntieDuels() {
untieDuels = 0;
unties.forEach(duel -> {
Expand Down Expand Up @@ -215,6 +227,14 @@ public void setHits(Integer hits) {
this.hits = hits;
}

public Integer getHitsLost() {
return hitsLost;
}

public void setHitsLost(Integer hitsLost) {
this.hitsLost = hitsLost;
}

public Integer getDuelsDone() {
return duelsDone;
}
Expand Down Expand Up @@ -273,7 +293,8 @@ public void setTotalFights(Integer totalFights) {

@Override
public String toString() {
return "{" + NameUtils.getLastnameName(competitor) + " D:" + getWonDuels() + "/" + getDrawDuels() + ", H:" + getHits() + "}";
return "{" + NameUtils.getLastnameName(competitor) + " D:" + getWonDuels() + "/"
+ getDrawDuels() + ", H:" + getHits() + ", HL:" + getHitsLost() + "}";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public int compare(ScoreOfCompetitor scoreOfCompetitor1, ScoreOfCompetitor score
return scoreOfCompetitor2.getHits().compareTo(scoreOfCompetitor1.getHits());
}

// Fewer hits lost
if (!Objects.equals(scoreOfCompetitor1.getHitsLost(), scoreOfCompetitor2.getHitsLost())) {
return scoreOfCompetitor1.getDuelsDone().compareTo(scoreOfCompetitor2.getDuelsDone());
}

// More duels done with same score is negative.
if (!Objects.equals(scoreOfCompetitor1.getDuelsDone(), scoreOfCompetitor2.getDuelsDone())) {
return scoreOfCompetitor1.getDuelsDone().compareTo(scoreOfCompetitor2.getDuelsDone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ScoreOfTeam {
private Integer drawDuels = null;
private Integer untieDuels = null;
private Integer hits = null;
private Integer hitsLost = null;
private Integer level = null;
private Integer sortingIndex = null;

Expand Down Expand Up @@ -81,6 +82,7 @@ public void update() {
drawDuels = null;
untieDuels = null;
hits = null;
hitsLost = null;
level = null;
fightsDone = null;
setLevel();
Expand All @@ -91,6 +93,7 @@ public void update() {
setFightsDone();
setUntieDuels();
setHits();
setHitsLost();
}

public void setLevel() {
Expand Down Expand Up @@ -129,6 +132,10 @@ public void setHits() {
hits = fights.stream().mapToInt(fight -> fight.getScore(team)).sum();
}

public void setHitsLost() {
hitsLost = fights.stream().mapToInt(fight -> fight.getScoreAgainst(team)).sum();
}

public void setUntieDuels() {
untieDuels = 0;
unties.forEach(duel -> {
Expand Down Expand Up @@ -211,6 +218,14 @@ public void setHits(Integer hits) {
this.hits = hits;
}

public Integer getHitsLost() {
return hitsLost;
}

public void setHitsLost(Integer hitsLost) {
this.hitsLost = hitsLost;
}

public Integer getLevel() {
return level;
}
Expand All @@ -230,6 +245,7 @@ public void setSortingIndex(Integer sortingIndex) {
@Override
public String toString() {
return "{" + team.getName() + ": Fights:" + getWonFights() + "/" + getDrawFights() + ", Duels: "
+ getWonDuels() + "/" + getDrawDuels() + ", hits:" + getHits() + "*".repeat(Math.max(0, getUntieDuels())) + "}";
+ getWonDuels() + "/" + getDrawDuels() + ", hits:" + getHits() + "*".repeat(Math.max(0, getUntieDuels()))
+ ", hits lost:" + getHitsLost() + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public int compare(ScoreOfTeam scoreOfTeam1, ScoreOfTeam scoreOfTeam2) {
return scoreOfTeam2.getHits().compareTo(scoreOfTeam1.getHits());
}

// Fewer hits lost
if (!Objects.equals(scoreOfTeam1.getHitsLost(), scoreOfTeam2.getHitsLost())) {
return scoreOfTeam1.getHitsLost().compareTo(scoreOfTeam2.getHitsLost());
}

return scoreOfTeam2.getUntieDuels().compareTo(scoreOfTeam1.getUntieDuels());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ public class ScoreTest extends AbstractTestNGSpringContextTests {
@Autowired
private DuelProvider duelProvider;

@Autowired
private GroupConverter groupConverter;

@Autowired
private TeamConverter teamConverter;

@Autowired
private RankingProvider rankingProvider;

Expand Down Expand Up @@ -270,6 +264,57 @@ public void testEuropeanScore() {
resetGroup(groupProvider.getGroups(tournament).get(0), null);
}

@Test(dependsOnMethods = {"createFights"})
public void testEuropeanScoreHitLost() {
tournament.setTournamentScore(new TournamentScore(ScoreType.EUROPEAN));
tournament = tournamentProvider.save(tournament);

final Group groupTest = groupProvider.getGroups(tournament).get(0);

// Team1 vs Team2
groupTest.getFights().get(0).getDuels().get(0).addCompetitor1Score(Score.MEN);
groupTest.getFights().get(0).getDuels().get(0).addCompetitor2Score(Score.MEN);
groupTest.getFights().get(0).getDuels().get(0).addCompetitor2Score(Score.MEN);
// Team3 vs Team2
groupTest.getFights().get(1).getDuels().get(0).addCompetitor1Score(Score.MEN);
groupTest.getFights().get(1).getDuels().get(0).addCompetitor2Score(Score.MEN);
groupTest.getFights().get(1).getDuels().get(1).addCompetitor1Score(Score.MEN);
groupTest.getFights().get(1).getDuels().get(1).addCompetitor2Score(Score.MEN);
// Team3 vs Team4
groupTest.getFights().get(2).getDuels().get(0).addCompetitor1Score(Score.MEN);
groupTest.getFights().get(2).getDuels().get(0).addCompetitor2Score(Score.MEN);
// Team1 vs Team4
groupTest.getFights().get(3).getDuels().get(0).addCompetitor1Score(Score.MEN);
groupTest.getFights().get(3).getDuels().get(0).addCompetitor1Score(Score.MEN);
groupTest.getFights().get(3).getDuels().get(0).addCompetitor2Score(Score.MEN);
// Team1 vs Team3
groupTest.getFights().get(4).getDuels().get(0).addCompetitor1Score(Score.MEN);
groupTest.getFights().get(4).getDuels().get(0).addCompetitor2Score(Score.MEN);
// Team4 vs Team2
groupTest.getFights().get(5).getDuels().get(0).addCompetitor1Score(Score.MEN);
groupTest.getFights().get(5).getDuels().get(0).addCompetitor1Score(Score.MEN);

// Total Team1 1/1F 1/7D 4H 4HL
// Total Team2 1/1F 1/7D 4H 5HL
// Total Team3 0/3F 0/9D 4H 4HL
// Total Team4 1/1F 1/7D 4H 3HL

// finish fights.
groupTest.getFights().forEach(fight -> {
fight.getDuels().forEach(duel -> duel.setFinished(true));
fightProvider.save(fight);
});

// Team04 has fewer hits lost.
List<ScoreOfTeam> scores = rankingProvider.getTeamsScoreRanking(tournament);
Assert.assertEquals(scores.get(0).getTeam(), teamProvider.get(tournament, "Team04").get());
Assert.assertEquals(scores.get(1).getTeam(), teamProvider.get(tournament, "Team01").get());
Assert.assertEquals(scores.get(2).getTeam(), teamProvider.get(tournament, "Team02").get());
Assert.assertEquals(scores.get(3).getTeam(), teamProvider.get(tournament, "Team03").get());

resetGroup(groupProvider.getGroups(tournament).get(0), null);
}

@Test(dependsOnMethods = {"createFights"})
public void testInternationalScore() {
tournament.setTournamentScore(new TournamentScore(ScoreType.INTERNATIONAL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ public Integer getScore(Participant competitor) {
return score;
}

public Integer getScoreAgainst(Participant competitor) {
int score = 0;
score += getDuels().stream().filter(duel ->
(Objects.equals(duel.getCompetitor1(), competitor))).mapToInt(Duel::getCompetitor2ScoreValue).sum();
score += getDuels().stream().filter(duel ->
(Objects.equals(duel.getCompetitor2(), competitor))).mapToInt(Duel::getCompetitor1ScoreValue).sum();
return score;
}

public Integer getDrawDuels(Participant competitor) {
return (int) getDuels().stream().filter(duel -> duel.getWinner() == 0
&& (Objects.equals(duel.getCompetitor1(), competitor) || Objects.equals(duel.getCompetitor2(), competitor))).count();
Expand Down Expand Up @@ -271,6 +280,16 @@ public Integer getScore(Team team) {
return 0;
}

public Integer getScoreAgainst(Team team) {
if (Objects.equals(team1, team)) {
return getScoreTeam2();
}
if (Objects.equals(team2, team)) {
return getScoreTeam1();
}
return 0;
}

public Integer getScoreTeam1() {
return getDuels().stream().mapToInt(Duel::getCompetitor1ScoreValue).sum();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.softwaremagico.kt.EchoWebSocketController;
import com.softwaremagico.kt.core.providers.AuthenticatedUserProvider;
import com.softwaremagico.kt.persistence.entities.AuthenticatedUser;
import com.softwaremagico.kt.persistence.entities.IAuthenticatedUser;
import com.softwaremagico.kt.rest.controllers.AuthenticatedUserController;
import com.softwaremagico.kt.rest.security.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -103,7 +102,7 @@ public void authentication() {
authenticatedUser = authenticatedUserController.createUser(null, USER_NAME, USER_FIRST_NAME, USER_LAST_NAME, USER_PASSWORD, USER_ROLES);

headers = new WebSocketHttpHeaders();
headers.set("Authorization", "Bearer " + jwtTokenUtil.generateAccessToken((IAuthenticatedUser) authenticatedUser, "127.0.0.1"));
headers.set("Authorization", "Bearer " + jwtTokenUtil.generateAccessToken(authenticatedUser, "127.0.0.1"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<th class="competitor-ranking-header">{{ 'competitor' | translate }}</th>
<th class="competitor-ranking-header">{{ 'duelsWon' | translate }}</th>
<th class="competitor-ranking-header">{{ 'duelsDraw' | translate }}</th>
<th class="competitor-ranking-header">{{ 'histsWon' | translate }}</th>
<th class="competitor-ranking-header">{{ 'hitsWon' | translate }}</th>
<th *ngIf="tournament && tournament.tournamentScore && tournament.tournamentScore.scoreType == ScoreType.EUROPEAN" class="competitor-ranking-header">{{ 'hitsLost' | translate }}</th>
<th class="competitor-ranking-header">{{ 'totalFights' | translate }}</th>
</tr>
</thead>
Expand All @@ -36,6 +37,9 @@
<td [ngClass]="{'selected': competitor?.id === scoreOfCompetitor.competitor.id}"
class="competitor-ranking-value">{{ scoreOfCompetitor.hits }}{{ (scoreOfCompetitor.untieHits ? "*" : "") }}
</td>
<td *ngIf="tournament && tournament.tournamentScore && tournament.tournamentScore.scoreType == ScoreType.EUROPEAN" [ngClass]="{'selected': competitor?.id === scoreOfCompetitor.competitor.id}"
class="competitor-ranking-value">{{ scoreOfCompetitor.hitsLost }}
</td>
<td [ngClass]="{'selected': competitor?.id === scoreOfCompetitor.competitor.id}"
class="competitor-ranking-value">{{ scoreOfCompetitor.totalFights }}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {RbacService} from "../../services/rbac/rbac.service";
import {Participant} from "../../models/participant";
import {DOCUMENT} from "@angular/common";
import {Club} from "../../models/club";
import {ScoreType} from "../../models/score-type";

@Component({
selector: 'app-competitors-ranking',
Expand Down Expand Up @@ -111,4 +112,6 @@ export class CompetitorsRankingComponent extends RbacBasedComponent implements O
daysChanged(): void {
this.getRanking();
}

protected readonly ScoreType = ScoreType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<th class="team-ranking-header">{{ 'fightsDraw' | translate }}</th>
<th class="team-ranking-header">{{ 'duelsWon' | translate }}</th>
<th class="team-ranking-header">{{ 'duelsDraw' | translate }}</th>
<th class="team-ranking-header">{{ 'histsWon' | translate }}</th>
<th class="team-ranking-header">{{ 'hitsWon' | translate }}</th>
<th *ngIf="tournament.tournamentScore && tournament.tournamentScore.scoreType == ScoreType.EUROPEAN" class="team-ranking-header">{{ 'hitsLost' | translate }}</th>
</tr>
</thead>
<tr *ngFor="let teamScore of teamScores; let i = index">
Expand All @@ -30,6 +31,7 @@
<td class="team-ranking-value">{{ teamScore.wonDuels }}</td>
<td class="team-ranking-value">{{ teamScore.drawDuels }}</td>
<td class="team-ranking-value">{{ teamScore.hits }}{{ (teamScore.untieDuels ? "*" : "") }}</td>
<td *ngIf="tournament.tournamentScore && tournament.tournamentScore.scoreType == ScoreType.EUROPEAN" class="team-ranking-value">{{ teamScore.hitsLost }}</td>
</tr>
</table>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {TournamentExtendedProperty} from "../../models/tournament-extended-prope
import {MessageService} from "../../services/message.service";
import {Router} from "@angular/router";
import {NameUtilsService} from "../../services/name-utils.service";
import {ScoreType} from "../../models/score-type";

@Component({
selector: 'app-team-ranking',
Expand Down Expand Up @@ -166,4 +167,6 @@ export class TeamRankingComponent extends RbacBasedComponent implements OnInit {
}
return teamMembers;
}

protected readonly ScoreType = ScoreType;
}
Loading
Loading