use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.
the class CheckNormalGameForWinTest method testFindSelfInNormalGame.
@Test
@Ignore
public void testFindSelfInNormalGame() {
Summoner dev = new SummonerBuilder().withPlatform(Platform.NA1).withName("devitgg").get();
List<MatchReference> refs = new MatchListBuilder().withPlatform(Platform.NA1).withAccountId(dev.getAccountId()).get();
for (MatchReference current : refs) {
Match fullGame = current.getFullMatch();
List<Participant> candidates = new ArrayList<>();
for (Participant participant : fullGame.getParticipants()) {
if (participant.getChampionId() == current.getChampionId()) {
candidates.add(participant);
}
}
candidates.removeIf(candidate -> candidate.getTimeline().getLane() != current.getLane());
candidates.removeIf(candidate -> candidate.getTimeline().getRole() != current.getRole());
if (candidates.size() == 1) {
Participant self = candidates.get(0);
System.out.println("I " + (self.getStats().isWinner() ? "won!" : "lost :("));
} else {
System.out.println("Unable to find self!");
}
}
}
use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.
the class CheckNormalGameForWinTest method testFindSelfAfterNormalGame.
@Test
@Ignore
public void testFindSelfAfterNormalGame() {
Summoner dev = new SummonerBuilder().withPlatform(Platform.NA1).withName("devitgg").get();
while (new SpectatorBuilder().withPlatform(Platform.NA1).withSummonerId(dev.getSummonerId()).getCurrentGame() != null) {
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
List<MatchReference> refs = new MatchListBuilder().withPlatform(Platform.NA1).withAccountId(dev.getAccountId()).get();
for (MatchReference current : refs) {
Match fullGame = current.getFullMatch();
List<Participant> candidates = new ArrayList<>();
for (Participant participant : fullGame.getParticipants()) {
if (participant.getChampionId() == current.getChampionId()) {
candidates.add(participant);
}
}
candidates.removeIf(candidate -> candidate.getTimeline().getLane() != current.getLane());
candidates.removeIf(candidate -> candidate.getTimeline().getRole() != current.getRole());
if (candidates.size() == 1) {
Participant self = candidates.get(0);
System.out.println("I " + (self.getStats().isWinner() ? "won!" : "lost :("));
} else {
System.out.println("Unable to find self!");
}
}
}
use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.
the class FrameToImageTest method generateMinimap.
private void generateMinimap(Match match) {
// Load map data
try {
BufferedImage image = ImageIO.read(new URL(api.getImageAPI().getMap("map" + match.getMap().getId(), null, null)));
Rectangle mapBounds = match.getMap().getBounds();
// load icon data
int championSquareOffset = (int) (120d / 4d);
int championSquarePadding = (int) (120d / 12d);
Map<Integer, Item> items = api.getStaticAPI().getItems(Platform.EUW1, null, null, null).getData();
Map<Integer, StaticChampion> champs = api.getStaticAPI().getChampions(Platform.EUW1, null, null, null);
Map<Integer, BufferedImage> championImages = new HashMap<>();
Map<Integer, BufferedImage> itemImages = new HashMap<>();
match.getParticipants().forEach(p -> {
try {
BufferedImage before = ImageIO.read(new URL(api.getImageAPI().getSquare(champs.get(p.getChampionId()), null, null)));
double scaleFactor = 1d / 4d;
BufferedImage after = scaleImage(before, scaleFactor);
championImages.put(p.getParticipantId(), after);
} catch (IOException e) {
e.printStackTrace();
}
});
items.values().parallelStream().forEach(i -> {
try {
BufferedImage before = ImageIO.read(new URL(api.getImageAPI().getItem(i, null, null)));
double scaleFactor = 1d / 2d;
BufferedImage after = scaleImage(before, scaleFactor);
itemImages.put(i.getId(), after);
} catch (IOException e) {
e.printStackTrace();
}
});
if (turretIcon == null) {
try {
turretIcon = new EnumMap<>(TeamType.class);
BufferedImage temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/turret_100.png"));
turretIcon.put(TeamType.BLUE, scaleImage(temp, .4));
temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/turret_200.png"));
turretIcon.put(TeamType.RED, scaleImage(temp, .4));
} catch (IOException e) {
e.printStackTrace();
}
}
if (inhibIcon == null) {
try {
inhibIcon = new EnumMap<>(TeamType.class);
BufferedImage temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/inhibitor_building_100.png"));
inhibIcon.put(TeamType.BLUE, scaleImage(temp, .25));
temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/inhibitor_building_200.png"));
inhibIcon.put(TeamType.RED, scaleImage(temp, .25));
} catch (IOException e) {
e.printStackTrace();
}
}
if (swordIcon == null) {
try {
swordIcon = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/css/resources/images/scoreboardicon_score.png"));
swordIcon = scaleImage(swordIcon, 1.5);
} catch (IOException e) {
e.printStackTrace();
}
}
Map<Integer, List<Pair<Item, Integer>>> inventory = new HashMap<>();
Map<Integer, Triplet<Integer>> kda = new HashMap<>();
IntStream.rangeClosed(1, 10).forEach(i -> kda.put(i, new Triplet<>(0, 0, 0)));
match.getTimeline().getFrames().forEach(frame -> {
try {
// Generate file output data
String path = match.getPlatform().getValue() + File.separator + match.getMatchId();
File outputFile = new File(path, frame.getTimestamp() + ".png");
outputFile.getParentFile().mkdirs();
// Make sure map is large enough for all the data
int imgW = image.getWidth() + (championSquareOffset + championSquarePadding) * 4;
int imgH = (image.getHeight() + (championSquareOffset + championSquarePadding) * 11);
BufferedImage newMap = new BufferedImage(imgW, imgH, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) newMap.getGraphics();
// set background
g.setColor(Color.black);
g.fillRect(0, 0, newMap.getWidth(), newMap.getHeight());
// set separator line
g.setColor(Color.white);
g.fillRect(0, image.getHeight() + (int) (championSquareOffset / 1.5f) + championSquarePadding / 2, newMap.getWidth(), championSquareOffset / 4);
g.fillRect(image.getWidth() + (int) (championSquareOffset / 1.5f), 0, championSquareOffset / 4, newMap.getHeight());
// set minimap
g.drawImage(image, 0, 0, null);
int[] killCount = { 0 };
frame.getEvents().forEach(me -> {
Predicate<Pair<Item, Integer>> itemIdFilter = p -> p.getKey().getId() == me.getItemId();
Predicate<Pair<Item, Integer>> itemAfterFilter = p -> p.getKey().getId() == me.getItemAfter();
Predicate<Pair<Item, Integer>> itemBeforeFilter = p -> p.getKey().getId() == me.getItemBefore();
if (!inhibDestroyTime.isEmpty()) {
Map<Pair<Integer, Integer>, Long> clone = new HashMap<>(inhibDestroyTime);
clone.forEach((k, v) -> {
if (v + (60000 * 5) <= me.getTimestamp()) {
inhib.add(k);
inhibDestroyTime.remove(k);
}
});
}
switch(me.getEventType()) {
case ITEM_PURCHASED:
{
handlePurchaseEvent(items, inventory, me, itemIdFilter);
break;
}
case ITEM_DESTROYED:
case ITEM_SOLD:
{
handleSoldEvent(inventory, me, itemIdFilter);
break;
}
case ITEM_UNDO:
{
handleUndoEvent(items, inventory, me, itemBeforeFilter, itemAfterFilter);
break;
}
case CHAMPION_KILL:
{
handleKillEvent(image, mapBounds, championSquareOffset, championSquarePadding, championImages, g, killCount, me, kda);
break;
}
// ignored events
case SKILL_LEVEL_UP:
case WARD_KILL:
case WARD_PLACED:
case ELITE_MONSTER_KILL:
{
break;
}
case BUILDING_KILL:
{
handleBuildingEvent(me);
break;
}
default:
{
System.out.println(me);
break;
}
}
});
turrets.forEach(p -> {
BufferedImage turretImage = turretIcon.get(turretTeam.get(p));
int xPos = scale(p.getKey(), (int) mapBounds.getX(), (int) mapBounds.getWidth(), 0, image.getWidth());
int yPos = image.getHeight() - scale(p.getValue(), (int) mapBounds.getY(), (int) mapBounds.getHeight(), 0, image.getHeight());
int xOffset = (int) (-turretImage.getWidth() / 1.25f);
int yOffset = -(turretImage.getHeight() / 2);
xPos += xOffset;
yPos += yOffset;
g.drawImage(turretImage, xPos, yPos, null);
});
inhib.forEach(p -> {
BufferedImage inhibImage = inhibIcon.get(inhibTeam.get(p));
int xPos = scale(p.getKey(), (int) mapBounds.getX(), (int) mapBounds.getWidth(), 0, image.getWidth());
int yPos = image.getHeight() - scale(p.getValue(), (int) mapBounds.getY(), (int) mapBounds.getHeight(), 0, image.getHeight());
int xOffset = (int) (-inhibImage.getWidth() / 1.1f);
int yOffset = -(inhibImage.getHeight() / 3);
xPos += xOffset;
yPos += yOffset;
g.drawImage(inhibImage, xPos, yPos, null);
});
frame.getParticipantFrames().values().forEach(mpf -> {
drawPosition(image, mapBounds, g, mpf, championImages);
drawInventory(image, championSquareOffset, championSquarePadding, itemImages, inventory, g, mpf, championImages);
drawKDA(kda, image, g, championSquareOffset, championSquarePadding);
});
for (int i = 0; i < killList.size(); i++) {
Pair<Integer, Integer> k = killList.get(i);
int xPos = k.getKey();
int yPos = k.getValue();
g.setColor(Color.red);
g.fillOval(xPos - 8, yPos - 8, 16, 16);
g.setColor(Color.black);
g.drawString(String.valueOf(i + 1), xPos - 3, yPos + 5);
g.drawOval(xPos - 8, yPos - 8, 16, 16);
}
killList.clear();
ImageIO.write(newMap, "png", outputFile);
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.
the class TournamentTest method testPostGameData.
@Test
public void testPostGameData() {
final List<Long> tournamentCodeMatchIds = this.api.getMatchIds(Constants.TEST_TOURNAMENT_CODES[0]);
final Match matchDetail = this.api.getMatchInfo(Platform.EUW1, Constants.TEST_TOURNAMENT_CODES[0], tournamentCodeMatchIds.get(0));
}
use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.
the class CacheTest method doCacheStuff.
private void doCacheStuff() throws InterruptedException {
List<MatchReference> recents = new MatchListBuilder().withPlatform(Constants.TEST_PLATFORM[0]).withAccountId(Constants.TEST_ACCOUNT_IDS[0]).get();
if (recents.isEmpty()) {
return;
}
MatchReference ref = recents.get(0);
System.out.println("Starting timer");
long start = stopwatch.runtime(TimeUnit.NANOSECONDS);
Match url = ref.getFullMatch();
System.out.printf("1x url fetch time: %dns%n", stopwatch.runtime(TimeUnit.NANOSECONDS) - start);
start = stopwatch.runtime(TimeUnit.NANOSECONDS);
Match cached = ref.getFullMatch();
System.out.printf("1x cache fetch time: %dns%n", stopwatch.runtime(TimeUnit.NANOSECONDS) - start);
if (!url.equals(cached)) {
throw new RuntimeException("CACHE IS BROKEN!!!!");
}
start = stopwatch.runtime(TimeUnit.NANOSECONDS);
for (int i = 0; i < 10; i++) {
ref.getFullMatch();
}
System.out.printf("10x cache fetch time: %dns%n", stopwatch.runtime(TimeUnit.NANOSECONDS) - start);
System.out.println();
start = stopwatch.runtime(TimeUnit.NANOSECONDS);
ref.getFullMatch();
System.out.printf("1x cache fetch time: %dns%n", stopwatch.runtime(TimeUnit.NANOSECONDS) - start);
System.out.println();
System.out.println("clearing cache");
System.out.println();
DataCall.getCacheProvider().clear(URLEndpoint.V3_MATCH);
start = stopwatch.runtime(TimeUnit.NANOSECONDS);
ref.getFullMatch();
System.out.printf("1x url fetch time: %dns%n", stopwatch.runtime(TimeUnit.NANOSECONDS) - start);
start = stopwatch.runtime(TimeUnit.NANOSECONDS);
for (int i = 0; i < 10; i++) {
ref.getFullMatch();
}
System.out.printf("10x cache fetch time: %dns%n", stopwatch.runtime(TimeUnit.NANOSECONDS) - start);
System.out.println();
System.out.println("Fetching 3 aditional matches");
recents.get(1).getFullMatch();
recents.get(2).getFullMatch();
recents.get(3).getFullMatch();
System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V3_MATCH));
System.out.println("Waiting for cache timeout");
TimeUnit.SECONDS.sleep(5);
System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V3_MATCH));
System.out.println("Re-fetching cached items");
start = stopwatch.runtime(TimeUnit.NANOSECONDS);
recents.get(0).getFullMatch();
recents.get(1).getFullMatch();
recents.get(2).getFullMatch();
recents.get(3).getFullMatch();
System.out.printf("4x fetches took: %dns%n", stopwatch.runtime(TimeUnit.NANOSECONDS) - start);
System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V3_MATCH));
System.out.println();
}
Aggregations