use of fr.guiguilechat.jcelechat.jcesi.interfaces.Requested in project JCELechat by guiguilechat.
the class Universe method names.
public R_post_universe_names[] names(int... ids) {
if (ids == null || ids.length == 0) {
return new R_post_universe_names[0];
}
synchronized (cachedNames) {
IntStream.of(ids).filter(i -> !cachedNames.containsKey(i));
// have to work with long, because CCP bug.
int[] missingIds = IntStream.of(ids).filter(i -> !cachedNames.containsKey(i)).toArray();
int[] fullbuffer = new int[MAXLONGIDPERREQUEST];
for (int start = 0; start < missingIds.length; start += MAXLONGIDPERREQUEST) {
if (start + MAXLONGIDPERREQUEST >= missingIds.length) {
fullbuffer = new int[missingIds.length - start];
}
System.arraycopy(missingIds, start, fullbuffer, 0, fullbuffer.length);
Requested<R_post_universe_names[]> newreq;
do {
newreq = ESIStatic.INSTANCE.post_universe_names(fullbuffer, null);
} while (newreq == null || newreq.isServerError());
if (newreq.isOk()) {
for (R_post_universe_names n : newreq.getOK()) {
cachedNames.put(n.id, n);
}
} else {
log.error("could not load names for ids" + IntStream.of(ids).mapToObj(i -> i).collect(Collectors.toList()) + " resp=" + newreq.getResponseCode() + " err=" + newreq.getError());
}
}
return IntStream.of(ids).mapToObj(cachedNames::get).toArray(R_post_universe_names[]::new);
}
}
use of fr.guiguilechat.jcelechat.jcesi.interfaces.Requested in project JCELechat by guiguilechat.
the class Assets method name.
// get the names of specific assets
protected void name(Map<Long, ItemNode> items) {
int max_ids_per_search = 1000;
if (items == null || items.size() == 0) {
return;
}
ArrayList<M_post_assets_names_2> ret = new ArrayList<>();
long[] ids = items.values().stream().filter(Assets::canName).mapToLong(item -> item.item_id).toArray();
int start = 0;
while (start < ids.length) {
long[] ids2 = Arrays.copyOfRange(ids, start, Math.min(start + max_ids_per_search, ids.length));
Requested<M_post_assets_names_2[]> names = con.connection().post_characters_assets_names(con.characterId(), ids2, null);
while (names.isServerError()) {
names = con.connection().post_characters_assets_names(con.characterId(), ids2, null);
}
if (names.isOk()) {
ret.addAll(Arrays.asList(names.getOK()));
} else {
System.err.println(" error " + names.getError() + " response=" + names.getResponseCode());
}
start += max_ids_per_search;
}
for (M_post_assets_names_2 item : ret) {
if (item.name != null) {
items.get(item.item_id).withOptional(item.name);
}
}
}
use of fr.guiguilechat.jcelechat.jcesi.interfaces.Requested 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.guiguilechat.jcelechat.jcesi.interfaces.Requested in project JCELechat by guiguilechat.
the class ShowAssets method main.
public static void main(String[] args) throws InterruptedException, IOException {
ESIAccount acc = new ESIAccount(args[0], args[1]);
File parentCorp = new File("target/debugcorpassets/");
parentCorp.mkdirs();
File parentChar = new File("target/debugcharassets/");
parentChar.mkdirs();
while (true) {
try (PrintWriter corpWritter = new PrintWriter(new FileWriter(new File(parentCorp, LocalDateTime.now(Clock.systemUTC()).format(DateTimeFormatter.ISO_DATE_TIME))))) {
int corpid = ESIStatic.INSTANCE.get_characters(acc.characterId(), null).getOK().corporation_id;
corpWritter.println("name=" + acc.name());
corpWritter.println("corporation_id=" + corpid);
corpWritter.println("pages :");
List<String> errors = new ArrayList<>();
IntFunction<Requested<R_get_corporations_corporation_id_assets[]>> getPage = page -> {
Requested<R_get_corporations_corporation_id_assets[]> requestedPage = acc.connection().get_corporations_assets(corpid, page, null);
while (requestedPage.isServerError()) {
errors.add("page " + page + (requestedPage != null ? "" + requestedPage.getResponseCode() + "-" + requestedPage.getError() : "null"));
requestedPage = acc.connection().get_corporations_assets(corpid, page, null);
}
return requestedPage;
};
Requested<R_get_corporations_corporation_id_assets[]> page1 = getPage.apply(1);
if (page1.isOk()) {
int pages = page1.getNbPages();
// System.err.println("corporation assets pages=" + pages);
Set<String> expiries = new HashSet<>();
HashMap<Long, List<String>> assetId2url = new HashMap<>();
List<Requested<R_get_corporations_corporation_id_assets[]>> requests = Stream.concat(Stream.of(page1), IntStream.range(2, pages + 1).parallel().mapToObj(getPage)).collect(Collectors.toList());
requests.forEach(page -> {
expiries.add(page.getHeaders().get("Expires").get(0));
corpWritter.println("\t" + page.getURL() + " Expires=" + page.getHeaders().get("Expires"));
for (R_get_corporations_corporation_id_assets ass : page.getOK()) {
corpWritter.println("\t\t" + ass.item_id + " : type=" + ass.type_id + " qtty=" + ass.quantity + " location=" + ass.location_id);
List<String> list = assetId2url.get(ass.item_id);
if (list == null) {
list = new ArrayList<>();
assetId2url.put(ass.item_id, list);
} else {
errors.add("asset " + ass.item_id + " already declared on url " + list);
}
list.add(page.getURL());
}
});
corpWritter.println("expiries : " + expiries);
corpWritter.println("duplicate items :");
for (Entry<Long, List<String>> e : assetId2url.entrySet()) {
if (e.getValue().size() > 1) {
corpWritter.println("" + e.getKey() + " : " + e.getValue());
}
}
}
corpWritter.println("errors :");
for (String error : errors) {
corpWritter.println("\t" + error);
System.err.println(error);
}
} catch (Exception e) {
System.err.println(e);
}
try (PrintWriter charWritter = new PrintWriter(new FileWriter(new File(parentChar, LocalDateTime.now(Clock.systemUTC()).format(DateTimeFormatter.ISO_DATE_TIME))))) {
charWritter.println("name=" + acc.name());
charWritter.println("pages :");
List<String> errors = new ArrayList<>();
IntFunction<Requested<R_get_characters_character_id_assets[]>> getPage = page -> {
Requested<R_get_characters_character_id_assets[]> requestedPage = acc.connection().get_characters_assets(acc.characterId(), page, null);
while (requestedPage.isServerError()) {
errors.add("page " + page + (requestedPage != null ? "" + requestedPage.getResponseCode() + "-" + requestedPage.getError() : "null"));
requestedPage = acc.connection().get_characters_assets(acc.characterId(), page, null);
}
return requestedPage;
};
Requested<R_get_characters_character_id_assets[]> page1 = getPage.apply(1);
if (page1.isOk()) {
int pages = page1.getNbPages();
// System.err.println("corporation assets pages=" + pages);
Set<String> expiries = new HashSet<>();
HashMap<Long, List<String>> assetId2url = new HashMap<>();
List<Requested<R_get_characters_character_id_assets[]>> requests = Stream.concat(Stream.of(page1), IntStream.range(2, pages + 1).parallel().mapToObj(getPage)).collect(Collectors.toList());
requests.forEach(page -> {
expiries.add(page.getHeaders().get("Expires").get(0));
charWritter.println("\t" + page.getURL() + " Expires=" + page.getHeaders().get("Expires"));
for (R_get_characters_character_id_assets ass : page.getOK()) {
charWritter.println("\t\t" + ass.item_id + " : type=" + ass.type_id + " qtty=" + ass.quantity + " location=" + ass.location_id);
List<String> list = assetId2url.get(ass.item_id);
if (list == null) {
list = new ArrayList<>();
assetId2url.put(ass.item_id, list);
} else {
errors.add("asset " + ass.item_id + " already declared on url " + list);
}
list.add(page.getURL());
}
});
charWritter.println("expiries : " + expiries);
charWritter.println("duplicate items :");
for (Entry<Long, List<String>> e : assetId2url.entrySet()) {
if (e.getValue().size() > 1) {
charWritter.println("" + e.getKey() + " : " + e.getValue());
}
}
}
charWritter.println("errors :");
for (String error : errors) {
charWritter.println("\t" + error);
System.err.println(error);
}
} catch (Exception e) {
System.err.println(e);
}
System.out.println(LocalDateTime.now(Clock.systemUTC()));
Thread.sleep(1000 * 60 * 15);
}
}
use of fr.guiguilechat.jcelechat.jcesi.interfaces.Requested in project JCELechat by guiguilechat.
the class Assets method name.
// get the names of specific assets
protected void name(Map<Long, ItemNode> items) {
if (items == null || items.size() == 0) {
return;
}
ArrayList<M_post_assets_names_2> ret = new ArrayList<>();
long[] ids = items.values().stream().filter(Assets::canName).mapToLong(item -> item.item_id).toArray();
int start = 0;
while (start < ids.length) {
long[] ids2 = Arrays.copyOfRange(ids, start, Math.min(start + 1000, ids.length));
Requested<M_post_assets_names_2[]> names = con.connection().post_corporations_assets_names(con.corporation.getId(), ids2, null);
while (names.isServerError()) {
names = con.connection().post_corporations_assets_names(con.corporation.getId(), ids2, null);
}
if (names.isOk()) {
ret.addAll(Arrays.asList(names.getOK()));
} else {
System.err.println(" error " + names.getError() + " response=" + names.getResponseCode());
}
start += 1000;
}
for (M_post_assets_names_2 item : ret) {
items.get(item.item_id).withOptional(item.name);
}
}
Aggregations