From fb75909f702143090221f8768afcc2af3ef3b08a Mon Sep 17 00:00:00 2001 From: GoldenGnu Date: Fri, 22 Sep 2023 10:47:21 +0200 Subject: [PATCH] Bug Fix: PB materials added to stockpiles are rounded up (Issue #413) --- .../gui/tabs/stockpile/StockpileBpDialog.java | 2 +- .../tabs/stockpile/StockpileItemDialog.java | 4 +- .../jeveasset/io/shared/ApiIdConverter.java | 18 ++-- .../io/shared/ApiIdConverterTest.java | 88 +++++++++++++++++++ 4 files changed, 103 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileBpDialog.java b/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileBpDialog.java index 66031bd34..db4d2f160 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileBpDialog.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileBpDialog.java @@ -275,7 +275,7 @@ public boolean matches(String value) { } public double doMath(int quantity, double countMinimum) { - return ApiIdConverter.getManufacturingQuantity(quantity, me, facility, rigs, security, countMinimum); + return ApiIdConverter.getManufacturingQuantity(quantity, me, facility, rigs, security, countMinimum, false); } } } diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileItemDialog.java b/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileItemDialog.java index 1cb4e27e6..55a65b65a 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileItemDialog.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileItemDialog.java @@ -386,14 +386,14 @@ private List getStockpileItems() { //Manufacturing Materials for (IndustryMaterial material : item.getManufacturingMaterials()) { Item materialItem = ApiIdConverter.getItem(material.getTypeID()); - double count = ApiIdConverter.getManufacturingQuantity(material.getQuantity(), me, facility, rigs, security, countMinimum); + double count = ApiIdConverter.getManufacturingQuantity(material.getQuantity(), me, facility, rigs, security, countMinimum, false); itemsMaterial.add(new StockpileItem(getStockpile(), materialItem, material.getTypeID(), count, false)); } } else if (jBlueprintType.isEnabled() && jBlueprintType.getItemAt(jBlueprintType.getSelectedIndex()) == BlueprintAddType.REACTION_MATERIALS) { //Reaction Materials for (IndustryMaterial material : item.getReactionMaterials()) { Item materialItem = ApiIdConverter.getItem(material.getTypeID()); - double count = ApiIdConverter.getManufacturingQuantity(material.getQuantity(), me, facility, rigs, security, countMinimum); + double count = ApiIdConverter.getManufacturingQuantity(material.getQuantity(), me, facility, rigs, security, countMinimum, false); itemsMaterial.add(new StockpileItem(getStockpile(), materialItem, material.getTypeID(), count, false)); } } else { diff --git a/src/main/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverter.java b/src/main/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverter.java index fbcae797a..a290d4c42 100644 --- a/src/main/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverter.java +++ b/src/main/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverter.java @@ -364,7 +364,7 @@ private static double getManufacturingQuantity(ManufacturingSettings manufacturi ManufacturingFacility facility = manufacturingSettings.getFacility(); ManufacturingRigs rigs = manufacturingSettings.getRigs(); ManufacturingSecurity security = manufacturingSettings.getSecurity(); - return getManufacturingQuantity(quantity, me, facility, rigs, security, 1); + return getManufacturingQuantity(quantity, me, facility, rigs, security, 1, true); } /** @@ -375,16 +375,22 @@ private static double getManufacturingQuantity(ManufacturingSettings manufacturi * @param rigs * @param security * @param runs + * @param round * @return Can return less than 1 (one) */ - public static double getManufacturingQuantity(int quantity, int me, ManufacturingFacility facility, ManufacturingRigs rigs, ManufacturingSecurity security, double runs) { + public static double getManufacturingQuantity(int quantity, int me, ManufacturingFacility facility, ManufacturingRigs rigs, ManufacturingSecurity security, double runs, boolean round) { //base * ((100-ME)/100) * (EC modifier) * (EC Rig modifier)) - return roundManufacturingQuantity(quantity * percentToBonus(me) * percentToBonus(facility.getMaterialBonus()) * rigToBonus(rigs, security), runs); + return roundManufacturingQuantity(quantity * percentToBonus(me) * percentToBonus(facility.getMaterialBonus()) * rigToBonus(rigs, security), runs, round); } - private static double roundManufacturingQuantity(double manufacturingQuantity, double runs) { - //max(runs,ceil(round((base * ((100-ME)/100) * (EC modifier) * (EC Rig modifier))*runs,2))) - return Math.max(runs, Math.ceil(roundQuantity(manufacturingQuantity, 2)) * runs); + private static double roundManufacturingQuantity(double manufacturingQuantity, double runs, boolean round) { + //max(runs,round(ceil((base * ((100-ME)/100) * (EC modifier) * (EC Rig modifier))*runs,2))) + double quantity = Math.max(runs, roundQuantity(manufacturingQuantity, 2) * runs); + if (round) { + return Math.ceil(quantity); + } else { + return quantity; + } } private static double percentToBonus(double value) { diff --git a/src/test/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverterTest.java b/src/test/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverterTest.java index 24f2052ef..9ef77ecdc 100644 --- a/src/test/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverterTest.java +++ b/src/test/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverterTest.java @@ -21,9 +21,12 @@ package net.nikr.eve.jeveasset.io.shared; +import java.util.HashMap; +import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import net.nikr.eve.jeveasset.TestUtil; +import net.nikr.eve.jeveasset.data.sde.IndustryMaterial; import net.nikr.eve.jeveasset.data.sde.Item; import net.nikr.eve.jeveasset.data.sde.MyLocation; import net.nikr.eve.jeveasset.data.sde.StaticData; @@ -88,6 +91,91 @@ public void testInstallationFee(ManufacturingSettings manufacturingSettings, Ite assertEquals(Formatter.doubleFormat(actual) + "!=" + Formatter.doubleFormat(expected), expected,actual , 1); } + /** + * Tested against Isk Per Hour 2023-09-20 + */ + @Test + public void testManufacturingQuantity() { + System.out.println(" --- Default ---"); + int me = 0; + ManufacturingFacility facility = ManufacturingFacility.ENGINEERING_COMPLEX_XLARGE; + ManufacturingRigs rigs = ManufacturingRigs.NONE; + ManufacturingSecurity security = ManufacturingSecurity.LOWSEC; + double runs = 1; + Map expected = new HashMap<>(); + expected.put(34, 7_920_000.0); + expected.put(35, 3_960_000.0); + expected.put(36, 594_000.0); + expected.put(37, 396_000.0); + expected.put(38, 11_880.0); + expected.put(39, 5_940.0); + expected.put(40, 2_970.0); + expected.put(57478, 198.0); + expected.put(57486, 99.0); + expected.put(57479, 1.0); + testManufacturingQuantity(expected, me, facility, rigs, security, runs); + } + + /** + * Tested against Isk Per Hour 2023-09-20 + */ + @Test + public void testManufacturingQuantityMe() { + System.out.println(" --- ME ---"); + int me = 10; + ManufacturingFacility facility = ManufacturingFacility.ENGINEERING_COMPLEX_XLARGE; + ManufacturingRigs rigs = ManufacturingRigs.NONE; + ManufacturingSecurity security = ManufacturingSecurity.HIGHSEC; + double runs = 1; + Map expected = new HashMap<>(); + expected.put(34, 7_128_000.0); + expected.put(35, 3_564_000.0); + expected.put(36, 534_600.0); + expected.put(37, 356_400.0); + expected.put(38, 10_692.0); + expected.put(39, 5_346.0); + expected.put(40, 2_673.0); + expected.put(57478, 179.0); + expected.put(57486, 90.0); + expected.put(57479, 1.0); + testManufacturingQuantity(expected, me, facility, rigs, security, runs); + } + + /** + * Tested against Isk Per Hour 2023-09-20 + */ + @Test + public void testManufacturingQuantityRuns() { + System.out.println(" --- Runs ---"); + int me = 10; + ManufacturingFacility facility = ManufacturingFacility.ENGINEERING_COMPLEX_XLARGE; + ManufacturingRigs rigs = ManufacturingRigs.NONE; + ManufacturingSecurity security = ManufacturingSecurity.HIGHSEC; + double runs = 200; + Map expected = new HashMap<>(); + expected.put(34, 1_425_600_000.0); + expected.put(35, 712_800_000.0); + expected.put(36, 106_920_000.0); + expected.put(37, 71_280_000.0); + expected.put(38, 2_138_400.0); + expected.put(39, 1_069_200.0); + expected.put(40, 534_600.0); + expected.put(57478, 35_640.0); + expected.put(57486, 17_820.0); + expected.put(57479, 200.0); + testManufacturingQuantity(expected, me, facility, rigs, security, runs); + } + + public void testManufacturingQuantity(Map expected, int me, ManufacturingFacility facility, ManufacturingRigs rigs, ManufacturingSecurity security, double runs) { + Item blueprint = ApiIdConverter.getItem(999); //Domenix Blueprint + for (IndustryMaterial material : blueprint.getManufacturingMaterials()) { + double quantity = ApiIdConverter.getManufacturingQuantity(material.getQuantity(), me, facility, rigs, security, runs, true); + System.out.println(" id=" + material.getTypeID() + " q=" + material.getQuantity() + " qmod=" + Formatter.compareFormat(quantity)); + assertEquals(expected.get(material.getTypeID()), quantity, 0.001); + //System.out.println("expected.put(" + material.getTypeID() + ", " + Formatter.compareFormat(quantity) + ");"); + } + } + /** * Test of location method, of class ApiIdConverter. */