|
|
@ -14,6 +14,7 @@ import org.springframework.lang.NonNull; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.function.ToLongFunction; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
@ -29,7 +30,7 @@ public class ChessComService { |
|
|
|
} |
|
|
|
|
|
|
|
@NonNull |
|
|
|
public List<Game> getLatestGamesBetweenPlayers(@NonNull Match match, int minAmountOfGames, int maxAmountOfMonths) { |
|
|
|
public List<Game> getLatestGamesBetweenPlayers(@NonNull Match match, int amountOfGames, int maxAmountOfMonths) { |
|
|
|
List<Game> games = new ArrayList<>(); |
|
|
|
for (String archiveUrl : getLatestArchiveUrls(match.getPlayer1(), maxAmountOfMonths)) { |
|
|
|
List<ChessComGame> chessComGames = getChessComGames(archiveUrl).stream() |
|
|
@ -41,10 +42,14 @@ public class ChessComService { |
|
|
|
games.addAll(chessComGames.stream() |
|
|
|
.map(chessComGame -> getGame(chessComGame, match)) |
|
|
|
.collect(Collectors.toList())); |
|
|
|
if (games.size() >= minAmountOfGames) { |
|
|
|
if (games.size() >= amountOfGames) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
games.sort(Comparator.comparingLong(game -> game.getGameInfo().getEndTime())); |
|
|
|
if (games.size() > amountOfGames) { |
|
|
|
games = games.subList(games.size() - amountOfGames, games.size()); |
|
|
|
} |
|
|
|
return games; |
|
|
|
} // TODO: find exactly two games of each time control |
|
|
|
|
|
|
@ -97,6 +102,7 @@ public class ChessComService { |
|
|
|
gameInfo.setChessComId(ChessComUtils.getGameId(chessComGame)); |
|
|
|
gameInfo.setTimeControl(chessComGame.getTimeControl()); |
|
|
|
gameInfo.setFen(chessComGame.getFen()); |
|
|
|
gameInfo.setEndTime(chessComGame.getEndTime()); |
|
|
|
gameInfo.setGame(game); |
|
|
|
|
|
|
|
return game; |
|
|
|