[Twinsen][0.17.43] Production statistics graph not updated on_flow without production

This subforum contains all the issues which we already resolved.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

[Twinsen][0.17.43] Production statistics graph not updated on_flow without production

Post by Qon »

What?
The graph doesn't show the production values when you use on_flow to insert values to the statistics flow if you have no previous machine production of that item. And then when I try again the graph does work, but the values are incorrect in the table above instead!

So yes, here's 2 different bugs that occur together.

It's one report because the reproduction steps, evidence, savefile and code is the same.
Reproduction and screenshots
If you start a new world produce some automation-science-pack in an assembler and run

Code: Select all

game.player.force.item_production_statistics.on_flow('automation-science-pack', 10000)
You get expected results.
ousu(190529-161539-18).jpg
ousu(190529-161539-18).jpg (473.33 KiB) Viewed 2693 times
And wait a few seconds to avoid overlap:

Code: Select all

game.player.force.item_production_statistics.on_flow('logistic-science-pack', 10000)
ousu(190529-161606-33).jpg
ousu(190529-161606-33).jpg (488.18 KiB) Viewed 2693 times
Notice that the orange graph is just a little line in the bottom corner of the graph.

I ran the command for logistic-science-pack again:
ousu(190529-162031-23).jpg
ousu(190529-162031-23).jpg (435.25 KiB) Viewed 2693 times
Now I get a bump in the graph, but the table shows 8.7k instead instead of the 10k I wrote in my command!

And here with military science (11k) and I get no graph again but correct table value:
ousu(190529-162107-88).jpg
ousu(190529-162107-88).jpg (498.31 KiB) Viewed 2693 times
So again first flow without production gives correct table values but incorrect graphs.

All time stats are correct:
ousu(190529-162757-29).jpg
ousu(190529-162757-29).jpg (378.14 KiB) Viewed 2693 times
Attachments
flowBug.zip
(1.94 MiB) Downloaded 145 times
factorio-current.log
(88.33 KiB) Downloaded 160 times
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Twinsen
Factorio Staff
Factorio Staff
Posts: 1359
Joined: Tue Sep 23, 2014 7:10 am
Contact:

Re: [Twinsen][0.17.43] Production statistics graph not updated on_flow without production

Post by Twinsen »

Because of the smoothing window, when an item was first added to the graph, it got eaten up by the smoothing logic.
Should be fixed now in Version: 0.17.44.

I made other changes to the statistics windows so let me know if you notice anything else that is strange.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: [Twinsen][0.17.43] Production statistics graph not updated on_flow without production

Post by Qon »

Thanks! <3

Is there documentation on how on_flow point-like addition to the stats affect the graph during some amount of seconds? Flowing 10k as in the screenshots shows gives a square wave instead of a single frame spike. Is it always the same time the addition is extended too? Or why do I get 68k/minute for 10~ish seconds on the graph when count=10000 with no duration parameter? 68k/min = 1.1333k/second. So duration should be 8.82 seconds duration to reach 10k, which looks like the width estimate of the graph peak. Obviously a single frame peak would look ridiculous and make the graph unreadable but it would be nice to know how it works.

Also the numbers, when shown correctly, don't seem at all connected to the integral of the graph. I get 10k/minute immediately when I get it even though the graph shows nothing yet or just the beginning of the "hill".

Might be useful to know how the graph is or isn't connected to the numbers when using them to debug my mod that uses on_flow. Because I tried to use the incorrect 8.7k (well, the actual example had more complicated dynamic counts so it wasn't that easy to spot the problems) at first to understand where my on_flow count got so wrong until I understood that the game was bugged q:

on_flow sounds like a LuaEvent or script.on_flow method to me, why isn't it named just `flow` or something? Well doesn't really matter...
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Twinsen
Factorio Staff
Factorio Staff
Posts: 1359
Joined: Tue Sep 23, 2014 7:10 am
Contact:

Re: [Twinsen][0.17.43] Production statistics graph not updated on_flow without production

Post by Twinsen »

The graph has 300 data points. Which means each data point represents (selected_timeframe_in_ticks / 300) ticks
The graph is smoothed using a sliding window with the size 1 + floor(150 / sqrt(selected_timeframe_in_ticks / 300))

Code: Select all

  for (uint32_t i = 0; i < smoothingWindowSize; ++i)
    sum += input.history[i];

  for (uint32_t i = smoothingWindowSize; i < input.history.max_size(); ++i)
  {
    sum += input.history[i];
    sum -= input.history[i - smoothingWindowSize];
    graph.push_back(Math::max(0.0f, sum / smoothingWindowSize));
  }
}
So one spike of 10k makes the smoothing window contain a sum of 10k. So for 1 minute time frame selected, each graph data point is 10k / (1 + floor(150 / sqrt(12)) = 10k / 44 = 227.(27). Since one data point represents 12 ticks, that means the graph should show 227.(27) / 12 = 18.(93) items per tick. That is 18.(93) * 60 * 60 = 68181.(81) items per minute.

You asked for it, you got math :P
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: [Twinsen][0.17.43] Production statistics graph not updated on_flow without production

Post by Qon »

Twinsen wrote: Thu May 30, 2019 7:11 pm You asked for it, you got math :P
And you delivered!
Thanks for the math, code, explanation and example <3
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Post Reply

Return to “Resolved Problems and Bugs”