use of fr.lelouet.tools.holders.interfaces.collections.MapHolder in project JCELechat by guiguilechat.
the class ShowDeathPerShipRatio method main.
public static void main(String[] args) {
CacheStatic cache = ESIStatic.INSTANCE.cache();
for (Integer r : cache.universe.systems().get()) {
cache.universe.systems(r);
}
MapHolder<Integer, R_get_universe_system_kills> kills = cache.universe.system_kills().toMap(sys -> sys.system_id);
MapHolder<Integer, R_get_universe_system_jumps> jumps_m = cache.universe.system_jumps().toMap(sys -> sys.system_id);
// useless because wh are not given their kill statistics
Set<Integer> whconstels = IntStream.range(11000001, 11000033 + 1).parallel().mapToObj(r_i -> cache.universe.regions(r_i)).flatMapToInt(h -> IntStream.of(h.get().constellations)).mapToObj(i -> i).collect(Collectors.toSet());
Set<Integer> abyssConstels = IntStream.range(12000001, 12000005 + 1).parallel().mapToObj(r_i -> cache.universe.regions(r_i)).flatMapToInt(h -> IntStream.of(h.get().constellations)).mapToObj(i -> i).collect(Collectors.toSet());
// System.err.println("constel ids=" + whconstels);
// HS, LS, NS, WH, abyssal
String[] indexNames = { "HS", "LS", "NS", "WS", "abyss" };
long[] npc_kills = new long[indexNames.length];
long[] ship_kills = new long[indexNames.length];
long[] jumps = new long[indexNames.length];
int[] totalsystems = new int[indexNames.length];
int[] nokills = new int[indexNames.length];
int[] nojumps = new int[indexNames.length];
int[] nokilljump = new int[indexNames.length];
for (Integer sys_id : cache.universe.systems().get()) {
R_get_universe_systems_system_id system = cache.universe.systems(sys_id).get();
int index = 0;
if (whconstels.contains(system.constellation_id)) {
index = 3;
} else if (abyssConstels.contains(system.constellation_id)) {
index = 4;
} else {
index = system.security_status > 0.45 ? 0 : system.security_status > 0.0 ? 1 : 2;
}
R_get_universe_system_kills syskills = kills.get().get(system.system_id);
if (syskills != null) {
npc_kills[index] += syskills.npc_kills;
ship_kills[index] += syskills.ship_kills;
} else {
nokills[index]++;
}
R_get_universe_system_jumps sysjumps = jumps_m.get().get(system.system_id);
if (sysjumps != null) {
jumps[index] += sysjumps.ship_jumps;
} else {
nojumps[index]++;
}
if (syskills == null && sysjumps == null) {
nokilljump[index]++;
nokills[index]--;
nojumps[index]--;
}
totalsystems[index]++;
}
System.out.println("space\tship kills\tnpc kills\tjumps\tnpc / ship\tnpc / jumps\t#systems\tnokilldata\tnojumpdata\tnok&j");
for (int i = 0; i < indexNames.length; i++) {
System.out.println(indexNames[i] + "\t" + ship_kills[i] + "\t" + npc_kills[i] + "\t" + jumps[i] + "\t" + 1.0f * npc_kills[i] / ship_kills[i] + "\t" + 1.0f * npc_kills[i] / jumps[i] + "\t" + totalsystems[i] + "\t" + nokills[i] + "\t" + nojumps[i] + "\t" + nokilljump[i]);
}
}
use of fr.lelouet.tools.holders.interfaces.collections.MapHolder 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);
// }
}
use of fr.lelouet.tools.holders.interfaces.collections.MapHolder 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));
}
use of fr.lelouet.tools.holders.interfaces.collections.MapHolder in project JCELechat by guiguilechat.
the class ESILoader method load.
public static TypeHierarchy load() {
TypeHierarchy ret = new TypeHierarchy();
// first preload everything
Universe universe = ESIStatic.INSTANCE.cache().universe;
Dogma dogma = ESIStatic.INSTANCE.cache().dogma;
MapHolder<Integer, R_get_universe_categories_category_id> catMap = universe.categories().mapItems(catid -> universe.categories(catid)).toMap(h -> h.get().category_id, h -> h.get());
MapHolder<Integer, R_get_universe_groups_group_id> groupMap = universe.groups().mapItems(groupID -> universe.groups(groupID)).toMap(h -> h.get().group_id, h -> h.get());
MapHolder<Integer, R_get_universe_types_type_id> typeMap = universe.types().mapItems(typeID -> universe.types(typeID)).toMap(h -> h.get().type_id, h -> h.get());
MapHolder<Integer, R_get_dogma_attributes_attribute_id> attMap = dogma.attributes().mapItems(typeID -> dogma.attributes(typeID)).toMap(h -> h.get().attribute_id, h -> h.get());
for (Entry<Integer, R_get_universe_categories_category_id> e : catMap.get().entrySet()) {
CatDetails det = new CatDetails();
det.id = e.getKey();
det.name = e.getValue().name;
det.published = e.getValue().published;
ret.catID2Details.put(e.getKey(), det);
ret.catID2GroupIDs.put(det.id, new HashSet<>());
}
for (Entry<Integer, R_get_universe_groups_group_id> e : groupMap.get().entrySet()) {
GroupDetails det = new GroupDetails();
det.id = e.getKey();
det.catID = e.getValue().category_id;
det.name = e.getValue().name;
det.published = e.getValue().published;
ret.groupID2Details.put(e.getKey(), det);
ret.groupID2TypeIDs.put(det.id, new HashSet<>());
ret.catID2GroupIDs.computeIfAbsent(e.getValue().category_id, i -> new HashSet<>()).add(e.getKey());
}
// types and their attributes
HashSet<Integer> floatAttributeIds = new HashSet<>();
HashSet<Integer> allAttributesIds = new HashSet<>();
for (Entry<Integer, R_get_universe_types_type_id> e : typeMap.get().entrySet()) {
TypeDetails det = new TypeDetails();
det.name = e.getValue().name;
det.id = e.getKey();
// TODO
// det.basePrice = e.getValue().;
det.marketGroupID = e.getValue().market_group_id;
det.groupID = e.getValue().group_id;
det.mass = e.getValue().mass;
det.packagedVolume = e.getValue().packaged_volume;
det.published = e.getValue().published;
det.portionSize = e.getValue().portion_size;
det.volume = e.getValue().volume;
ret.typeID2Details.put(e.getKey(), det);
ret.groupID2TypeIDs.computeIfAbsent(det.groupID, i -> new HashSet<>()).add(e.getKey());
if (e.getValue().dogma_attributes != null) {
for (get_dogma_dynamic_items_type_id_item_id_dogma_attributes attribute : e.getValue().dogma_attributes) {
if (attribute.attribute_id == 161) {
det.volume = attribute.value;
} else if (attribute.attribute_id == 4) {
det.mass = attribute.value;
} else {
int attId = attribute.attribute_id;
float floatValue = attribute.value;
det.definition.put(attId, floatValue);
if ((int) floatValue != floatValue) {
floatAttributeIds.add(attId);
}
allAttributesIds.add(attId);
}
}
}
}
for (int attId : allAttributesIds) {
R_get_dogma_attributes_attribute_id eattr = attMap.get().get(attId);
AttributeDetails det = new AttributeDetails();
det.defaultValue = eattr.default_value;
det.description = eattr.description;
det.hasFloat = floatAttributeIds.contains(attId);
det.highIsGood = eattr.high_is_good;
det.id = attId;
det.name = eattr.name;
det.published = eattr.published;
det.stackable = eattr.stackable;
ret.attID2Details.put(attId, det);
}
return ret;
}
use of fr.lelouet.tools.holders.interfaces.collections.MapHolder in project JCELechat by guiguilechat.
the class CheckESISDE method main.
public static void main(String[] args) {
long start = System.currentTimeMillis();
// first preload everything
Universe universe = ESIStatic.INSTANCE.cache().universe;
Dogma dogma = ESIStatic.INSTANCE.cache().dogma;
MapHolder<Integer, R_get_universe_categories_category_id> catMap = universe.categories().mapItems(catid -> universe.categories(catid)).toMap(h -> h.get().category_id, h -> h.get());
MapHolder<Integer, R_get_universe_groups_group_id> groupMap = universe.groups().mapItems(groupID -> universe.groups(groupID)).toMap(h -> h.get().group_id, h -> h.get());
MapHolder<Integer, R_get_universe_types_type_id> typeMap = universe.types().mapItems(typeID -> universe.types(typeID)).toMap(h -> h.get().type_id, h -> h.get());
MapHolder<Integer, R_get_dogma_attributes_attribute_id> attMap = dogma.attributes().mapItems(typeID -> dogma.attributes(typeID)).toMap(h -> h.get().attribute_id, h -> h.get());
EcategoryIDs.load();
EgroupIDs.load();
EtypeIDs.load();
EdogmaAttributes.load();
long postLoad = System.currentTimeMillis();
System.out.println("loaded in " + (postLoad - start) + "ms");
int errors = 0;
for (Entry<Integer, EcategoryIDs> e : EcategoryIDs.load().entrySet()) {
EcategoryIDs sdeEntry = e.getValue();
R_get_universe_categories_category_id esiEntry = catMap.get().get(e.getKey());
if (sdeEntry.published != esiEntry.published) {
System.out.println("cat=" + e.getKey() + "(" + esiEntry.name + ")" + " esi=" + esiEntry.published + " sde=" + sdeEntry.published);
errors++;
}
}
for (Entry<Integer, EgroupIDs> e : EgroupIDs.load().entrySet()) {
EgroupIDs sdeEntry = e.getValue();
R_get_universe_groups_group_id esiEntry = groupMap.get().get(e.getKey());
if (sdeEntry.published != esiEntry.published) {
System.out.println("group=" + e.getKey() + "(" + esiEntry.name + ")" + " esi=" + esiEntry.published + " sde=" + sdeEntry.published);
errors++;
}
}
for (Entry<Integer, EtypeIDs> e : EtypeIDs.load().entrySet()) {
EtypeIDs sdeEntry = e.getValue();
R_get_universe_types_type_id esiEntry = typeMap.get().get(e.getKey());
if (sdeEntry.published != esiEntry.published) {
System.out.println("type=" + e.getKey() + "(" + esiEntry.name + ")" + " esi=" + esiEntry.published + " sde=" + sdeEntry.published);
errors++;
}
}
Set<Integer> attributeIds = new HashSet<>();
Map<Integer, EdogmaAttributes> attSDEMap = EdogmaAttributes.load();
attributeIds.addAll(attSDEMap.keySet());
attributeIds.addAll(attMap.get().keySet());
for (int attId : attributeIds) {
EdogmaAttributes sdeEntry = attSDEMap.get(attId);
R_get_dogma_attributes_attribute_id esiEntry = attMap.get().get(attId);
if (sdeEntry == null) {
System.out.println("attid=" + attId + " null in SDE, name in ESI=" + esiEntry.name);
errors++;
}
if (esiEntry == null) {
System.out.println("attid=" + attId + " null in ESI, name in SDE=" + sdeEntry.name);
errors++;
}
if (sdeEntry != null && esiEntry != null) {
if (sdeEntry.published != esiEntry.published) {
System.out.println("att=" + attId + "(" + esiEntry.name + ")" + " esi=" + esiEntry.published + " sde=" + sdeEntry.published);
errors++;
}
if (!sdeEntry.name.equals(esiEntry.name)) {
System.out.println("att=" + attId + " esiname=" + esiEntry.name + " sdename=" + sdeEntry.name);
errors++;
}
}
}
System.out.println("found " + errors + " errors in " + (System.currentTimeMillis() - postLoad) + " ms");
}
Aggregations