Search in sources :

Example 1 with VALMatch

use of no.stelar7.api.r4j.pojo.val.match.VALMatch in project L4J8 by stelar7.

the class VALMatchAPI method getMatch.

public VALMatch getMatch(ValorantShard platform, String gameId) {
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, gameId).withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getVALAPIKey()).withEndpoint(URLEndpoint.V1_VAL_MATCH_BY_ID).withPlatform(platform);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", platform);
    data.put("gameid", gameId);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_VAL_MATCH_BY_ID, data);
    if (chl.isPresent()) {
        return (VALMatch) chl.get();
    }
    try {
        VALMatch match = (VALMatch) builder.build();
        data.put("value", match);
        DataCall.getCacheProvider().store(URLEndpoint.V1_VAL_MATCH_BY_ID, data);
        return match;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : VALMatch(no.stelar7.api.r4j.pojo.val.match.VALMatch)

Example 2 with VALMatch

use of no.stelar7.api.r4j.pojo.val.match.VALMatch in project L4J8 by stelar7.

the class TestVALMatch method testGetSingleById.

@Test
public void testGetSingleById() {
    R4J api = new R4J(SecretFile.CREDS);
    VALMatchAPI matchAPI = api.getVALAPI().getMatchAPI();
    VALMatch match = matchAPI.getMatch(ValorantShard.AP, "c4eb3e3d-d175-4b73-b7d4-279374d1b19b");
    System.out.println();
}
Also used : VALMatchAPI(no.stelar7.api.r4j.impl.val.VALMatchAPI) R4J(no.stelar7.api.r4j.impl.R4J)

Example 3 with VALMatch

use of no.stelar7.api.r4j.pojo.val.match.VALMatch 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 4 with VALMatch

use of no.stelar7.api.r4j.pojo.val.match.VALMatch in project L4J8 by stelar7.

the class TestVALMatch method getSingle.

@Test
public void getSingle() throws IOException {
    R4J api = new R4J(SecretFile.CREDS);
    VALMatchAPI matchAPI = api.getVALAPI().getMatchAPI();
    RiotAccount account = api.getAccountAPI().getAccountByTag(RegionShard.EUROPE, "Coup De Graçe", "EUNE");
    List<MatchReference> matchlist = matchAPI.getMatchList(ValorantShard.EU, account.getPUUID());
    VALMatch match = matchAPI.getMatch(ValorantShard.EU, matchlist.get(0).getMatchId());
    Files.write(Paths.get(System.getProperty("user.home") + "\\Desktop\\game.json"), Utils.getGson().toJson(match).getBytes(StandardCharsets.UTF_8));
    System.out.println(match);
}
Also used : RiotAccount(no.stelar7.api.r4j.pojo.shared.RiotAccount) VALMatchAPI(no.stelar7.api.r4j.impl.val.VALMatchAPI) R4J(no.stelar7.api.r4j.impl.R4J)

Example 5 with VALMatch

use of no.stelar7.api.r4j.pojo.val.match.VALMatch in project L4J8 by stelar7.

the class TestVALMatch method getDeep.

@Test
public void getDeep() {
    R4J api = new R4J(SecretFile.CREDS);
    VALMatchAPI matchAPI = api.getVALAPI().getMatchAPI();
    RiotAccount account = api.getAccountAPI().getAccountByTag(RegionShard.EUROPE, "Jbzz", "EUW");
    List<String> ids = new ArrayList<>();
    ids.add(account.getPUUID());
    List<MatchReference> matchlist = matchAPI.getMatchList(ValorantShard.EU, account.getPUUID());
    matchlist.forEach(m -> {
        VALMatch match = matchAPI.getMatch(ValorantShard.EU, m.getMatchId());
        match.getRoundResults().forEach(r -> {
            if (match.getPlayers().stream().anyMatch(p -> p.getCharacter() == null)) {
                System.out.println();
            }
            r.getPlayerStats().forEach(s -> {
                if (s.getAbility().getGrenadeEffects() != null && !s.getAbility().getGrenadeEffects().equals("null")) {
                    System.out.println();
                }
            });
        });
        match.getPlayers().forEach(p -> ids.add(p.getPUUID()));
    });
    ids.forEach(puuid -> {
        List<MatchReference> matches = matchAPI.getMatchList(ValorantShard.EU, puuid);
        matches.forEach(m -> {
            VALMatch match = matchAPI.getMatch(ValorantShard.EU, m.getMatchId());
            match.getRoundResults().forEach(r -> {
                r.getPlayerStats().forEach(s -> {
                    if (s.getAbility().getGrenadeEffects() != null && !s.getAbility().getGrenadeEffects().equals("null")) {
                        System.out.println();
                    }
                });
            });
        });
    });
}
Also used : RiotAccount(no.stelar7.api.r4j.pojo.shared.RiotAccount) VALMatchAPI(no.stelar7.api.r4j.impl.val.VALMatchAPI) R4J(no.stelar7.api.r4j.impl.R4J)

Aggregations

R4J (no.stelar7.api.r4j.impl.R4J)4 VALMatchAPI (no.stelar7.api.r4j.impl.val.VALMatchAPI)4 RiotAccount (no.stelar7.api.r4j.pojo.shared.RiotAccount)3 URLEndpoint (no.stelar7.api.r4j.basic.constants.api.URLEndpoint)1 VALMatch (no.stelar7.api.r4j.pojo.val.match.VALMatch)1