[0.14.20] Huge (probably negative) item counts in a logistic_network

Bugs that are actually features.
Skandragon
Inserter
Inserter
Posts: 29
Joined: Fri Nov 18, 2016 9:26 am
Contact:

[0.14.20] Huge (probably negative) item counts in a logistic_network

Post by Skandragon »

I'm using code to iterate through all logistics networks and ultimately write this data to a json file. My code looks like this:

Code: Select all

    for name, nets in pairs(force.logistic_networks) do
      local netData = {}
      for i, net in ipairs(nets) do
        local data = {
          items = net.get_contents(),
          available_logistic_robots = net.available_logistic_robots,
          all_logistic_robots = net.all_logistic_robots,
          all_construction_robots = net.all_construction_robots,
          available_construction_robots = net.available_construction_robots,
        }
        netData[#netData + 1] = data
      end
        
      statistic.logistics[name] = netData
    end
However, for some items returned by get_contents() I get very large numbers, which are likely negative:

"low-density-structure": 4294967242

This appears to happen when the amount available in the network is zero, and it is being requested.

If I disable the rocket building, the number goes to a small integer of approximately the value I'd expect, once the requestor chests are satisfied.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15915
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.14.20] Huge (probably negative) item counts in a logistic_network

Post by Rseding91 »

That's expected. The logistic network stores counts using signed numbers so you can have negative items after accounting for robots on-the-way.

When they're exported to Lua they're converted to unsigned numbers and so you see the huge number instead of a negative.
If you want to get ahold of me I'm almost always on Discord.
Skandragon
Inserter
Inserter
Posts: 29
Joined: Fri Nov 18, 2016 9:26 am
Contact:

Re: [0.14.20] Huge (probably negative) item counts in a logistic_network

Post by Skandragon »

Ahh, then negative means "in flight" -- doesn't this make the counts sort of strange, as I could have 100 of them in a chest, 10 in flight, and get the inaccurate count of 90?
Rseding91
Factorio Staff
Factorio Staff
Posts: 15915
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.14.20] Huge (probably negative) item counts in a logistic_network

Post by Rseding91 »

Skandragon wrote:Ahh, then negative means "in flight" -- doesn't this make the counts sort of strange, as I could have 100 of them in a chest, 10 in flight, and get the inaccurate count of 90?
The method simply extracts the values you'd see if you moused over a logistic container and looked at the right-pane display. It's also the count that anything uses when checking logistic network conditions.

The network doesn't have a quick-access count of items actually in containers since that's meaningless to the normal operation of the network.
If you want to get ahold of me I'm almost always on Discord.
Skandragon
Inserter
Inserter
Posts: 29
Joined: Fri Nov 18, 2016 9:26 am
Contact:

Re: [0.14.20] Huge (probably negative) item counts in a logistic_network

Post by Skandragon »

Rseding91 wrote:The method simply extracts the values you'd see if you moused over a logistic container and looked at the right-pane display.
Except I never see negative or huge values in the right-hand display. :)
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: [0.14.20] Huge (probably negative) item counts in a logistic_network

Post by daniel34 »

Skandragon wrote:
Rseding91 wrote:The method simply extracts the values you'd see if you moused over a logistic container and looked at the right-pane display.
Except I never see negative or huge values in the right-hand display. :)
There are no huge numbers in the right-hand display - they are displayed as negatives.

The reason you're not seeing the negative numbers is that the right-hand display doesn't have enough space to show all items in the logistic network, and it sorts them by amount which means that negative numbers will be at the end of the list. If you look at a small enough (in terms of different items) logistics network that is requesting items not in storage then you'll see these negative numbers.

Imagine an engine production where the only chest connected to the logistics network is the passive provider the engines are placed in. If the chest only contains 2 engines but the carrying capacity of robots is 5 and the requester chest allows for 5 or more engines, then the logistic network will state -3 on the right-hand display (or a huge 4294... number in lua which actually is 2^32 -3) while the logistics robot is in flight picking up the engines.
quick links: log file | graphical issues | wiki
Rseding91
Factorio Staff
Factorio Staff
Posts: 15915
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.14.20] Huge (probably negative) item counts in a logistic_network

Post by Rseding91 »

What I can do is have it return the counts as signed values so you get negative results from the get_contents call.
If you want to get ahold of me I'm almost always on Discord.
Skandragon
Inserter
Inserter
Posts: 29
Joined: Fri Nov 18, 2016 9:26 am
Contact:

Re: [0.14.20] Huge (probably negative) item counts in a logistic_network

Post by Skandragon »

Knowing the negative value would work easier than knowing I must subtract 2^32 if it's > 2^31... I doubt you'll ever make it a 64-bit value but just in case! :)

What I really sort of want is the true amount of available resources, which should never be negative to start with as I cannot have -1 iron plate.

A counter for "number of items robots can pick up", "number of items in transit", and perhaps even "number of items demanded". I suspect I can find the number of items demanded by iterating through all requestor chests, but this seems like it'd be a performance issue -- that said, an atomic counter updated per logistics network seems like it should be fast.

My use case is this: I want to make a web-based dashboard showing production statistics with alerting based on lack of items, where demand > supply, and by how much.
Post Reply

Return to “Not a bug”