greeny / SatisfactoryTools

Satisfactory Tools for planning and building the perfect base.
https://www.satisfactorytools.com/
MIT License
326 stars 66 forks source link

Power usage values are incorrect #91

Closed JakenVeina closed 2 years ago

JakenVeina commented 2 years ago

Call me crazy, but all the power consumption values seem to be wrong.

As an example.....

120/min Limestone => Concrete (2.6667x Constructor) => 40/min Concrete.

This reports a power usage of 11.105MW. By my reckoning, using the "underclock last machine" algorithm, the usage should be 10.091MW. That is, 8MW for the first 2 machines, and 4 * (0.6667 ^ 1.6) = 2.091MW for the third.

Looking at the code, it seems like you're just using the wrong formula for calculating power: https://github.com/greeny/SatisfactoryTools/blob/feb7d2d4046c32f7d90b00be66763157db34d8ed/src/Tools/Production/Result/MachineGroup.ts#L93

power += machine.amount * (this.recipeData.machine.metadata.powerConsumption * Math.pow(machine.clockSpeed / 100, 1 / this.recipeData.machine.metadata.powerConsumptionExponent));

Whereas, elsewhere in the codebase, you're using the correct formula: https://github.com/greeny/SatisfactoryTools/blob/c1282105295d003bccc4b9d6c156eb7d2c3db7ce/src/Formula.ts#L21

return Math.pow(overclock / 100, building.metadata.powerConsumptionExponent || Formula.defaultPowerProductionExponent) * (building.metadata.powerConsumption || 0);

Seems like you refactored yourself a utility method for calculating building power consumption, at some point, but missed a spot of code that should be using it.

greeny commented 2 years ago

You're absolutely right, I have no idea why did the 1 / x instead of x got there. Should be fixed in 87b6111