Page 1 of 1
Total electrical network consumption
Posted: Tue Jan 26, 2021 1:16 am
by Xorimuth
I'm trying to get the total power flow (aka consumption) across a network which I think that I can calculate by summing LuaFlowStatistics.get_flow_count{name=name, input=true, precision_index=defines.flow_precision_index.five_seconds} across all names in LuaFlowStatistics.input_counts.
This will be quite slow in a large base, so would it be possible to expose the single number that I'm looking for? I don't mind if it is a tick out of date, but let me know if I'm actually misunderstanding how it all works.
Re: Total electrical network consumption
Posted: Tue Jan 26, 2021 2:01 am
by ichVII
Have you actually tried that? It seems to me like it should only include one entry per type of power generating entity (so one for steam engine, one for steam turbine, one for solar panel, and one for accumulator). That wouldnt be any problem
Re: Total electrical network consumption
Posted: Tue Jan 26, 2021 2:16 am
by Xorimuth
ichVII wrote: ↑Tue Jan 26, 2021 2:01 am
Have you actually tried that? It seems to me like it should only include one entry per type of power generating entity (so one for steam engine, one for steam turbine, one for solar panel, and one for accumulator). That wouldnt be any problem
Well this is consumption, so it will be one for every entity that consumes electricity, which includes all types of inserters, assembling machines and who knows how many modded machines. It isn't the end of the world if I have to calculate it myself, but this will be happening in an extremely performance sensitive part of the code, so I really want it to happen as quick as possible.
Re: Total electrical network consumption
Posted: Tue Feb 02, 2021 6:07 pm
by Xorimuth
I've implemented the calculation myself and it works ok. However, the minimum time to get the data across is 5 seconds, which means that the true network consumption value is often delayed by 5 seconds. The in game consumption meter is calculated based on the previous tick only. This means that this value cannot be perfectly calculated with workarounds, so the request is still open
Re: Total electrical network consumption
Posted: Mon Jun 06, 2022 2:54 pm
by Xorimuth
Xorimuth wrote: ↑Tue Feb 02, 2021 6:07 pm
I've implemented the calculation myself and it works ok. However, the minimum time to get the data across is 5 seconds, which means that the true network consumption value is often delayed by 5 seconds. The in game consumption meter is calculated based on the previous tick only. This means that this value cannot be perfectly calculated with workarounds, so the request is still open
This is implemented in 1.1.60 by using
LuaFlowStatistics.get_flow_count with the new sample_index parameter.
e.g.
Code: Select all
local total = 0
for name, _ in pairs(statistics.input_counts) do
total = total + 60 * statistics.get_flow_count{
name = name,
input = true,
precision_index = defines.flow_precision_index.five_seconds,
sample_index = 1,
count = false,
}
end