Skip to content

Commit

Permalink
Bug Fix: PB materials added to stockpiles are rounded up (Issue #413)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenGnu committed Sep 22, 2023
1 parent 900412e commit 8107127
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,14 @@ private List<StockpileItem> 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 {
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/net/nikr/eve/jeveasset/io/shared/ApiIdConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer, Double> 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<Integer, Double> 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<Integer, Double> 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<Integer, Double> 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.
*/
Expand Down

0 comments on commit 8107127

Please sign in to comment.