Electric network information (LuaFlowStatistics)

Place to get help with not working mods / modding interface.
Post Reply
ArCePi
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue Jun 05, 2018 5:21 pm
Contact:

Electric network information (LuaFlowStatistics)

Post by ArCePi »

Hello:

I'm trying to develop a mod to incorporate into the circuit network the current power production and consumption information. I'd be happy just to create an entity that exported as signals the 'satisfaction' and 'production' values that can be seen on the Electric Network Info window.

I'm trying reading electric power information using the electric_network_statistics attribute of a powerpole entity but I don't understand what information I'm getting.

I can iterate over all the consumers and producers (iterating on the producers I see many steam-turbine and steam-engine so it seems to work) but I don't know how to interpret the value associated. I'd expect it to be the current production in watts or something like that but I get a very big float number that doesn't look to me that has any correlation with the current production.

I've been searching in the forum and using Google but I can't find any information on what data LuaFlowStatistics has.

Thanks!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13218
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Electric network information (LuaFlowStatistics)

Post by Rseding91 »

If you want to get ahold of me I'm almost always on Discord.

ArCePi
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue Jun 05, 2018 5:21 pm
Contact:

Re: Electric network information (LuaFlowStatistics)

Post by ArCePi »

Thanks!

I had already read that API documentation but what I did not understand is what the value returned for each source meant.

This might be pretty obvious when you have experience developing mods, but for me it wasn't. Just in case somebody has the same question and for future reference:

What it returns seems to be joules produced or consumed (since the beginning of time?). If you get the statistics every, for example, 300 ticks (5 seconds), calculate the difference and divide by 5, you get the average Watts used or produced by every source or consumer in that 5 second period.

Anyway, I was trying to get the current power demand, but this does not seem to be the way.

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

Re: Electric network information (LuaFlowStatistics)

Post by eradicator »

Energy is always measured per tick internally.
One second has 60 ticks, so 1Joule/tick = 60Joule/second = 60Watt.

The current demand for a single entity is as far as i know simply the difference between buffer_size and buffer content. How that works on a network level i have no clue of :x

ArCePi
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue Jun 05, 2018 5:21 pm
Contact:

Re: Electric network information (LuaFlowStatistics)

Post by ArCePi »

eradicator wrote:Energy is always measured per tick internally.
One second has 60 ticks, so 1Joule/tick = 60Joule/second = 60Watt.

The current demand for a single entity is as far as i know simply the difference between buffer_size and buffer content. How that works on a network level i have no clue of :x
It seems that as you say electric_buffer_size is the energy amount that the entity demanded in the last tick (although I get 2755 for assembling-machine-2 entities and I don't know how to get 150kW from that figure). I found in another post that 'energy' value is the energy consumed in the last tick by the entity. Subtracting both I can get the amount of energy that is not being satisfied.

What I wanted to do is to be able to turn on and off steam engines to meet demand but priorizing the power generated by a nuclear reactor. For that I need to know how much electricity is being produced in the network and how much demand there is.

How much is being produced can be obtained with the LuaFlowStatistics returned by an electric pole and I already fill circuit network signals with that information. However I think that there's no easy way of getting how much electrical demand there is for an electric network. I figure that internally the game engine should already have this information but it is not exported.

Should I open an API request?

Thanks!

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

Re: Electric network information (LuaFlowStatistics)

Post by eradicator »

ArCePi wrote: What I wanted to do is to be able to turn on and off steam engines to meet demand but priorizing the power generated by a nuclear reactor. For that I need to know how much electricity is being produced in the network and how much demand there is.
If that is your only goal it should be sufficient to make steam turbines higher priority than steam engines. Or add a new high-priority turbine if you don't want to change the vanilla one.

Code: Select all

data.raw.generator['steam-turbine'].energy_source.usage_priority = 'primary-output'

Post Reply

Return to “Modding help”