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.
Total electrical network consumption
Total electrical network consumption
Last edited by Xorimuth on Mon Aug 30, 2021 11:34 pm, edited 1 time in total.
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Re: Total electrical network consumption
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
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.
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Re: Total electrical network consumption
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
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Re: Total electrical network consumption
This is implemented in 1.1.60 by using LuaFlowStatistics.get_flow_count with the new sample_index parameter.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
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
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings