From 1fc7aec99c0ea45db339b024c9af578faae13b2b Mon Sep 17 00:00:00 2001 From: GoldenGnu Date: Tue, 15 Oct 2024 23:03:31 +0200 Subject: [PATCH] Code: Updated prices library to 3.1.1 (Issue #469) Removed Perimeter TTT. Added Rens, Dodixie, Hek. Enabled R1O-GN and MJ-5F9 Ensured you only need to edit the JaniceLocation enum in the future --- pom.xml | 2 +- .../net/nikr/eve/jeveasset/LibraryManager.java | 2 +- .../data/settings/PriceDataSettings.java | 6 +++++- .../dialogs/settings/PriceDataSettingsPanel.java | 8 +++----- .../eve/jeveasset/io/online/PriceDataGetter.java | 15 +++++++++------ .../io/online/PriceDataGetterOnlineTest.java | 16 ++++++++++------ 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index ac83d7f9f5..a33f8bdf49 100644 --- a/pom.xml +++ b/pom.xml @@ -759,7 +759,7 @@ uk.me.candle pricing - 3.0.0 + 3.1.1 uk.me.candle diff --git a/src/main/java/net/nikr/eve/jeveasset/LibraryManager.java b/src/main/java/net/nikr/eve/jeveasset/LibraryManager.java index 6d031266ac..a94bdfead4 100644 --- a/src/main/java/net/nikr/eve/jeveasset/LibraryManager.java +++ b/src/main/java/net/nikr/eve/jeveasset/LibraryManager.java @@ -98,7 +98,7 @@ public static synchronized Set getLibFiles() { files.add("guava-r09.jar"); files.add("LGoodDatePicker-11.2.1.jar"); files.add("jfreechart-1.5.3.jar"); - files.add("pricing-3.0.0.jar"); + files.add("pricing-3.1.1.jar"); files.add("routing-2.0.0.jar"); files.add("slf4j-api-1.7.36.jar"); files.add("log4j-over-slf4j-1.7.36.jar"); diff --git a/src/main/java/net/nikr/eve/jeveasset/data/settings/PriceDataSettings.java b/src/main/java/net/nikr/eve/jeveasset/data/settings/PriceDataSettings.java index e4829bef84..c94f3c0d1d 100644 --- a/src/main/java/net/nikr/eve/jeveasset/data/settings/PriceDataSettings.java +++ b/src/main/java/net/nikr/eve/jeveasset/data/settings/PriceDataSettings.java @@ -26,6 +26,7 @@ import javax.swing.Icon; import net.nikr.eve.jeveasset.gui.images.Images; import net.nikr.eve.jeveasset.i18n.DataModelPriceDataSettings; +import uk.me.candle.eve.pricing.impl.Janice.JaniceLocation; import uk.me.candle.eve.pricing.options.LocationType; import uk.me.candle.eve.pricing.options.PriceType; import uk.me.candle.eve.pricing.options.PricingFetch; @@ -46,7 +47,7 @@ public enum PriceSource { } }, */ - JANICE(PricingFetch.JANICE, LocationType.STATION, 1L, Images.LINK_JANICE.getIcon()) { + JANICE(PricingFetch.JANICE, LocationType.STATION, JaniceLocation.JITA_4_4.getPriceLocation().getLocationID(), Images.LINK_JANICE.getIcon()) { @Override String getI18N() { return DataModelPriceDataSettings.get().sourceJanice(); } @@ -118,6 +119,9 @@ public Icon getIcon() { public boolean isValid(LocationType locationType, Long locationID) { if (null != locationType && locationID != null) { + if (this == JANICE && !JaniceLocation.isValid(locationID)) { + return false; + } switch (locationType) { case REGION: return supportRegions(); diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/PriceDataSettingsPanel.java b/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/PriceDataSettingsPanel.java index c23d9e8c2f..ad1e24259f 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/PriceDataSettingsPanel.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/PriceDataSettingsPanel.java @@ -429,11 +429,9 @@ private void updateSource(final PriceSource source) { list.add(ApiIdConverter.getLocation(60005686)); } else if (source == PriceSource.JANICE) { list = new ArrayList<>(); - list.add(JaniceLocation.AMARR.getPriceLocation()); - list.add(JaniceLocation.JITA_4_4.getPriceLocation()); - list.add(JaniceLocation.JITA_4_4_AND_PERIMETER_TTT.getPriceLocation()); - list.add(JaniceLocation.NPC.getPriceLocation()); - list.add(JaniceLocation.PERIMETER_TTT.getPriceLocation()); + for (JaniceLocation janiceLocation : JaniceLocation.values()) { + list.add(janiceLocation.getPriceLocation()); + } locationType = LocationType.STATION; } else { list = stations; diff --git a/src/main/java/net/nikr/eve/jeveasset/io/online/PriceDataGetter.java b/src/main/java/net/nikr/eve/jeveasset/io/online/PriceDataGetter.java index bd04985bae..3d747ca8b3 100644 --- a/src/main/java/net/nikr/eve/jeveasset/io/online/PriceDataGetter.java +++ b/src/main/java/net/nikr/eve/jeveasset/io/online/PriceDataGetter.java @@ -67,7 +67,6 @@ public class PriceDataGetter implements PricingListener { private static final int ATTEMPT_COUNT = 2; private static final int ZERO_PRICES_WARNING_LIMIT = 10; private static final int FAILED_PERCENT_CANCEL_LIMIT = 5; - private static final int ZERO_PERCENT_CANCEL_LIMIT = 25; private UpdateTask updateTask; private boolean update; @@ -197,6 +196,9 @@ protected Map processUpdate(final UpdateTask task, final boo pricingOptions.addHeader("X-ApiKey", janiceKey); } else if (!JANICE.isEmpty()) { pricingOptions.addHeader("X-ApiKey", JANICE); + } else if (updateTask != null) { + updateTask.addError("Price data", "No Janice API Key"); + return null; } } @@ -235,8 +237,9 @@ protected Map processUpdate(final UpdateTask task, final boo return null; } } - boolean updated = (!okay.isEmpty() && (typeIDs.size() * FAILED_PERCENT_CANCEL_LIMIT / 100) > failed.size() && (typeIDs.size() * ZERO_PERCENT_CANCEL_LIMIT / 100) > zero.size()); - if (updated && !failed.isEmpty()) { + boolean updated = !okay.isEmpty() && typeIDs.size() * FAILED_PERCENT_CANCEL_LIMIT / 100 > failed.size(); + + if (!failed.isEmpty()) { StringBuilder errorString = new StringBuilder(); boolean first = true; synchronized (failed) { @@ -250,11 +253,11 @@ protected Map processUpdate(final UpdateTask task, final boo } } LOG.error("Failed to update price data for the following typeIDs: " + errorString.toString()); - if (updateTask != null) { + if (updated && updateTask != null) { updateTask.addError("Price data", "Failed to update price data for " + failed.size() + " of " + typeIDs.size() + " item types"); } } - if (updated && !zero.isEmpty()) { + if (!zero.isEmpty()) { StringBuilder errorString = new StringBuilder(); synchronized (zero) { boolean first = true; @@ -268,7 +271,7 @@ protected Map processUpdate(final UpdateTask task, final boo } } LOG.warn("Price data is zero for the following typeIDs: " + errorString.toString()); - if (updateTask != null && zero.size() > ZERO_PRICES_WARNING_LIMIT) { + if (updated && updateTask != null && typeIDs.size() * ZERO_PRICES_WARNING_LIMIT / 100 < zero.size()) { updateTask.addWarning("Price data", "Price data is zero for " + zero.size() + " of " + typeIDs.size() + " item types"); } } diff --git a/src/test/java/net/nikr/eve/jeveasset/io/online/PriceDataGetterOnlineTest.java b/src/test/java/net/nikr/eve/jeveasset/io/online/PriceDataGetterOnlineTest.java index e2a8213324..7e896fd05b 100644 --- a/src/test/java/net/nikr/eve/jeveasset/io/online/PriceDataGetterOnlineTest.java +++ b/src/test/java/net/nikr/eve/jeveasset/io/online/PriceDataGetterOnlineTest.java @@ -48,8 +48,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import uk.me.candle.eve.pricing.impl.Janice; +import uk.me.candle.eve.pricing.impl.Janice.JaniceLocation; import uk.me.candle.eve.pricing.options.LocationType; +import uk.me.candle.eve.pricing.options.NamedPriceLocation; import uk.me.candle.eve.pricing.options.PriceLocation; import uk.me.candle.eve.pricing.options.PricingOptions; @@ -119,19 +120,22 @@ private void test(PriceSource source) { } if (source.supportStations()) { if (source == PriceSource.JANICE) { - test(source, LocationType.STATION, Janice.JaniceLocation.JITA_4_4.getPriceLocation()); + for (JaniceLocation location : JaniceLocation.values()) { + test(source, LocationType.STATION, location.getPriceLocation()); + } } else { test(source, LocationType.STATION, ApiIdConverter.getLocation(STATION_JITA_4_4)); } } } - private void test(PriceSource source, LocationType locationType, PriceLocation location) { + private void test(PriceSource source, LocationType locationType, NamedPriceLocation location) { TestPricingOptions options = new TestPricingOptions(locationType, location); System.out.println(source.toString() + " (" + options.getLocationType().name().toLowerCase() - + " - " +typeIDs.size() + " IDs)" + + " - " + location.getLocation() + + " - " + typeIDs.size() + " IDs)" ); if (source == PriceSource.JANICE && JANICE_KEY != null) { options.addHeader("X-ApiKey", JANICE_KEY); @@ -175,7 +179,7 @@ public TestPricingOptions(LocationType locationType, PriceLocation location) { @Override public long getPriceCacheTimer() { - return 60*60*1000l; // 1 hour + return 60*60*1000L; // 1 hour } @Override @@ -200,7 +204,7 @@ public OutputStream getCacheOutputStream() throws IOException { @Override public boolean getCacheTimersEnabled() { - return true; + return false; } @Override