Determining performance impact of low_power state

Place to get help with not working mods / modding interface.
Post Reply
User avatar
blargh2015
Inserter
Inserter
Posts: 28
Joined: Sun Jun 03, 2018 3:47 pm
Contact:

Determining performance impact of low_power state

Post by blargh2015 »

So for my UtilizationMonitorBlargh mod, I'm looking for a way to determine just how slow a machine is going due to entity.status == defines.entity_status.low_power.

For example, if an assembler or research lab or whatever is in low_power and is only performing at 50% speed because of that, I'm wanting 0.5.

Any one have a pointer?

Thanks!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Determining performance impact of low_power state

Post by eradicator »

My best guess would've been

Code: Select all

current_energy / energy_buffer_size
But when trying it the number is slightly wrong. LuaEntity.energy is larger than expected and I don't know where the difference comes from. Adding drain to capacity gets it closer but feels weird.

Code: Select all

local inaccurate_speed = LuaEntity.crafting_speed
  * (LuaEntity.energy
    /
    (LuaEntity.prototype.electric_energy_source_prototype.buffer_capacity
      + LuaEntity.prototype.electric_energy_source_prototype.drain
      )
    )
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
blargh2015
Inserter
Inserter
Posts: 28
Joined: Sun Jun 03, 2018 3:47 pm
Contact:

Re: Determining performance impact of low_power state

Post by blargh2015 »

My other concern is (at least according to posts and such) not all entities are created equal in low power states - for example defenses have power priority over machines. I THOUGHT I had saw somewhere that machines CAN have more than a simple-ratio impact of the available power as well (i.e. loss of 10% of power is a 50% loss in performance), but not finding where I saw that at the moment.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2247
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Determining performance impact of low_power state

Post by boskid »

low_power state shows in case of entity with electric energy source which has availableEnergy below 90,909% of the buffer size. That state is irrelevant for the performance computation. Crafting machines (assembling machines, furnaces, rocket silo) use performance value:

Code: Select all

craftingMachinePerformance = fractionOfRequestedEnergyDelivered * prototype.craftingSpeed * (1 + speedBonus)
fractionOfRequestedEnergyDelivered depends on the requested energy:

Code: Select all

requestedEnergy = prototype.energyUsage * (1 + consumptionBonus)
fractionOfRequestedEnergyDelivered = min(requestedEnergy, availableEnergy) / requestedEnergy
In case of a Lab, performance value:

Code: Select all

labPerfornance = fractionOfRequestedEnergyDelivered  * prototype.researchingSpeed * (1 + force.labSpeedModifier) * (1 + speedBonus)
Combinators have binary performance (either 0 or 1): they update only if requestedEnergy >= availableEnergy.

Those are some coarse formulas, i cannot guarantee anything about them (also no support nor feedback will be given if anything changes), and for other entities they will be most likely completly wrong (for example inserter takes energy twice: once for rotation and once for changing hand distance, pump takes energy twice when pumping into a fluid wagon). In general the performance of a machine is related to the amount of energy entity wants versus what it has in the buffer. Some entities may have buffer just enough to feed them every tick

In general the performance computation for any entity depends only on the available energy and buffer size of the energy source during the given tick. If there are some defenses they simply have higher usage priority (if they were defined as such) which drives the electric energy update to transfer energy to them first (to top up their buffer) and only when their buffers are full and there is more energy available to transfer from producers: to fill energy buffers of entities with lower energy usage priority (following the energy fair share: if all entities on given priority need total of 100J and there is only 50J left available from producers, entities will get 50% of their requested value: entity entity A wanted 80J will get 40J while entity B that requested 20J will get 10J). Electric energy sources request min(bufferSize - availableEnergy, inputFlowLimit).

In the performance computation you can ignore the energy drain as it is the amount of energy taken out from the energy buffer just before the demand value is computed - drain is the last to be taken out from the buffer so if there is not enough energy in the buffer after entity update, the drain will not apply at all or will be reduced to the amount of energy remaining. If there was enough energy left for the drain that means the energy in the buffer before update was greater than requested by the entity so the fractionOfRequestedEnergyDelivered was equal to 1. For example assembling-machine-3 has 12,5kW of drain and takes 388kW (387,5kW in fact) when working (no modules). If you deliver just 375kW assembling-machine-3 will work at full performance because during update there was enough energy to get full performance and there was no energy left for the drain. In this state assembling machine will complain it has low power while still working at full performance. This is easy to verify using Electric Energy Interface: if you set it to produce 6250 [+reduce buffer] (which is equal to 6250*60 = 375000 -> 375kW) the assembling machine will be producing at the same rate as fully powered one but if you reduce the energy production below that you will notice in long term it starts to produce slighly less.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Determining performance impact of low_power state

Post by eradicator »

Aha. I assumed the buffer size would be exactly one tick for assembling machines, but it's actually slightly larger than energy_usage + buffer_capacity. But using LuaEntity.energy_usage i can get a value that looks correct:

Code: Select all

/sudo machine = that print(math.min(machine.energy, machine.prototype.energy_usage)/machine.prototype.energy_usage * machine.crafting_speed)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
blargh2015
Inserter
Inserter
Posts: 28
Joined: Sun Jun 03, 2018 3:47 pm
Contact:

Re: Determining performance impact of low_power state

Post by blargh2015 »

Thanks eradicator and boskid for the info and the pointers - I've updated UtilizaitonMonitorBlargh (https://mods.factorio.com/mod/UtilizationMonitorBlargh) with the code adopted from this thread.

Post Reply

Return to “Modding help”