Skip to content

Commit

Permalink
v2024.1.3 Switched to fractional quantities/volumes display; some mor…
Browse files Browse the repository at this point in the history
…e fixes to schematic-related costs
  • Loading branch information
tobitege committed Jan 1, 2024
1 parent d8b9381 commit 67aff73
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 47 deletions.
65 changes: 34 additions & 31 deletions DU-Industry-Tool/Classes/CalculatorClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static void Collect(CalculatorClass calc)
else
if (CalcSchematic(pCalc.SchematicType, prod.Quantity, out var minCost2, out _, out _))
{
calc.AddSchema(pCalc.SchematicType, (int)Math.Ceiling(prod.Quantity), minCost2);
calc.AddSchema(pCalc.SchematicType, prod.Quantity, minCost2);
calc.AddSchematicCost(minCost2);
}
}
Expand All @@ -196,15 +196,15 @@ public static void Collect(CalculatorClass calc)
var batches = ProductQuantity;
if (calc.IsBatchmode && calc.BatchOutput > 0)
{
batches = ProductQuantity / (decimal)calc.BatchOutput;
batches = Math.Round(ProductQuantity / (decimal)calc.BatchOutput, 3);
if (DUData.FullSchematicQuantities)
{
batches = Math.Max(1, Math.Floor(batches));
batches = Math.Ceiling(batches);
}
}
if (CalcSchematic(calc.SchematicType, (int)batches, out var minCost, out _, out _))
if (CalcSchematic(calc.SchematicType, batches, out var minCost, out _, out _))
{
calc.AddSchema(calc.SchematicType, (int)batches, minCost);
calc.AddSchema(calc.SchematicType, batches, minCost);
calc.AddSchematicCost(minCost);
}
}
Expand All @@ -228,15 +228,18 @@ public static bool CalcSchematic(string schematicId, decimal qtySchematic,
return false;
}

//qtySchematic = Math.Ceiling(qtySchematic);
minCost = Math.Round(schemata.Cost * qtySchematic); // cost is a breakdown to x1 schematic
minCost = Math.Round(schemata.Cost * qtySchematic, 3); // cost is a breakdown to x1 schematic
// number of copy jobs that need to be started to cover all needed schematics,
// (which depends on the batch size of a copy, e.g. 10 per copy process):
qtyCopies = qtySchematic / (decimal)Math.Max(1, schemata.BatchSize);
qtyCopies = Math.Ceiling(qtyCopies);
qtyCopies = qtySchematic / Math.Max(1, Math.Round((decimal)schemata.BatchSize, 3));

if (DUData.FullSchematicQuantities)
{
qtyCopies = Math.Ceiling(qtyCopies);
}

// copyCost is the single schematic cost multiplied by batch size and the number of copies:
copyCost = schemata.Cost * schemata.BatchSize * qtyCopies;
copyCost = Math.Round(copyCost, 2);
copyCost = Math.Round(schemata.Cost * schemata.BatchSize * qtyCopies);
return true;
}

Expand All @@ -263,7 +266,7 @@ private static void CollectSchematics(CalculatorClass calc, SummationType sumTyp
tmp.Quantity = val.Qty;
tmp.GetTalents();
if (tmp.BatchOutput == null) continue;// happens (on purpose)
tmp.Quantity = tmp.Quantity / (decimal)tmp.BatchOutput;
tmp.Quantity = Math.Round(tmp.Quantity / (decimal)tmp.BatchOutput, 3);
if (DUData.FullSchematicQuantities)
{
tmp.Quantity = (int)Math.Ceiling(tmp.Quantity);
Expand All @@ -276,7 +279,7 @@ private static void CollectSchematics(CalculatorClass calc, SummationType sumTyp
continue;
}
val.AmtSchemata = minCost;
calc.AddSchema(val.SchematicType, (int)Math.Ceiling((decimal)val.QtySchemata), minCost);
calc.AddSchema(val.SchematicType, val.QtySchemata ?? 0, minCost);
calc.AddSchematicCost(minCost);
calc.Sums[sumType][entry.Key] = val;
}
Expand Down Expand Up @@ -347,8 +350,7 @@ public static decimal CalculateRecipe(string key, decimal amount = 0, string lev
// and determine the minimum of batches to be produced
if (depth == 0 && calc.IsAmmo)
{
// at minimum 1 batch; using fractional values here
productQty = Math.Max(1, Math.Floor(amount / (decimal)(calc.BatchOutput ?? 40)));
productQty = Math.Round(amount / (decimal)(calc.BatchOutput ?? 40), 3);
amount = productQty;
}
var curLevel = level;
Expand All @@ -362,7 +364,7 @@ public static decimal CalculateRecipe(string key, decimal amount = 0, string lev
var ore = DUData.Ores.FirstOrDefault(o => o.Key == recipe.Key);
if (ore != null)
{
cost = Math.Round(amount * ore.Value, 2);
cost = Math.Round(amount * ore.Value, 3);
}
calc.OreCost = cost;
return cost;
Expand Down Expand Up @@ -411,7 +413,7 @@ public static decimal CalculateRecipe(string key, decimal amount = 0, string lev
else
// assumption: Plasma qty always 1
qty = myRecipe.IsPlasma ? 1 : (amount / factor);
cost = Math.Round(qty * DUData.Ores.First(o => o.Key == ingredient.Type).Value, 2);
cost = Math.Round(qty * DUData.Ores.First(o => o.Key == ingredient.Type).Value, 3);
// Only for ores we accumulate the cost within "calc"!
calc2.OreCost = cost;
calc2.Quantity = qty;
Expand Down Expand Up @@ -580,7 +582,7 @@ public static List<CalculatorClass> GetIngredientRecipes(string key, decimal qua
entry.GetTalents();
entry.SetParent(calc.Id);

var factor = 1M;
var factor = 1m;
var productQty = calc.Recipe.Products.First().Quantity;
if (reverse)
{
Expand All @@ -596,7 +598,7 @@ public static List<CalculatorClass> GetIngredientRecipes(string key, decimal qua
//entry.SchematicType = calc.Recipe.SchemaType;
factor = (productQty * calc.OutputMultiplier + calc.OutputAdder) /
(ingredient.Quantity * calc.InputMultiplier + calc.InputAdder);
entry.Quantity = Math.Round(quantity * factor,2);
entry.Quantity = Math.Round(quantity * factor, 3);
//if (!calc.IsOre)
//{
// entry.BatchInput = ingredient.Quantity * calc.InputMultiplier;
Expand Down Expand Up @@ -631,7 +633,7 @@ public class CalculatorClass : RecipeBase
private SchematicRecipe _recipe;

public Dictionary<SummationType, SortedDictionary<string, CalcEntry>> Sums { get; }
public SortedDictionary<string, Tuple<int, decimal>> SumSchemClass { get; private set; }
public SortedDictionary<string, Tuple<decimal, decimal>> SumSchemClass { get; private set; }

public Guid Id { get; private set; }
public Guid Parent { get; private set; }
Expand Down Expand Up @@ -673,7 +675,7 @@ public CalculatorClass()
Id = Guid.NewGuid();
Sums = new Dictionary<SummationType, SortedDictionary<string, CalcEntry>>();
SchematicsCost = 0;
SumSchemClass = new SortedDictionary<string, Tuple<int, decimal>>();
SumSchemClass = new SortedDictionary<string, Tuple<decimal, decimal>>();
}

public CalculatorClass(string key) : this()
Expand Down Expand Up @@ -716,33 +718,33 @@ public void SetParent(Guid parent)
Parent = parent;
}

public void AddSchematicCost(decimal quantity)
public void AddSchematicCost(decimal cost)
{
SchematicsCost += quantity;
SchematicsCost += cost;
}

public void ResetSchematicCost()
{
SchematicsCost = 0;
}

public void AddSchema(string schemaKey, int qty, decimal amount)
public void AddSchema(string schemaKey, decimal qty, decimal amount)
{
if (string.IsNullOrEmpty(schemaKey) || qty < 1) return;
if (string.IsNullOrEmpty(schemaKey) || qty < 0.001m) return;
if (SumSchemClass == null)
{
SumSchemClass = new SortedDictionary<string, Tuple<int, decimal>>();
SumSchemClass = new SortedDictionary<string, Tuple<decimal, decimal>>();
}

if (SumSchemClass.ContainsKey(schemaKey))
{
var item1 = SumSchemClass[schemaKey].Item1 + qty;
var item2 = SumSchemClass[schemaKey].Item2 + amount;
SumSchemClass.Remove(schemaKey);
SumSchemClass.Add(schemaKey, new Tuple<int, decimal>(item1, item2));
SumSchemClass.Add(schemaKey, new Tuple<decimal, decimal>(item1, item2));
}
else
SumSchemClass.Add(schemaKey, new Tuple<int, decimal>(qty, amount));
SumSchemClass.Add(schemaKey, new Tuple<decimal, decimal>(qty, amount));
}

public void Add(SummationType sumType, string key, CalcEntry value)
Expand Down Expand Up @@ -799,8 +801,9 @@ public List<string> GetTalents()
return GetTalents(Recipe); // in RecipeBase
}

// not used for pures, but elements
public bool CalcSchematicFromQty(string schematicType, decimal qty, decimal batchOutput,
out int batches, out decimal minCost, out decimal copyCost, out decimal qtyCopies)
out decimal batches, out decimal minCost, out decimal copyCost, out decimal qtyCopies)
{
minCost = 0M;
copyCost = 0M;
Expand All @@ -815,8 +818,8 @@ public bool CalcSchematicFromQty(string schematicType, decimal qty, decimal batc
{
qty /= batchOutput;
}
batches = DUData.FullSchematicQuantities ? (int)Math.Ceiling(qty) : (int)qty;
return Calculator.CalcSchematic(schematicType, (int)batches, out minCost, out copyCost, out qtyCopies);
batches = DUData.FullSchematicQuantities ? (int)Math.Ceiling(qty) : Math.Round(qty, 3);
return Calculator.CalcSchematic(schematicType, batches, out minCost, out copyCost, out qtyCopies);
}
}
}
4 changes: 2 additions & 2 deletions DU-Industry-Tool/Classes/DUData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public bool PrepareProductListRecipe()
calc.GetTalents();

// Add items to the overall products list
var batchCount = 1;
var batchCount = 1m;
foreach (var prod in calc.Recipe.Products)
{
/* Example: Production List item: 5000 L Pure Silver
Expand All @@ -169,7 +169,7 @@ public bool PrepareProductListRecipe()
prod.Mass += prodItem.Quantity * (calc.Recipe.UnitMass ?? 0);
prod.Volume += prodItem.Quantity * (calc.Recipe.UnitVolume ?? 0);
// TODO check why BatchOutput is occasionally null here
var batchOutput = calc.IsBatchmode ? (decimal)(calc.BatchOutput) : prod.Quantity;
var batchOutput = calc.IsBatchmode ? (decimal)(calc.BatchOutput ?? 0) : prod.Quantity;
if (calc.CalcSchematicFromQty(prod.SchemaType, prod.Quantity, batchOutput,
out batchCount , out var minCost, out var _, out var _))
{
Expand Down
2 changes: 1 addition & 1 deletion DU-Industry-Tool/Classes/Recipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public class ProductDetail
[JsonIgnore]
public string SchemaType { get; set; }
[JsonIgnore]
public int SchemaQty { get; set; }
public decimal SchemaQty { get; set; }
[JsonIgnore]
public decimal SchemaAmt { get; set; }
[JsonIgnore]
Expand Down
6 changes: 3 additions & 3 deletions DU-Industry-Tool/Classes/RecipeCalculation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RecipeCalculation : INotifyPropertyChanged

public RecipeCalculation(string section)
{
if (string.IsNullOrEmpty(section)) throw new ArgumentNullException(@"RecipeCalculation");
if (string.IsNullOrEmpty(section)) throw new ArgumentNullException(nameof(RecipeCalculation));
Section = section;
Id = Guid.NewGuid();
ParentId = Guid.Empty;
Expand Down Expand Up @@ -277,7 +277,7 @@ public IEnumerable GetChildren()
return children;
foreach (var schemaItem in calc.SumSchemClass)
{
if (!Calculator.CalcSchematic(schemaItem.Key, schemaItem.Value.Item1,
if (!Calculator.CalcSchematic(schemaItem.Key, Math.Round(schemaItem.Value.Item1, 3),
out var minCost, out var maxCost, out var copies))
{
continue;
Expand All @@ -288,7 +288,7 @@ public IEnumerable GetChildren()
{
Entry = schemaItem.Key,
QtySchemata = schemaItem.Value.Item1,
AmtSchemata = maxCost, //minCost,
AmtSchemata = minCost,
Comment = "C: "+Utils.GetReadableTime(copyTime)+
$" (x{copies}) {s.Cost * s.BatchSize:N2}q for {s.BatchSize}",
ParentId = Id
Expand Down
12 changes: 6 additions & 6 deletions DU-Industry-Tool/Forms/ContentDocumentTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void SetCalcResult(CalculatorClass calc)
// IF ore, then we basically display values from its Pure (except plasma)
// to have any useful information for it :)
Ore ore = null;
var batches = 1;
var batches = 1m;
var industry = calc.Recipe.Industry;

if (calc.IsOre || calc.IsPlasma)
Expand Down Expand Up @@ -172,7 +172,7 @@ public void SetCalcResult(CalculatorClass calc)
out batches , out var minCost, out var _, out var _))
{
// store values in main calc!
calc.AddSchema(calcP.SchematicType, (int)batches, minCost);
calc.AddSchema(calcP.SchematicType, batches, minCost);
calc.AddSchematicCost(minCost);
}
time = calc.BatchTime ?? time;
Expand Down Expand Up @@ -393,15 +393,15 @@ private void SetupGrid(CalculatorClass calc)
return "";
};

olvColumnQty.AspectGetter = x => (x is RecipeCalculation t && t.Qty > 0 ? $"{t.Qty:N2}" : "");
olvColumnAmt.AspectGetter = x => (x is RecipeCalculation t && t.Amt > 0 ? $"{t.Amt:N2}" : "");
olvColumnQty.AspectGetter = x => (x is RecipeCalculation t && t.Qty > 0 ? $"{t.Qty:N3}" : "");
olvColumnAmt.AspectGetter = x => (x is RecipeCalculation t && t.Amt > 0 ? $"{t.Amt:N3}" : "");
olvColumnMass.AspectGetter = x => (x is RecipeCalculation t && t.Mass > 0 ? $"{t.Mass:N3}" : "");
olvColumnVol.AspectGetter = x => (x is RecipeCalculation t && t.Vol > 0 ? $"{t.Vol:N3}" : "");

olvColumnSchemataQ.AspectGetter = x => (x is RecipeCalculation t && t.QtySchemata > 0
? (DUData.FullSchematicQuantities ? $"{t.QtySchemata:N0}" : $"{t.QtySchemata:N2}")
? (DUData.FullSchematicQuantities ? $"{t.QtySchemata:N0}" : $"{t.QtySchemata:N3}")
: "");
olvColumnSchemataA.AspectGetter = x => (x is RecipeCalculation t && t.AmtSchemata > 0 ? $"{t.AmtSchemata:N2}" : "");
olvColumnSchemataA.AspectGetter = x => (x is RecipeCalculation t && t.AmtSchemata > 0 ? $"{t.AmtSchemata:N3}" : "");

olvColumnTier.AspectGetter = x => (x is RecipeCalculation t && t.Tier > 0 ? $"{t.Tier}" : "");

Expand Down
2 changes: 1 addition & 1 deletion DU-Industry-Tool/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ private void ExportToSpreadsheetToolStripMenuItem_Click(object sender, EventArgs
var costToMake = Calculator.CalculateRecipe(recipe.Key, cnt, silent: true);
var calc = Calculator.Get(recipe.Key, Guid.Empty);

worksheet.Cell(row, 2).Value = Math.Round(costToMake,2);
worksheet.Cell(row, 2).Value = Math.Round(costToMake, 2);

var orders = _market.MarketOrders.Values.Where(o => o.ItemType == recipe.NqId && o.BuyQuantity < 0 && DateTime.Now < o.ExpirationDate && o.Price > 0);

Expand Down
4 changes: 2 additions & 2 deletions DU-Industry-Tool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2024.1.2.0")]
[assembly: AssemblyFileVersion("2024.1.2.0")]
[assembly: AssemblyVersion("2024.1.3.0")]
[assembly: AssemblyFileVersion("2024.1.3.0")]
2 changes: 1 addition & 1 deletion DU-Industry-Tool/Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.1.2
2024.1.3
6 changes: 6 additions & 0 deletions DU-Industry-Tool/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v2024.1.3

- Decided to use the "Full schematics" option also on the Schematics in the bottom calculation tree
- Quantities and amounts are now displayed rounded to 3 decimals
- With above also fixed in some cases schematics for products/ammo being rounded down instead of up

## v2024.1.2

- Fix: if quantity is below batch output, use at least 1 schematic for products/ammo, still
Expand Down
6 changes: 6 additions & 0 deletions latestchanges.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Latest Changes

## v2024.1.3

- Decided to use the "Full schematics" option also on the Schematics in the bottom calculation tree
- Quantities and amounts are now displayed rounded to 3 decimals
- With above also fixed in some cases schematics for products/ammo being rounded down instead of up

## v2024.1.2

- Fix: if quantity is below batch output, use at least 1 schematic for products/ammo, still
Expand Down

0 comments on commit 67aff73

Please sign in to comment.