Search in sources :

Example 1 with CacheStatic

use of fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic in project JCELechat by guiguilechat.

the class InsuranceEval method main.

@SuppressWarnings("unused")
public static void main(String[] args) {
    CacheStatic cache = ESIStatic.INSTANCE.cache();
    ListHolder<R_get_insurance_prices> prices = cache.insurance.prices().filter(ins -> ins.levels[0].cost > 0);
    MapHolder<Integer, R_get_insurance_prices> id2Data = prices.toMap(price -> price.type_id);
    MapHolder<Integer, Float> id2Payout0 = prices.toMap(price -> price.type_id, price -> price.levels[0].payout);
    MapHolder<Integer, R_get_universe_types_type_id> id2Type = id2Data.keys().unpackItems(id -> cache.universe.types(id)).toMap(t -> t.type_id);
    Map<Integer, R_get_universe_types_type_id> types = id2Type.get();
// for (Entry<Integer, R_get_insurance_prices> e : id2Data.entries().get())
// {
// R_get_insurance_prices_levels level0 = e.getValue().levels[0];
// System.out.println(types.get(e.getKey()).name + "\t" + level0.payout /
// level0.cost + "\t" + level0.cost
// + "\t" + level0.payout + "\t" + level0.name);
// }
}
Also used : R_get_insurance_prices(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_insurance_prices) R_get_universe_types_type_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_types_type_id) Map(java.util.Map) ListHolder(fr.lelouet.tools.holders.interfaces.collections.ListHolder) CacheStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic) ESIStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic) MapHolder(fr.lelouet.tools.holders.interfaces.collections.MapHolder) R_get_insurance_prices(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_insurance_prices) CacheStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic) R_get_universe_types_type_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_types_type_id)

Example 2 with CacheStatic

use of fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic in project JCELechat by guiguilechat.

the class NPCsTranslater method translate.

private static void translate(LinkedHashMap<Integer, Eagents> eagents, LinkedHashMap<String, Agent> agents, LinkedHashMap<String, Corporation> corporations, LinkedHashMap<Integer, LPOffer> offers) {
    ESIAccess esi = ESIAccess.INSTANCE;
    CacheStatic cache = ESIStatic.INSTANCE.cache();
    // prefetch
    MapHolder<Integer, R_get_corporations_corporation_id> corporationsHolder = ((ListHolder<Integer>) cache.corporations.npccorps().follow(l -> {
        l.parallelStream().forEach(cache.corporations::get);
    })).toMap(i -> i, i -> cache.corporations.get(i).get());
    MapHolder<Integer, R_get_universe_factions> factionsHolder = cache.universe.factions().toMap(f -> f.faction_id);
    eagents.values().parallelStream().map(ag -> ag.locationID).distinct().forEach(lid -> Location.resolve(null, lid).system());
    // 
    LinkedHashMap<Integer, EnpcCorporations> ecorps = EnpcCorporations.load();
    Map<Integer, String> idx2name = EinvNames.loadById();
    Map<Integer, R_get_corporations_corporation_id> npcCorps = corporationsHolder.get();
    Map<Integer, R_get_universe_factions> factionById = factionsHolder.get();
    Map<Integer, Location> agentsLocation = eagents.entrySet().parallelStream().collect(Collectors.toMap(eag -> eag.getKey(), eag -> Location.resolve(null, eag.getValue().locationID)));
    logger.info("NPC prefetch received");
    for (Entry<Integer, Eagents> eagt : eagents.entrySet()) {
        Agent agent = new Agent();
        Eagents agt = eagt.getValue();
        agent.id = eagt.getKey();
        agent.corporation = ecorps.get(agt.corporationID).enName();
        agent.name = idx2name.get(agent.id);
        agent.isLocator = agt.isLocator;
        agent.level = agt.level;
        agent.type = AGENT_TYPE.of(agt.agentTypeID);
        if (agent.type == null) {
            logger.warn("no type for agent " + agent.name + " typeID=" + agt.agentTypeID);
        }
        agent.division = AGENT_DIVISION.of(agt.divisionID);
        if (agent.division == null) {
            logger.warn("no division for agent " + agent.name + " divisionID=" + agt.divisionID);
        }
        Location loc = agentsLocation.get(agent.id);
        if (loc != null) {
            agent.system = loc.system().name;
            R_get_universe_stations_station_id station = loc.station();
            if (station != null) {
                agent.station = station.name;
                agent.stationId = agt.locationID;
            }
            agents.put(agent.name, agent);
        } else {
            logger.warn("invalid location for agent " + agent.name + " locid=" + agt.locationID);
        }
    }
    logger.info("translated agents data");
    for (Entry<Integer, EnpcCorporations> e : ecorps.entrySet()) {
        Corporation add = new Corporation();
        add.id = e.getKey();
        EnpcCorporations snpc = e.getValue();
        add.name = snpc.enName();
        R_get_universe_factions faction = factionById.get(snpc.factionID);
        if (faction == null) {
            logger.debug("can't find faction from id " + snpc.factionID + " for corporation " + add.name);
        } else {
            add.faction = faction.name;
        }
        R_get_corporations_corporation_id esicorp = npcCorps.get(add.id);
        if (esicorp != null && esicorp.faction_id != 0) {
            add.warfare = factionById.get(esicorp.faction_id).name;
        }
        add.concordRate = EnpcCorporations.concordRates().getOrDefault(add.id, 0.0);
        if (add.id == EnpcCorporations.CONCORD_ID) {
            add.concordRate = 1.0;
        }
        corporations.put(add.name, add);
    }
    Map<Integer, LPOffer> covertedOffers = corporations.values().stream().parallel().flatMap(c -> {
        Requested<R_get_loyalty_stores_corporation_id_offers[]> req = esi.connection.get_loyalty_stores_offers(c.id, null);
        return req.isOk() ? Stream.of(req.getOK()) : Stream.empty();
    }).map(offer -> makeOffer(offer)).filter(o -> o != null).collect(Collectors.toMap(off -> off.id, off -> off, (o1, o2) -> o1));
    offers.putAll(covertedOffers);
    corporations.values().stream().parallel().forEach(c -> loadCorpOffers(c, esi.connection, offers));
}
Also used : R_get_universe_stations_station_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id) ItemRef(fr.guiguilechat.jcelechat.model.sde.npcs.LPOffer.ItemRef) FileTools(fr.guiguilechat.jcelechat.model.FileTools) Corporation(fr.guiguilechat.jcelechat.model.sde.npcs.Corporation) LoggerFactory(org.slf4j.LoggerFactory) AGENT_DIVISION(fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_DIVISION) EinvNames(fr.guiguilechat.jcelechat.model.sde.load.bsd.EinvNames) ESIStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic) Agent(fr.guiguilechat.jcelechat.model.sde.npcs.Agent) LPOffer(fr.guiguilechat.jcelechat.model.sde.npcs.LPOffer) MapHolder(fr.lelouet.tools.holders.interfaces.collections.MapHolder) ESIAccess(fr.guiguilechat.jcelechat.jcesi.disconnected.modeled.ESIAccess) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Eblueprints(fr.guiguilechat.jcelechat.model.sde.load.fsd.Eblueprints) R_get_universe_factions(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_factions) Map(java.util.Map) ListHolder(fr.lelouet.tools.holders.interfaces.collections.ListHolder) Location(fr.guiguilechat.jcelechat.jcesi.tools.locations.Location) Material(fr.guiguilechat.jcelechat.model.sde.load.fsd.Eblueprints.Material) CacheStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic) Collectors(java.util.stream.Collectors) File(java.io.File) R_get_loyalty_stores_corporation_id_offers(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_loyalty_stores_corporation_id_offers) AGENT_TYPE(fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_TYPE) Eagents(fr.guiguilechat.jcelechat.model.sde.load.fsd.Eagents) Requested(fr.guiguilechat.jcelechat.jcesi.interfaces.Requested) Stream(java.util.stream.Stream) R_get_corporations_corporation_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id) Entry(java.util.Map.Entry) EnpcCorporations(fr.guiguilechat.jcelechat.model.sde.load.fsd.EnpcCorporations) Comparator(java.util.Comparator) Collections(java.util.Collections) EtypeIDs(fr.guiguilechat.jcelechat.model.sde.load.fsd.EtypeIDs) Requested(fr.guiguilechat.jcelechat.jcesi.interfaces.Requested) R_get_corporations_corporation_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id) R_get_loyalty_stores_corporation_id_offers(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_loyalty_stores_corporation_id_offers) R_get_universe_stations_station_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id) ListHolder(fr.lelouet.tools.holders.interfaces.collections.ListHolder) R_get_universe_factions(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_factions) CacheStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic) EnpcCorporations(fr.guiguilechat.jcelechat.model.sde.load.fsd.EnpcCorporations) LPOffer(fr.guiguilechat.jcelechat.model.sde.npcs.LPOffer) Agent(fr.guiguilechat.jcelechat.model.sde.npcs.Agent) Corporation(fr.guiguilechat.jcelechat.model.sde.npcs.Corporation) ESIAccess(fr.guiguilechat.jcelechat.jcesi.disconnected.modeled.ESIAccess) Eagents(fr.guiguilechat.jcelechat.model.sde.load.fsd.Eagents) Location(fr.guiguilechat.jcelechat.jcesi.tools.locations.Location)

Example 3 with CacheStatic

use of fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic in project JCELechat by guiguilechat.

the class SortInvasionStandingGain method main.

public static void main(String[] args) {
    CacheStatic esi = ESIStatic.INSTANCE.cache();
    Set<Integer> trigGroups = new HashSet<>(Arrays.asList(4028));
    Set<Integer> edenGroups = new HashSet<>(Arrays.asList(4034, 4035, 4036, 4037));
    for (int gid : trigGroups) {
        esi.universe.groups(gid);
    }
    for (int gid : edenGroups) {
        esi.universe.groups(gid);
    }
    int[] trigTypes = trigGroups.stream().flatMapToInt(gid -> IntStream.of(esi.universe.groups(gid).get().types)).toArray();
    int[] edenTypes = edenGroups.stream().flatMapToInt(gid -> IntStream.of(esi.universe.groups(gid).get().types)).toArray();
    for (int tid : trigTypes) {
        esi.universe.types(tid);
    }
    for (int tid : edenTypes) {
        esi.universe.types(tid);
    }
    HashMap<Float, Set<R_get_universe_types_type_id>> entitiesGroupedByEdenStanding = new HashMap<>();
    for (int tid : trigTypes) {
        R_get_universe_types_type_id type = esi.universe.types(tid).get();
        float factionLoss = Stream.of(type.dogma_attributes).filter(d -> d.attribute_id == 562).map(d -> d.value).findFirst().orElse(0.0f);
        entitiesGroupedByEdenStanding.computeIfAbsent(factionLoss, d -> new HashSet<>()).add(type);
    }
    for (int tid : edenTypes) {
        R_get_universe_types_type_id type = esi.universe.types(tid).get();
        float factionLoss = -Stream.of(type.dogma_attributes).filter(d -> d.attribute_id == 562).map(d -> d.value).findFirst().orElse(0.0f);
        entitiesGroupedByEdenStanding.computeIfAbsent(factionLoss, d -> new HashSet<>()).add(type);
    }
    List<Entry<Float, Set<R_get_universe_types_type_id>>> sorted = entitiesGroupedByEdenStanding.entrySet().stream().sorted(Comparator.comparing(Entry::getKey)).collect(Collectors.toList());
    for (Entry<Float, Set<R_get_universe_types_type_id>> e : sorted) {
        if (e.getKey() != 0.0f) {
            System.out.println(e.getKey() + "\t" + e.getValue().stream().map(t -> t.name).collect(Collectors.joining(";")));
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) R_get_universe_types_type_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_types_type_id) Set(java.util.Set) HashMap(java.util.HashMap) CacheStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic) ESIStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Comparator(java.util.Comparator) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) R_get_universe_types_type_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_types_type_id) Entry(java.util.Map.Entry) CacheStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic) HashSet(java.util.HashSet)

Aggregations

CacheStatic (fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic)3 ESIStatic (fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic)3 R_get_universe_types_type_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_types_type_id)2 ListHolder (fr.lelouet.tools.holders.interfaces.collections.ListHolder)2 MapHolder (fr.lelouet.tools.holders.interfaces.collections.MapHolder)2 Comparator (java.util.Comparator)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 ESIAccess (fr.guiguilechat.jcelechat.jcesi.disconnected.modeled.ESIAccess)1 Requested (fr.guiguilechat.jcelechat.jcesi.interfaces.Requested)1 Location (fr.guiguilechat.jcelechat.jcesi.tools.locations.Location)1 FileTools (fr.guiguilechat.jcelechat.model.FileTools)1 R_get_corporations_corporation_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id)1 R_get_insurance_prices (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_insurance_prices)1 R_get_loyalty_stores_corporation_id_offers (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_loyalty_stores_corporation_id_offers)1 R_get_universe_factions (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_factions)1 R_get_universe_stations_station_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id)1 EinvNames (fr.guiguilechat.jcelechat.model.sde.load.bsd.EinvNames)1