Skip to content

Commit

Permalink
New Feature: Get missing item data from EveRef (data not in ESI)
Browse files Browse the repository at this point in the history
Merge Feature
  • Loading branch information
GoldenGnu committed May 16, 2024
2 parents a622e08 + 3add20e commit af262c9
Show file tree
Hide file tree
Showing 11 changed files with 1,759 additions and 99 deletions.
40 changes: 30 additions & 10 deletions src/main/java/net/nikr/eve/jeveasset/data/sde/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
package net.nikr.eve.jeveasset.data.sde;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.nikr.eve.jeveasset.data.settings.types.ItemType;


Expand Down Expand Up @@ -73,7 +75,7 @@ public class Item implements Comparable<Item>, ItemType {
private final String name;
private final String group;
private final String category;
private final long price;
private final long basePrice;
private final float volume;
private final float volumePackaged;
private final float capacity;
Expand All @@ -83,7 +85,7 @@ public class Item implements Comparable<Item>, ItemType {
private final boolean piMaterial;
private final int portion;
private final int productTypeID;
private int blueprintTypeID = 0;
private final Set<Integer> blueprintTypeIDs = new HashSet<>();
private final int productQuantity;
private final boolean blueprint;
private final boolean formula;
Expand All @@ -93,6 +95,7 @@ public class Item implements Comparable<Item>, ItemType {
private final List<IndustryMaterial> reactionMaterials = new ArrayList<>();
private final String slot;
private final String chargeSize;
//Dynamic values
private double priceReprocessed;
private double priceReprocessedMax;
private double priceManufacturing;
Expand All @@ -105,12 +108,20 @@ public Item(int typeID, String version) {
this(typeID, emptyType(typeID), "", "", -1, -1, -1, -1, -1, "", false, 0, 0, 1, "", "", version);
}

public Item(final int typeID, final String name, final String group, final String category, final long price, final float volume, final float volumePackaged, final float capacity, final int meta, final String tech, final boolean marketGroup, final int portion, final int productTypeID, final int productQuantity, String slot, String chargeSize, String version) {
public Item(Item item, long basePrice, String tech, int productTypeID, int productQuantity, Set<Integer> blueprintTypeIDs, List<ReprocessedMaterial> reprocessedMaterials, List<IndustryMaterial> manufacturingMaterials, List<IndustryMaterial> reactionMaterials) {
this(item.getTypeID(), item.getTypeName(), item.getGroup(), item.getCategory(), basePrice, item.getVolume(), item.getVolumePackaged(), item.getCapacity(), item.getMeta(), tech, item.isMarketGroup(), item.getPortion(), productTypeID, productQuantity, item.getSlot(), item.getChargeSize(), item.getVersion());
this.blueprintTypeIDs.addAll(blueprintTypeIDs);
this.reprocessedMaterials.addAll(reprocessedMaterials);
this.manufacturingMaterials.addAll(manufacturingMaterials);
this.reactionMaterials.addAll(reactionMaterials);
}

public Item(final int typeID, final String name, final String group, final String category, final long basePrice, final float volume, final float volumePackaged, final float capacity, final int meta, final String tech, final boolean marketGroup, final int portion, final int productTypeID, final int productQuantity, String slot, String chargeSize, String version) {
this.typeID = typeID;
this.name = name;
this.group = group.intern();
this.category = category.intern();
this.price = price;
this.basePrice = basePrice;
this.volume = volume;
this.volumePackaged = volumePackaged;
this.capacity = capacity;
Expand Down Expand Up @@ -215,7 +226,7 @@ public String getTypeName() {
}

public double getPriceBase() {
return price;
return basePrice;
}

public double getPriceReprocessed() {
Expand Down Expand Up @@ -293,15 +304,23 @@ public long getItemCount() {
}

public boolean isProduct() {
return blueprintTypeID > 0;
return !blueprintTypeIDs.isEmpty();
}

public Set<Integer> getBlueprintTypeIDs() {
return blueprintTypeIDs;
}

public int getBlueprintTypeID() {
return blueprintTypeID;
public Integer getBlueprintTypeID() {
if (blueprintTypeIDs.isEmpty()) {
return 0;
} else {
return blueprintTypeIDs.iterator().next();
}
}

public void setBlueprintID(int blueprintID) {
this.blueprintTypeID = blueprintID;
public void addBlueprintID(int blueprintID) {
this.blueprintTypeIDs.add(blueprintID);
}

public void setPriceReprocessed(double priceReprocessed) {
Expand All @@ -321,6 +340,7 @@ public String toString() {
return name;
}


@Override
public int compareTo(final Item o) {
return this.getTypeName().compareToIgnoreCase(o.getTypeName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ private void add(final ItemType itemType, final Collection<MyLocation> locations
inventionTypeIDs.add(item.getTypeID());
}
} else if (item.isProduct()) {
blueprintTypeIDs.add(item.getBlueprintTypeID());
blueprintTypeIDs.addAll(item.getBlueprintTypeIDs());
if (item.getMeta() == 0 && item.getTypeName().endsWith(" I")) {
inventionTypeIDs.add(item.getBlueprintTypeID());
inventionTypeIDs.addAll(item.getBlueprintTypeIDs());
}
}
//Market TypeID
Expand Down
167 changes: 112 additions & 55 deletions src/main/java/net/nikr/eve/jeveasset/io/esi/EsiItemsGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
package net.nikr.eve.jeveasset.io.esi;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.nikr.eve.jeveasset.data.sde.Item;
import net.nikr.eve.jeveasset.data.settings.Settings;
import net.nikr.eve.jeveasset.gui.shared.Formatter;
import static net.nikr.eve.jeveasset.io.esi.AbstractEsiGetter.DATASOURCE;
import static net.nikr.eve.jeveasset.io.esi.AbstractEsiGetter.getMarketApiOpen;
import net.nikr.eve.jeveasset.io.local.ItemsReader;
import net.nikr.eve.jeveasset.io.online.EveRefGetter;
import net.troja.eve.esi.ApiException;
import net.troja.eve.esi.ApiResponse;
import net.troja.eve.esi.model.CategoryResponse;
Expand All @@ -42,10 +46,21 @@ public class EsiItemsGetter extends AbstractEsiGetter {

/**
* Change ESI_ITEM_VERSION to force items_updates.xml items to be updated again.
* ChangeLog
* 1.2.0:
* Updated with EveRef type and blueprint data
*/
public final static String ESI_ITEM_VERSION = "1.0.2";
public final static String ESI_ITEM_VERSION = "1.2.0";
public final static String ESI_ITEM_EMPTY = "EMPTY";

private final static Map<Integer, GroupResponse> GROUPS_CACHE = new HashMap<>();
private final static Map<Integer, CategoryResponse> CATEGORY_CACHE = new HashMap<>();
private final static Map<Integer, MarketGroupResponse> MARKET_GROUP_CACHE = new HashMap<>();

public final static long BASE_PRICE_DEFAULT = -1;
public final static int PRODUCT_TYPE_ID_DEFAULT = 0;
public final static int PRODUCT_QUANTITY_DEFAULT = 1;

private final int typeID;
private Item item = null;

Expand All @@ -64,33 +79,64 @@ public ApiResponse<TypeResponse> get() throws ApiException {
}
});
//Groups
GroupResponse groupResponse = update(DEFAULT_RETRIES, new EsiHandler<GroupResponse>() {
@Override
public ApiResponse<GroupResponse> get() throws ApiException {
return getUniverseApiOpen().getUniverseGroupsGroupIdWithHttpInfo(typeResponse.getGroupId(), null, DATASOURCE, null, null);
}
});
final int groupID = typeResponse.getGroupId();
GroupResponse groupResponse = GROUPS_CACHE.get(groupID);
if (groupResponse == null) {
groupResponse = update(DEFAULT_RETRIES, new EsiHandler<GroupResponse>() {
@Override
public ApiResponse<GroupResponse> get() throws ApiException {
return getUniverseApiOpen().getUniverseGroupsGroupIdWithHttpInfo(groupID, null, DATASOURCE, null, null);
}
});
GROUPS_CACHE.put(groupID, groupResponse);
}
final int categoryID = groupResponse.getCategoryId();
//Categories
CategoryResponse categoryResponse = update(DEFAULT_RETRIES, new EsiHandler<CategoryResponse>() {
@Override
public ApiResponse<CategoryResponse> get() throws ApiException {
return getUniverseApiOpen().getUniverseCategoriesCategoryIdWithHttpInfo(groupResponse.getCategoryId(), null, DATASOURCE, null, null);
}
});
//Market Groups
MarketGroupResponse marketGroupResponse = null;
if (typeResponse.getMarketGroupId() != null) {
marketGroupResponse = update(DEFAULT_RETRIES, new EsiHandler<MarketGroupResponse>() {
CategoryResponse categoryResponse = CATEGORY_CACHE.get(categoryID);
if (categoryResponse == null) {
categoryResponse = update(DEFAULT_RETRIES, new EsiHandler<CategoryResponse>() {
@Override
public ApiResponse<MarketGroupResponse> get() throws ApiException {
return getMarketApiOpen().getMarketsGroupsMarketGroupIdWithHttpInfo(typeResponse.getMarketGroupId(), null, DATASOURCE, null, null);
public ApiResponse<CategoryResponse> get() throws ApiException {
return getUniverseApiOpen().getUniverseCategoriesCategoryIdWithHttpInfo(categoryID, null, DATASOURCE, null, null);
}
});
CATEGORY_CACHE.put(categoryID, categoryResponse);
}
String name = typeResponse.getName();
//Market Groups
MarketGroupResponse marketGroupResponse = null;
if (typeResponse.getMarketGroupId() != null) {
Integer marketGroupID = typeResponse.getMarketGroupId();
marketGroupResponse = MARKET_GROUP_CACHE.get(marketGroupID);
if (marketGroupResponse == null) {
marketGroupResponse = update(DEFAULT_RETRIES, new EsiHandler<MarketGroupResponse>() {
@Override
public ApiResponse<MarketGroupResponse> get() throws ApiException {
return getMarketApiOpen().getMarketsGroupsMarketGroupIdWithHttpInfo(marketGroupID, null, DATASOURCE, null, null);
}
});
MARKET_GROUP_CACHE.put(marketGroupID, marketGroupResponse);
}
}
String name = typeResponse.getName()
.replaceAll(" +", " ") //Replace 2 or more spaces
.replace("\t", " ") //Tab
.replace("„", "\"") //Index
.replace("“", "\"") //Set transmit state
.replace("”", "\"") //Cancel character
.replace("‘", "'") //Private use one
.replace("’", "'") //Private use two
.replace("`", "'") //Grave accent
.replace("´", "'") //Acute accent
.replace("–", "-") //En dash
.replace("‐", "-") //Hyphen
.replace("‑", "-") //Non-breaking hyphen
.replace("‒", "-") //Figure dash
.replace("—", "-") //Em dash
.trim();

String group = groupResponse.getName();
String category = categoryResponse.getName();
long price = -1; //Base Price
long basePrice = BASE_PRICE_DEFAULT; //Base Price
float volume = getNotNull(typeResponse.getVolume());
float packagedVolume = getNotNull(typeResponse.getPackagedVolume());
float capacity = getNotNull(typeResponse.getCapacity());
Expand All @@ -113,46 +159,17 @@ public ApiResponse<MarketGroupResponse> get() throws ApiException {
}
}
//Tech Level
final String techLevel;
if (metaGroupID != null) {
switch (metaGroupID) {
case 1: techLevel = "Tech I"; break;
case 2: techLevel = "Tech II"; break;
case 3: techLevel = "Storyline"; break;
case 4: techLevel = "Faction"; break;
case 5: techLevel = "Officer"; break;
case 6: techLevel = "Deadspace"; break;
/*
//No longer in use
case 7: tech = "Frigates"; break;
case 8: tech = "Elite Frigates"; break;
case 9: tech = "Commander Frigates"; break;
case 10: tech = "Destroyer"; break;
case 11: tech = "Cruiser"; break;
case 12: tech = "Elite Cruiser"; break;
case 13: tech = "Commander Cruiser"; break;
*/
case 14: techLevel = "Tech III"; break;
case 15: techLevel = "Abyssal"; break;
case 17: techLevel = "Premium"; break;
case 19: techLevel = "Limited Time"; break;
case 52: techLevel = "Faction"; break; //Structure Faction
case 53: techLevel = "Tech II"; break; //Structure Tech II
case 54: techLevel = "Tech I"; break; //Structure Tech I
default: techLevel = "Tech I"; break;
}
} else {
techLevel = "Tech 1";
}
final String techLevel = getTechLevel(metaGroupID);

boolean marketGroup;
if (marketGroupResponse != null) {
marketGroup = marketGroupResponse.getTypes().contains(typeID);
} else {
marketGroup = false;
}
int portion = typeResponse.getPortionSize();
int productTypeID = 0; //Product
int productQuantity = 1; //Product Quantity
int productTypeID = PRODUCT_TYPE_ID_DEFAULT; //Product
int productQuantity = PRODUCT_QUANTITY_DEFAULT; //Product Quantity
//Slot
String slot = null;
List<TypeDogmaEffect> dogmaEffects = typeResponse.getDogmaEffects();
Expand Down Expand Up @@ -185,7 +202,11 @@ public ApiResponse<MarketGroupResponse> get() throws ApiException {
}
//Charge Size
String chargeSize = ItemsReader.getChargeSize(charge);
item = new Item(typeID, name, group, category, price, volume, packagedVolume, capacity, metaLevel, techLevel, marketGroup, portion, productTypeID, productQuantity, slot, chargeSize, ESI_ITEM_VERSION);
//Item
item = new Item(typeID, name, group, category, basePrice, volume, packagedVolume, capacity, metaLevel, techLevel, marketGroup, portion, productTypeID, productQuantity, slot, chargeSize, ESI_ITEM_VERSION);

//EveRef Update
item = EveRefGetter.getItem(item); //Update from EveRef
}

private float getNotNull(Float f) {
Expand All @@ -196,7 +217,43 @@ private float getNotNull(Float f) {
}
}

public static String getTechLevel(Integer metaGroupID) {
if (metaGroupID == null) {
return "Tech I";
}

switch (metaGroupID) {
case 1: return "Tech I";
case 2: return "Tech II";
case 3: return "Storyline";
case 4: return "Faction";
case 5: return "Officer";
case 6: return "Deadspace";
/*
//No longer in use
case 7: return "Frigates";
case 8: return "Elite Frigates";
case 9: return "Commander Frigates";
case 10: return "Destroyer";
case 11: return "Cruiser";
case 12: return "Elite Cruiser";
case 13: return "Commander Cruiser";
*/
case 14: return "Tech III";
case 15: return "Abyssal";
case 17: return "Premium";
case 19: return "Limited Time";
case 52: return "Faction"; //Structure Faction
case 53: return "Tech II"; //Structure Tech II
case 54: return "Tech I"; //Structure Tech I
default: return "Tech I";
}
}

public Item getItem() {
if (item == null) { //Empty Item
item = new Item(typeID, EsiItemsGetter.ESI_ITEM_EMPTY + Formatter.dateOnly(Settings.getNow()));
}
return item;
}

Expand Down
Loading

0 comments on commit af262c9

Please sign in to comment.