For one of my uni subjects i was tasked to find some data in a time series and do something with them in Py (to learn Py). Normally people would get some publicly available data, but i thought of using production statistics from one of my vanilla Factorio save.
Unfortunately i dont know how to export the necessary data from my save.
Does anyone know, how to export production statistics from my save to csv or json?
Im including a copy of my save in case someone needed it.
Its a vanilla playthrough, doesnt have Space age DLC, game version 2.0.15
How to export production stats to csv/json from saves?
How to export production stats to csv/json from saves?
- Attachments
-
- 2.0 game.zip
- save file of my game
- (11.38 MiB) Downloaded 32 times
Re: How to export production stats to csv/json from saves?
Sounds like the Stats Saver mod. This covers "Live" data as you play the game.
If you wanted to get the Historical data for an existing Save you would need to iterate through the LuaFlowStatistics using get_flow_count for your chosen items/timeframes; then export using write_file.
Good Luck!
If you wanted to get the Historical data for an existing Save you would need to iterate through the LuaFlowStatistics using get_flow_count for your chosen items/timeframes; then export using write_file.
Good Luck!
Re: How to export production stats to csv/json from saves?
I made the following command (to be run in the console):
It should export all item production stats into json files in the script-output folder.
Item consumption stats could also be available (output category of LuaFlowStatistics), fluids/builds/kills production/consumption (see other get_*_statistics of LuaForce, electric network, or pollution stats.
Code: Select all
local timescales = {
[defines.flow_precision_index.five_seconds] = "5s",
[defines.flow_precision_index.one_minute] = "1min",
[defines.flow_precision_index.ten_minutes] = "10min",
[defines.flow_precision_index.one_hour] = "1h",
[defines.flow_precision_index.ten_hours] = "10h",
[defines.flow_precision_index.fifty_hours] = "50h",
[defines.flow_precision_index.two_hundred_fifty_hours] = "250h",
[defines.flow_precision_index.one_thousand_hours] = "1000h"
}
for surface_name, _ in pairs(game.surfaces) do
local flowdata = game.forces.player.get_item_production_statistics(surface_name)
for timescale_index, timescale_name in pairs(timescales) do
local tbl = {}
local totals = flowdata.input_counts
for item_name, _ in pairs(totals) do
local row = {item_name}
for i = 1, 300 do
table.insert(row, flowdata.get_flow_count{name=item_name, category="input", precision_index=timescale_index, sample_index=i, count=true})
end
table.insert(tbl, row)
end
helpers.write_file("stats-" .. surface_name .. "-" .. timescale_name .. ".json", helpers.table_to_json(tbl), false)
end
end
game.player.print("Export done")
Item consumption stats could also be available (output category of LuaFlowStatistics), fluids/builds/kills production/consumption (see other get_*_statistics of LuaForce, electric network, or pollution stats.
- Attachments
-
- 127078-2.0 game-stats-productions.zip
- (75.75 KiB) Downloaded 22 times
Re: How to export production stats to csv/json from saves?
Thank you both for you answers.

Thank you for your code and the file!

Thank you for your tip. I will check out the LuaFlowStatistics, how it works, so i can write about it in a report accompanying my Py code.eugenekay wrote: Sun Feb 23, 2025 6:35 pm If you wanted to get the Historical data for an existing Save you would need to iterate through the LuaFlowStatistics using get_flow_count for your chosen items/timeframes; then export using write_file.

Re: How to export production stats to csv/json from saves?
Added it (including Muche as a source) to to https://wiki.factorio.com/Production_statistics - This worked wonders. Thanks!eugenekay wrote: Sun Feb 23, 2025 8:06 pmWow, that looks like a good candidate to put on the Wiki for future reference! I was just spitballing how it could be achieved, and here is a complete implementation.![]()