Search in sources :

Example 1 with R_get_corporations_corporation_id_assets

use of fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id_assets in project JCELechat by guiguilechat.

the class Assets method grow.

protected ItemForest grow(List<R_get_corporations_corporation_id_assets> assets) {
    ItemForest ret = new ItemForest();
    for (R_get_corporations_corporation_id_assets item : assets) {
        ret.itemsByID.put(item.item_id, new ItemNode(item));
    }
    // fetch the names
    name(ret.itemsByID);
    // place the items in the roots.
    for (ItemNode itemNode : ret.itemsByID.values()) {
        ItemNode parent = ret.itemsByID.get(itemNode.location_id);
        if (parent == null) {
            Location location = Location.resolve(con, itemNode.location_id);
            ret.roots.computeIfAbsent(location, loc -> new HashMap<>()).computeIfAbsent(itemNode.location_flag, f -> new ArrayList<>()).add(itemNode);
        } else {
            parent.contained.computeIfAbsent(itemNode.location_flag, f -> new ArrayList<>()).add(itemNode);
        }
    }
    return ret;
}
Also used : Arrays(java.util.Arrays) fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag) Hangar(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.Hangar) Getter(lombok.Getter) HashMap(java.util.HashMap) MapHolder(fr.lelouet.tools.holders.interfaces.collections.MapHolder) R_get_corporations_corporation_id_assets(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id_assets) Impounded(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.Impounded) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) ListHolder(fr.lelouet.tools.holders.interfaces.collections.ListHolder) StreamSupport(java.util.stream.StreamSupport) Location(fr.guiguilechat.jcelechat.jcesi.tools.locations.Location) CorpDeliveries(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpDeliveries) Locked(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.Locked) AutoFit(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.AutoFit) DroneBay(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.DroneBay) ObjHolder(fr.lelouet.tools.holders.interfaces.ObjHolder) ShipHangar(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.ShipHangar) ItemForest(fr.guiguilechat.jcelechat.jcesi.connected.modeled.character.Assets.ItemForest) Unlocked(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.Unlocked) Set(java.util.Set) Collectors(java.util.stream.Collectors) Requested(fr.guiguilechat.jcelechat.jcesi.interfaces.Requested) List(java.util.List) Stream(java.util.stream.Stream) ESIAccount(fr.guiguilechat.jcelechat.jcesi.connected.modeled.ESIAccount) HangarAll(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.HangarAll) M_post_assets_names_2(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.M_post_assets_names_2) CorpSAG7(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpSAG7) Entry(java.util.Map.Entry) CorpSAG6(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpSAG6) CorpSAG5(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpSAG5) ItemNode(fr.guiguilechat.jcelechat.jcesi.connected.modeled.character.Assets.ItemNode) CorpSAG4(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpSAG4) CorpSAG3(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpSAG3) CorpSAG2(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpSAG2) Deliveries(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.Deliveries) CorpSAG1(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpSAG1) ItemNode(fr.guiguilechat.jcelechat.jcesi.connected.modeled.character.Assets.ItemNode) R_get_corporations_corporation_id_assets(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id_assets) ItemForest(fr.guiguilechat.jcelechat.jcesi.connected.modeled.character.Assets.ItemForest) ArrayList(java.util.ArrayList) Location(fr.guiguilechat.jcelechat.jcesi.tools.locations.Location)

Example 2 with R_get_corporations_corporation_id_assets

use of fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id_assets 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);
    }
}
Also used : Requested(fr.guiguilechat.jcelechat.jcesi.interfaces.Requested) PrintWriter(java.io.PrintWriter) IntStream(java.util.stream.IntStream) FileWriter(java.io.FileWriter) LocalDateTime(java.time.LocalDateTime) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) ESIStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic) R_get_characters_character_id_assets(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_characters_character_id_assets) Collectors(java.util.stream.Collectors) R_get_corporations_corporation_id_assets(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id_assets) File(java.io.File) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Requested(fr.guiguilechat.jcelechat.jcesi.interfaces.Requested) List(java.util.List) Stream(java.util.stream.Stream) ESIAccount(fr.guiguilechat.jcelechat.jcesi.connected.modeled.ESIAccount) DateTimeFormatter(java.time.format.DateTimeFormatter) Entry(java.util.Map.Entry) Clock(java.time.Clock) IntFunction(java.util.function.IntFunction) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet) R_get_characters_character_id_assets(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_characters_character_id_assets) IOException(java.io.IOException) ESIAccount(fr.guiguilechat.jcelechat.jcesi.connected.modeled.ESIAccount) R_get_corporations_corporation_id_assets(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id_assets) File(java.io.File)

Aggregations

ESIAccount (fr.guiguilechat.jcelechat.jcesi.connected.modeled.ESIAccount)2 Requested (fr.guiguilechat.jcelechat.jcesi.interfaces.Requested)2 R_get_corporations_corporation_id_assets (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id_assets)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 ItemForest (fr.guiguilechat.jcelechat.jcesi.connected.modeled.character.Assets.ItemForest)1 ItemNode (fr.guiguilechat.jcelechat.jcesi.connected.modeled.character.Assets.ItemNode)1 ESIStatic (fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic)1 Location (fr.guiguilechat.jcelechat.jcesi.tools.locations.Location)1 M_post_assets_names_2 (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.M_post_assets_names_2)1 R_get_characters_character_id_assets (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_characters_character_id_assets)1 fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag)1 AutoFit (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.AutoFit)1 CorpDeliveries (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.get_corporations_corporation_id_assets_location_flag.CorpDeliveries)1