Total electrical network consumption

Xorimuth
Filter Inserter
Filter Inserter
Posts: 704
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Total electrical network consumption

Post 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.
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
ichVII
Fast Inserter
Fast Inserter
Posts: 117
Joined: Mon Feb 27, 2017 10:16 pm
Contact:

Re: Total electrical network consumption

Post 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
Xorimuth
Filter Inserter
Filter Inserter
Posts: 704
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Total electrical network consumption

Post 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.
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Xorimuth
Filter Inserter
Filter Inserter
Posts: 704
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Total electrical network consumption

Post 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 :D
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Xorimuth
Filter Inserter
Filter Inserter
Posts: 704
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Total electrical network consumption

Post 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 :D
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
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Post Reply

Return to “Implemented mod requests”