Page 1 of 1
Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 9:30 am
by eradicator
So after a recent discussion about train loading i thought it'd be nice to be able to measure belt throughput without elaborate circuit contraptions. I had an idea, but failed. So... does anybody have an idea how to do it?
(
For reference the failed idea was to track LuaItemStack as they enter and leave the belt. But from what i can tell they never do this and the same belt segment always has the same stacks. So i'm assuming they just change content, which isn't detectable on a fully compressed belt.)
Edit: More precisely i want to measure
- any belt (bonus points if it works on belts that already have circuitry attached)
- without any visible change to the belt (invisible changes are fine)
- preferably purely in control.lua stage
- performance is not a concern
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 9:58 am
by DaveMcW
There are no events that could help you. So you are stuck with doing everything in on_tick.
You can port the circuit contraptions to lua I guess?
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 10:02 am
by eradicator
DaveMcW wrote: Mon Sep 16, 2019 9:58 am
There are no events that could help you. So you are stuck with doing everything in on_tick.
You can port the circuit contraptions to lua I guess?
On_tick is obvious, the problem is that there is no API for getting any sort of speed data at all. The contraptions work by wiring up a belt and setting it to pulse mode. But there is no API equivalent to a pulse. So if there even *is* a solution i think it'll have to do some pretty obscure voodoo.
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 10:05 am
by DaveMcW
The most efficient way seems to be connecting a wire and checking the circuit network every tick.
So only the combinators are replaced by lua. At that point, is your lua more elaborate than the combinators?
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 10:25 am
by eradicator
DaveMcW wrote: Mon Sep 16, 2019 10:05 am
The most efficient way seems to be connecting a wire and checking the circuit network every tick.
That is measuring the circuit network, not the belt. I know how to do that already. I'm looking for a magic way to calculate/interpolate/guess the throughput of a belt
without changing the state of the belt.
Reason: Proof of concept. I just want to know if it's possible.
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 10:33 am
by darkfrei
https://lua-api.factorio.com/latest/Lua ... tLine.html
What the different between moving items and not moving items / not full speed moving items?
You can place in the middle the belt with higher tier and calculate how many items is on it. On the moving line you has less items than on the stopped one.
You can place to the belt one special item and check the position of it.
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 10:40 am
by eradicator
darkfrei wrote: Mon Sep 16, 2019 10:33 am
What the different between moving items and not moving items / not full speed moving items?
I think they're the same.
darkfrei wrote: Mon Sep 16, 2019 10:33 am
You can place in the middle the belt with higher tier and calculate how many items is on it. On the moving line you has less items than on the stopped one.
A completely stopped belt has 8 items, a fully compressed belt at full speed also has 8 items.
darkfrei wrote: Mon Sep 16, 2019 10:33 am
You can place to the belt one special item and check the position of it.
LuaStack does not have a "position".
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 10:59 am
by darkfrei
The red belt after yellow belt is not full when it moves and full when the belt is stopped.
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 11:05 am
by eradicator
darkfrei wrote: Mon Sep 16, 2019 10:59 am
The red belt
after yellow belt is not full when it moves and full when the belt is stopped.
I don't see how that helps. Modded belts can have any maximum speed. And measurement has to work for any speed. If a blue belt has a throughput of 0.5i/s because the factory is stalled, then i still want to be able to measure that.
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 1:05 pm
by mrvn
Note that you can have quite a number of native combinators before the CPU cost approaches the cost of the LUA on_tick() call.
Re: Measuring belt througput in lua.
Posted: Mon Sep 16, 2019 8:39 pm
by eradicator
For the record:
I got it working by swapping the first stack of a transport belt with a "tracker" item, then measuring how long it takes to reach the last stack of the next belt piece. Thus getting a "pulse" equal to a circuit connected belt.