Search in sources :

Example 1 with no.stelar7.api.r4j.pojo.lol.match.v5

use of no.stelar7.api.r4j.pojo.lol.match.v5 in project L4J8 by stelar7.

the class TestVALMatch method generateRecentGamesData.

@Test
@Disabled
public void generateRecentGamesData() throws IOException {
    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.INFO);
    while (true) {
        DataCall.getCacheProvider().clear(URLEndpoint.V1_VAL_MATCH_BY_ID, new HashMap<>());
        Map<String, JsonElement> matches = new HashMap<>();
        Map<String, JsonElement> players = new HashMap<>();
        R4J api = new R4J(SecretFile.CREDS);
        VALMatchAPI matchAPI = api.getVALAPI().getMatchAPI();
        RecentMatchList recentMatches = matchAPI.getRecentMatches(ValorantShard.EU, GameQueueType.COMPETITIVE);
        List<String> matchIds = recentMatches.getMatchIds().stream().limit(100).collect(Collectors.toList());
        int max = matchIds.size();
        int current = 0;
        for (String matchId : matchIds) {
            System.out.println("Working on match " + (++current) + "/" + max);
            VALMatch match = matchAPI.getMatch(ValorantShard.EU, matchId);
            JsonElement matchJson = Utils.getGson().toJsonTree(match);
            matches.put(matchId, matchJson);
            for (Player player : match.getPlayers()) {
                RiotAccount account = api.getAccountAPI().getAccountByPUUID(RegionShard.EUROPE, player.getPUUID());
                JsonElement accountJson = Utils.getGson().toJsonTree(account);
                players.put(account.getPUUID(), accountJson);
            }
        }
        JsonArray matchJson = new JsonArray();
        for (JsonElement value : matches.values()) {
            matchJson.add(value);
        }
        JsonArray playerJson = new JsonArray();
        for (JsonElement value : players.values()) {
            playerJson.add(value);
        }
        JsonObject obj = new JsonObject();
        obj.add("players", playerJson);
        obj.add("matches", matchJson);
        Path outputPath = Paths.get("C:\\cdragon\\valorant\\" + recentMatches.getGeneratedAt() + ".json");
        Files.createDirectories(outputPath.getParent());
        Files.write(outputPath, Utils.getGson().toJson(obj).getBytes(StandardCharsets.UTF_8));
    }
}
Also used : VALMatchAPI(no.stelar7.api.r4j.impl.val.VALMatchAPI) R4J(no.stelar7.api.r4j.impl.R4J) URLEndpoint(no.stelar7.api.r4j.basic.constants.api.URLEndpoint) RiotAccount(no.stelar7.api.r4j.pojo.shared.RiotAccount)

Example 2 with no.stelar7.api.r4j.pojo.lol.match.v5

use of no.stelar7.api.r4j.pojo.lol.match.v5 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)

Aggregations

URLEndpoint (no.stelar7.api.r4j.basic.constants.api.URLEndpoint)2 CacheLifetimeHint (no.stelar7.api.r4j.basic.cache.CacheLifetimeHint)1 R4J (no.stelar7.api.r4j.impl.R4J)1 MatchListBuilder (no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder)1 SpectatorBuilder (no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder)1 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)1 VALMatchAPI (no.stelar7.api.r4j.impl.val.VALMatchAPI)1 LOLMatch (no.stelar7.api.r4j.pojo.lol.match.v5.LOLMatch)1 Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)1 RiotAccount (no.stelar7.api.r4j.pojo.shared.RiotAccount)1