Search in sources :

Example 11 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class CacheTest method doCacheStuff.

private void doCacheStuff() throws InterruptedException {
    // DataCall.getCacheProvider().clear(URLEndpoint.V3_MATCH);
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    loggerContext.getLogger("no.stelar7.api.r4j.basic.calling.DataCallBuilder").setLevel(Level.INFO);
    loggerContext.getLogger("no.stelar7.api.r4j.basic.ratelimiting.BurstRateLimiter").setLevel(Level.OFF);
    loggerContext.getLogger("no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider").setLevel(Level.OFF);
    System.out.println("Fetching a random summoner and their match list");
    String id = new SpectatorBuilder().withPlatform(LeagueShard.EUW1).getFeaturedGames().get(0).getParticipants().get(0).getSummonerName();
    Summoner s = new SummonerBuilder().withPlatform(LeagueShard.EUW1).withName(id).get();
    List<String> recents = new MatchListBuilder().withPlatform(LeagueShard.EUW1).withPuuid(s.getPUUID()).get();
    if (recents.isEmpty()) {
        return;
    }
    String ref = recents.get(0);
    System.out.println("Starting timer");
    long start = System.currentTimeMillis();
    LOLMatch url = LOLMatch.get(LeagueShard.EUW1, ref);
    System.out.printf("1x url fetch time: %dns%n", System.currentTimeMillis() - start);
    start = System.currentTimeMillis();
    LOLMatch cached = LOLMatch.get(LeagueShard.EUW1, ref);
    System.out.printf("1x cache fetch time: %dns%n", System.currentTimeMillis() - start);
    if (!url.equals(cached)) {
        throw new RuntimeException("CACHE IS BROKEN!!!!");
    }
    start = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        LOLMatch.get(LeagueShard.EUW1, ref);
    }
    System.out.printf("10x cache fetch time: %dns%n", System.currentTimeMillis() - start);
    System.out.println();
    start = System.currentTimeMillis();
    LOLMatch.get(LeagueShard.EUW1, ref);
    System.out.printf("1x cache fetch time: %dns%n", System.currentTimeMillis() - start);
    System.out.println();
    System.out.println("clearing cache");
    System.out.println();
    DataCall.getCacheProvider().clear(URLEndpoint.V5_MATCH, Collections.emptyMap());
    start = System.currentTimeMillis();
    LOLMatch.get(LeagueShard.EUW1, ref);
    System.out.printf("1x url fetch time: %dns%n", System.currentTimeMillis() - start);
    start = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        LOLMatch.get(LeagueShard.EUW1, ref);
    }
    System.out.printf("10x cache fetch same item time: %dns%n", System.currentTimeMillis() - start);
    System.out.println();
    System.out.println("Fetching 3 aditional matches");
    LOLMatch.get(LeagueShard.EUW1, recents.get(1));
    LOLMatch.get(LeagueShard.EUW1, recents.get(2));
    LOLMatch.get(LeagueShard.EUW1, recents.get(3));
    System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V5_MATCH, Collections.emptyMap()));
    System.out.println("Waiting for cache timeout");
    TimeUnit.SECONDS.sleep(6);
    System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V5_MATCH, Collections.emptyMap()));
    System.out.println("Re-fetching cached items");
    start = System.currentTimeMillis();
    LOLMatch.get(LeagueShard.EUW1, recents.get(0));
    LOLMatch.get(LeagueShard.EUW1, recents.get(1));
    LOLMatch.get(LeagueShard.EUW1, recents.get(2));
    LOLMatch.get(LeagueShard.EUW1, recents.get(3));
    System.out.printf("4x fetches took: %dns%n", System.currentTimeMillis() - start);
    System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V5_MATCH, Collections.emptyMap()));
    System.out.println();
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) MatchListBuilder(no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder) LOLMatch(no.stelar7.api.r4j.pojo.lol.match.v5.LOLMatch) SpectatorBuilder(no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder) CacheLifetimeHint(no.stelar7.api.r4j.basic.cache.CacheLifetimeHint) URLEndpoint(no.stelar7.api.r4j.basic.constants.api.URLEndpoint)

Example 12 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class MatchHistoryCrawler method insertTeamData.

private void insertTeamData(long matchid, Match match) throws SQLException {
    for (TeamType type : TeamType.values()) {
        TeamStats team = match.getTeamStats(type).get(0);
        tsInsertStatement.setLong(1, matchid);
        tsInsertStatement.setLong(2, team.getTeamType().getValue());
        tsInsertStatement.setBoolean(3, team.isFirstBlood());
        tsInsertStatement.setBoolean(4, team.isFirstTower());
        tsInsertStatement.setBoolean(5, team.isFirstInhibitor());
        tsInsertStatement.setBoolean(6, team.isFirstBaron());
        tsInsertStatement.setBoolean(7, team.isFirstDragon());
        tsInsertStatement.setBoolean(8, team.isFirstRiftHerald());
        tsInsertStatement.setLong(9, team.getTowerKills());
        tsInsertStatement.setLong(10, team.getInhibitorKills());
        tsInsertStatement.setLong(11, team.getBaronKills());
        tsInsertStatement.setLong(12, team.getDragonKills());
        tsInsertStatement.setLong(13, team.getRiftHeraldKills());
        tsInsertStatement.executeUpdate();
        for (BannedChampion ban : team.getBans()) {
            tbInsertStatement.setLong(1, matchid);
            tbInsertStatement.setLong(2, team.getTeamType().getValue());
            tbInsertStatement.setLong(3, ban.getChampionId());
            tbInsertStatement.setLong(4, ban.getPickTurn());
            tbInsertStatement.executeUpdate();
        }
    }
}
Also used : TeamType(no.stelar7.api.l4j8.basic.constants.types.TeamType) BannedChampion(no.stelar7.api.l4j8.pojo.shared.BannedChampion)

Example 13 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class FrameToImageTest method testStuff.

@Test
@Ignore
public void testStuff() {
    DataCall.setCacheProvider(new FileSystemCacheProvider());
    Summoner sum = new SummonerBuilder().withPlatform(Platform.EUW1).withName("stelar7").get();
    LazyList<MatchReference> refs = new MatchListBuilder().withPlatform(sum.getPlatform()).withAccountId(sum.getAccountId()).getLazy();
    Match full = refs.get(0).getFullMatch();
    TowerLocationType.getTowersMap(MapType.SUMMONERS_RIFT).forEach((k, v) -> v.forEach((k2, v2) -> v2.forEach((t, p) -> turretTeam.put(p, t))));
    turretTeam.forEach((k, v) -> turrets.add(k));
    InhibitorLocationType.getInhibMap(MapType.SUMMONERS_RIFT).forEach((k, v) -> v.forEach((t, p) -> inhibTeam.put(p, t)));
    inhibTeam.forEach((k, v) -> inhib.add(k));
    generateMinimap(full);
}
Also used : Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) IntStream(java.util.stream.IntStream) Platform(no.stelar7.api.l4j8.basic.constants.api.Platform) no.stelar7.api.l4j8.basic.utils(no.stelar7.api.l4j8.basic.utils) java.awt.image(java.awt.image) java.util(java.util) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item) no.stelar7.api.l4j8.basic.constants.types(no.stelar7.api.l4j8.basic.constants.types) URL(java.net.URL) Predicate(java.util.function.Predicate) no.stelar7.api.l4j8.pojo.match(no.stelar7.api.l4j8.pojo.match) SummonerBuilder(no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder) AffineTransform(java.awt.geom.AffineTransform) L4J8(no.stelar7.api.l4j8.impl.L4J8) FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider) java.awt(java.awt) List(java.util.List) Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) java.io(java.io) MatchListBuilder(no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder) SecretFile(no.stelar7.api.l4j8.tests.SecretFile) ImageIO(javax.imageio.ImageIO) org.junit(org.junit) StaticChampion(no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion) DataCall(no.stelar7.api.l4j8.basic.calling.DataCall) SummonerBuilder(no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder) MatchListBuilder(no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder) FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)

Example 14 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class UseageTest method testUseage.

@Test
public void testUseage() {
    L4J8 api = new L4J8(SecretFile.CREDS);
    DataCall.setLogLevel(LogLevel.DEBUG);
    DataCall.setCacheProvider(new FileSystemCacheProvider());
    Map<Integer, StaticRune> runeData = api.getStaticAPI().getRunes(Platform.EUW1, null, null, null);
    Map<Integer, StaticMastery> masteriesData = api.getStaticAPI().getMasteries(Platform.EUW1, null, null, null);
    Map<Integer, StaticChampion> championData = api.getStaticAPI().getChampions(Platform.EUW1, null, null, null);
    Summoner stelar7 = new SummonerBuilder().withPlatform(Platform.EUW1).withName("stelar7").get();
    List<MatchReference> some = stelar7.getGames().get();
    MatchReference mostRecentGame = some.stream().max(Comparator.comparing(MatchReference::getTimestamp)).get();
    Match match = mostRecentGame.getFullMatch();
    Participant self = match.getParticipantFromSummonerId(stelar7.getSummonerId());
    List<MatchRune> runes = self.getRunes();
    List<MatchMastery> masteries = self.getMasteries();
    StaticChampion champion = championData.get(mostRecentGame.getChampionId());
    ChampionMastery mastery = stelar7.getChampionMastery(champion.getId());
    boolean didWin = match.didWin(self);
    ParticipantIdentity opponentIdentity = match.getLaneOpponentIdentity(self);
    Participant opponent = match.getParticipantFromParticipantId(opponentIdentity.getParticipantId());
    StaticChampion opponentChampion = championData.get(opponent.getChampionId());
    System.out.format("Player '%s' played their latest game as '%s'%n", stelar7.getName(), champion.getName());
    System.out.format("They have a masteryscore of %s on that champion%n", mastery.getChampionPoints());
    System.out.format("They played in %s, their role was: %s%n", self.getTimeline().getLane(), self.getTimeline().getRole());
    System.out.format("They %s that game%n", didWin ? "won" : "lost");
    System.out.format("They laned against '%s' as '%s'%n", opponentIdentity.getPlayer().getSummonerName(), opponentChampion.getName());
    System.out.format("%nThey used the following runes:%n");
    for (MatchRune rune : runes) {
        String name = runeData.get(rune.getRuneId()).getName();
        System.out.format("Name: '%-45s' Count: %s%n", name, rune.getRank());
    }
    System.out.format("%nThey used the following masteries:%n");
    for (MatchMastery matchMastery : masteries) {
        String name = masteriesData.get(matchMastery.getMasteryId()).getName();
        System.out.format("Name: '%-45s' Level: %s%n", name, matchMastery.getRank());
    }
}
Also used : Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) SummonerBuilder(no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder) StaticChampion(no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion) FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider) L4J8(no.stelar7.api.l4j8.impl.L4J8) StaticRune(no.stelar7.api.l4j8.pojo.staticdata.rune.StaticRune) ChampionMastery(no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery) StaticMastery(no.stelar7.api.l4j8.pojo.staticdata.mastery.StaticMastery) Test(org.junit.Test)

Example 15 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class MatchListTest method testMatchAndMatchList.

@Test
@Ignore
public void testMatchAndMatchList() {
    DataCall.setCacheProvider(new FileSystemCacheProvider());
    DataCall.setLogLevel(LogLevel.INFO);
    // EnumSet.of(GameQueueType.TEAM_BUILDER_RANKED_SOLO);
    Set<GameQueueType> queue = null;
    // EnumSet.of(SeasonType.SEASON_2018);
    Set<SeasonType> season = null;
    // new HashSet<>(Collections.singletonList(40));
    Set<Integer> champ = null;
    // LocalDateTime.now().withHour(0).toEpochSecond(ZoneOffset.UTC) * 1000;//1481108400000L; // start of season 2017
    Long beginTime = null;
    // LocalDateTime.now().withHour(0).plusWeeks(1).toEpochSecond(ZoneOffset.UTC) * 1000; // 604800000 is one week in ms
    Long endTime = null;
    // 0;
    Long beginIndex = null;
    // 100;
    Long endIndex = null;
    MatchListBuilder builder = new MatchListBuilder();
    Summoner sum = new SummonerBuilder().withPlatform(Platform.EUW1).withName("stelar7").get();
    builder = builder.withPlatform(sum.getPlatform()).withAccountId(sum.getAccountId());
    builder = builder.withBeginTime(beginTime).withEndTime(endTime);
    builder = builder.withBeginIndex(beginIndex).withEndIndex(endIndex);
    builder = builder.withQueues(queue).withSeasons(season).withChampions(champ);
    LazyList<MatchReference> all = builder.getLazy();
    MatchBuilder mb = new MatchBuilder();
    TimelineBuilder tb = new TimelineBuilder();
    for (MatchReference reference : all) {
        Match detail = reference.getFullMatch();
    }
}
Also used : Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) SummonerBuilder(no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder) FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)

Aggregations

Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)8 R4J (no.stelar7.api.r4j.impl.R4J)7 SummonerBuilder (no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder)6 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)6 MatchListBuilder (no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder)5 java.util (java.util)4 FileSystemCacheProvider (no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)4 FileSystemCacheProvider (no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)4 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)4 VALMatchAPI (no.stelar7.api.r4j.impl.val.VALMatchAPI)4 java.awt (java.awt)3 AffineTransform (java.awt.geom.AffineTransform)3 java.awt.image (java.awt.image)3 java.io (java.io)3 URL (java.net.URL)3 List (java.util.List)3 Predicate (java.util.function.Predicate)3 IntStream (java.util.stream.IntStream)3 ImageIO (javax.imageio.ImageIO)3 L4J8 (no.stelar7.api.l4j8.impl.L4J8)3