Search in sources :

Example 1 with RaidBoss

use of com.ixale.starparse.domain.RaidBoss in project StarParse by Ixale.

the class RankTest method testFull.

@Test
public void testFull() {
    Raid raid = new WorldBoss();
    RaidBoss boss = raid.getBosses().get(4);
    assertEquals(boss.getRaidBossName(), RaidBossName.ColossalMonolith);
    assertEquals(boss.getMode(), Mode.SM);
    assertEquals(boss.getSize(), Size.Eight);
    service.initialize(Config.DEFAULT_SERVER_HOST);
    service.getRank(boss, RankType.DPS, CharacterDiscipline.Darkness, 360001, 2485, (rc) -> {
        assertNotNull(rc);
        assertNull(rc.getReason());
        assertTrue(rc.getPercent() >= 0 && rc.getPercent() <= 100);
        assertEquals(RankType.DPS, rc.getType());
    });
    try {
        service.getRank(boss, RankType.DTPS, CharacterDiscipline.CombatMedic, 360001, 2485, (rc) -> fail("Healer should not have DTPS"));
    } catch (Exception e) {
    // OK, healer should not have DTPS (yet)
    }
    service.getRank(boss, RankType.DTPS, CharacterDiscipline.Defense, 360001, 2485, (rc) -> {
        assertNotNull(rc);
        assertNull(rc.getReason());
        assertTrue(rc.getPercent() > 0 && rc.getPercent() < 100);
        assertEquals(RankType.DTPS, rc.getType());
    });
    service.getRank(boss, RankType.EHPS, CharacterDiscipline.CombatMedic, 360001, 2485, (rc) -> {
        assertNotNull(rc);
        assertNull(rc.getReason());
        assertTrue(rc.getPercent() >= 0 && rc.getPercent() <= 100);
        assertEquals(RankType.EHPS, rc.getType());
    });
}
Also used : WorldBoss(com.ixale.starparse.domain.ops.WorldBoss) Raid(com.ixale.starparse.domain.Raid) RaidBoss(com.ixale.starparse.domain.RaidBoss) Test(org.junit.Test)

Example 2 with RaidBoss

use of com.ixale.starparse.domain.RaidBoss in project StarParse by Ixale.

the class RankServiceImpl method getRanking.

private void getRanking(final RaidBoss boss, final RankType type, final CharacterDiscipline discipline, final Consumer<Ranking> callback) {
    final String key = buildKey(boss, type, discipline);
    if (!rankings.containsKey(key)) {
        if (rankingExecutor == null) {
            rankingExecutor = Executors.newSingleThreadExecutor(r -> {
                final Thread worker = new Thread(r, "Ranking Worker");
                worker.setDaemon(true);
                return worker;
            });
        }
        rankingExecutor.execute(() -> {
            try {
                // build remote URL
                final URL url = buildUrl(boss, host, key);
                // fetch from remote
                final String content = FileDownloader.fetchFile(url);
                // parse
                final Ranking ranking = readRanking(content);
                // cache
                rankings.put(key, ranking);
                Platform.runLater(() -> {
                    callback.accept(rankings.get(key));
                });
                if (logger.isDebugEnabled()) {
                    logger.debug("Ranking fetched from remote (" + boss + ", " + type + ", " + discipline + "): " + ranking);
                }
            } catch (Exception e) {
                if (e.getMessage().equals("Read timed out") || e.getMessage().startsWith("Server returned non-OK status: 404")) {
                    // local issue, silently ignore
                    return;
                }
                logger.error("Failed to rank " + key + ": " + e.getMessage(), e);
            }
        });
        return;
    }
    callback.accept(rankings.get(key));
}
Also used : CharacterDiscipline(com.ixale.starparse.domain.CharacterDiscipline) RaidBossName(com.ixale.starparse.domain.RaidBossName) Marshaller(com.ixale.starparse.gui.Marshaller) Logger(org.slf4j.Logger) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Percentile(com.ixale.starparse.domain.Ranking.Percentile) RankService(com.ixale.starparse.service.RankService) Executors(java.util.concurrent.Executors) FileDownloader(com.ixale.starparse.utils.FileDownloader) Platform(javafx.application.Platform) Consumer(java.util.function.Consumer) Reason(com.ixale.starparse.domain.RankClass.Reason) RankClass(com.ixale.starparse.domain.RankClass) Ranking(com.ixale.starparse.domain.Ranking) RaidBoss(com.ixale.starparse.domain.RaidBoss) Service(org.springframework.stereotype.Service) Map(java.util.Map) CharacterClass(com.ixale.starparse.domain.CharacterClass) Mode(com.ixale.starparse.domain.Raid.Mode) ExecutorService(java.util.concurrent.ExecutorService) Ranking(com.ixale.starparse.domain.Ranking) URL(java.net.URL)

Example 3 with RaidBoss

use of com.ixale.starparse.domain.RaidBoss in project StarParse by Ixale.

the class RankTest method testDownload.

@Test
public void testDownload() throws Exception {
    Raid raid = new WorldBoss();
    RaidBoss boss = raid.getBosses().get(1);
    assertEquals(boss.getRaidBossName(), RaidBossName.ColossalMonolith);
    assertEquals(boss.getMode(), Mode.HM);
    assertEquals(boss.getSize(), Size.Sixteen);
    final String key = service.buildKey(boss, RankType.DPS, CharacterDiscipline.InnovativeOrdnance);
    assertEquals("dps_ColossalMonolith_HM_16m_Commando", key);
    final URL url = service.buildUrl(boss, Config.DEFAULT_SERVER_HOST, key);
    final String content = FileDownloader.fetchFile(url);
    assertNotNull(content);
    assertTrue(content.contains("<boss>ColossalMonolith HM 16m</boss>"));
    assertTrue(content.contains("<className>Commando</className>"));
    assertTrue(content.contains("<type>dps</type>"));
    final Ranking r = service.readRanking(content);
    assertNotNull(r);
    assertTrue(r.getMinTick() > 120000);
    final RankClass rc = service.getRank(r, r.getMinTick() + 1, 2485);
    assertNotNull(rc);
    assertNull(rc.getReason());
    assertTrue(rc.getPercent() >= 0 && rc.getPercent() <= 100);
}
Also used : Ranking(com.ixale.starparse.domain.Ranking) RankClass(com.ixale.starparse.domain.RankClass) WorldBoss(com.ixale.starparse.domain.ops.WorldBoss) Raid(com.ixale.starparse.domain.Raid) RaidBoss(com.ixale.starparse.domain.RaidBoss) URL(java.net.URL) Test(org.junit.Test)

Aggregations

RaidBoss (com.ixale.starparse.domain.RaidBoss)3 Raid (com.ixale.starparse.domain.Raid)2 RankClass (com.ixale.starparse.domain.RankClass)2 Ranking (com.ixale.starparse.domain.Ranking)2 WorldBoss (com.ixale.starparse.domain.ops.WorldBoss)2 URL (java.net.URL)2 Test (org.junit.Test)2 CharacterClass (com.ixale.starparse.domain.CharacterClass)1 CharacterDiscipline (com.ixale.starparse.domain.CharacterDiscipline)1 Mode (com.ixale.starparse.domain.Raid.Mode)1 RaidBossName (com.ixale.starparse.domain.RaidBossName)1 Reason (com.ixale.starparse.domain.RankClass.Reason)1 Percentile (com.ixale.starparse.domain.Ranking.Percentile)1 Marshaller (com.ixale.starparse.gui.Marshaller)1 RankService (com.ixale.starparse.service.RankService)1 FileDownloader (com.ixale.starparse.utils.FileDownloader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1