use of no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder 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();
}
use of no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder 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);
}
use of no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder in project L4J8 by stelar7.
the class MatchListTest method testMatchlistAllLazy.
@Test
public void testMatchlistAllLazy() {
DataCall.setCacheProvider(new FileSystemCacheProvider());
DataCall.getCacheProvider().clear(URLEndpoint.V3_MATCHLIST);
for (int i = 0; i < Constants.TEST_ACCOUNT_IDS.length; i++) {
List<MatchReference> list = new MatchListBuilder().withAccountId(Constants.TEST_ACCOUNT_IDS[i]).withPlatform(Constants.TEST_PLATFORM[i]).getLazy();
Assert.assertTrue("LazyList loaded data?!", list.isEmpty());
list.get(51);
Assert.assertTrue("LazyList didnt load data?!", !list.isEmpty());
}
}
use of no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder 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();
}
}
use of no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder in project L4J8 by stelar7.
the class AsyncTest method testAsync.
@Test
@Ignore
public void testAsync() {
List<CompletableFuture> futures = new ArrayList<>();
for (int i = 0; i < 100; i++) {
futures.add(supplyAsync(() -> new SummonerBuilder().withPlatform(Platform.EUW1).withAccountId(Constants.TEST_ACCOUNT_IDS[1]).get()).thenAccept(this::handleSummonerCallback));
}
futures.add(supplyAsync(() -> new MatchListBuilder().withPlatform(Platform.EUW1).withAccountId(Constants.TEST_ACCOUNT_IDS[1]).get()).thenAccept(this::handleMatchCallback));
CompletableFuture spinner = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
spinner.join();
}
Aggregations