Update all code styles

This commit is contained in:
Cooldude2606
2024-09-28 01:56:54 +01:00
parent 5e2a62ab27
commit 292c1a1b68
194 changed files with 9817 additions and 9703 deletions

View File

@@ -5,186 +5,192 @@ local config = require("modules.exp_legacy.config.graftorio")
local lib = {}
lib.collect_production = function()
for _, force in pairs(game.forces) do
general.data.output[force.name].production = {}
for _, surface in pairs(game.surfaces) do
---@class ItemStats
---@field count number
for _, force in pairs(game.forces) do
general.data.output[force.name].production = {}
for _, surface in pairs(game.surfaces) do
--- @class ItemStats
--- @field count number
---@class ProductionStatistics
---@field item_input table<string, ItemStats>
---@field item_output table<string, ItemStats>
---@field fluid_input table<string, ItemStats>
---@field fluid_output table<string, ItemStats>
---@field kill_input table<string, ItemStats>
---@field kill_output table<string, ItemStats>
---@field build_input table<string, ItemStats>
---@field build_output table<string, ItemStats>
local stats = {
item_input = {},
item_output = {},
fluid_input = {},
fluid_output = {},
kill_input = {},
kill_output = {},
build_input = {},
build_output = {},
}
--- @class ProductionStatistics
--- @field item_input table<string, ItemStats>
--- @field item_output table<string, ItemStats>
--- @field fluid_input table<string, ItemStats>
--- @field fluid_output table<string, ItemStats>
--- @field kill_input table<string, ItemStats>
--- @field kill_output table<string, ItemStats>
--- @field build_input table<string, ItemStats>
--- @field build_output table<string, ItemStats>
local stats = {
item_input = {},
item_output = {},
fluid_input = {},
fluid_output = {},
kill_input = {},
kill_output = {},
build_input = {},
build_output = {},
}
for name, count in pairs(force.get_item_production_statistics(surface).input_counts) do
local itemstats = stats.item_input[name] or {}
itemstats.count = count
stats.item_input[name] = itemstats
end
for name, count in pairs(force.get_item_production_statistics(surface).output_counts) do
local itemstats = stats.item_output[name] or {}
itemstats.count = count
stats.item_output[name] = itemstats
end
for name, count in pairs(force.get_item_production_statistics(surface).input_counts) do
local itemstats = stats.item_input[name] or {}
itemstats.count = count
stats.item_input[name] = itemstats
end
for name, count in pairs(force.get_fluid_production_statistics(surface).input_counts) do
local fluidstats = stats.fluid_input[name] or {}
fluidstats.count = count
stats.fluid_input[name] = fluidstats
end
for name, count in pairs(force.get_fluid_production_statistics(surface).output_counts) do
local fluidstats = stats.fluid_output[name] or {}
fluidstats.count = count
stats.fluid_output[name] = fluidstats
end
for name, count in pairs(force.get_item_production_statistics(surface).output_counts) do
local itemstats = stats.item_output[name] or {}
itemstats.count = count
stats.item_output[name] = itemstats
end
for name, count in pairs(force.get_kill_count_statistics(surface).input_counts) do
local killstats = stats.kill_input[name] or {}
killstats.count = count
stats.kill_input[name] = killstats
end
for name, count in pairs(force.get_kill_count_statistics(surface).output_counts) do
local killstats = stats.kill_output[name] or {}
killstats.count = count
stats.kill_output[name] = killstats
end
for name, count in pairs(force.get_fluid_production_statistics(surface).input_counts) do
local fluidstats = stats.fluid_input[name] or {}
fluidstats.count = count
stats.fluid_input[name] = fluidstats
end
for name, count in pairs(force.get_entity_build_count_statistics(surface).input_counts) do
local buildstats = stats.build_input[name] or {}
buildstats.count = count
stats.build_input[name] = buildstats
end
for name, count in pairs(force.get_entity_build_count_statistics(surface).output_counts) do
local buildstats = stats.build_output[name] or {}
buildstats.count = count
stats.build_output[name] = buildstats
end
for name, count in pairs(force.get_fluid_production_statistics(surface).output_counts) do
local fluidstats = stats.fluid_output[name] or {}
fluidstats.count = count
stats.fluid_output[name] = fluidstats
end
general.data.output[force.name].production[surface.name] = stats
end
end
for name, count in pairs(force.get_kill_count_statistics(surface).input_counts) do
local killstats = stats.kill_input[name] or {}
killstats.count = count
stats.kill_input[name] = killstats
end
for name, count in pairs(force.get_kill_count_statistics(surface).output_counts) do
local killstats = stats.kill_output[name] or {}
killstats.count = count
stats.kill_output[name] = killstats
end
for name, count in pairs(force.get_entity_build_count_statistics(surface).input_counts) do
local buildstats = stats.build_input[name] or {}
buildstats.count = count
stats.build_input[name] = buildstats
end
for name, count in pairs(force.get_entity_build_count_statistics(surface).output_counts) do
local buildstats = stats.build_output[name] or {}
buildstats.count = count
stats.build_output[name] = buildstats
end
general.data.output[force.name].production[surface.name] = stats
end
end
end
lib.collect_loginet = function()
for _, force in pairs(game.forces) do
---@class RobotStatistics
---@field all_construction_robots uint
---@field available_construction_robot uint
---@field all_logistic_robots uint
---@field available_logistic_robots uint
---@field charging_robot_count uint
---@field to_charge_robot_count uint
---@field items table<string, uint>
---@field pickups table<string, uint>
---@field deliveries table<string, uint>
local stats = {
all_construction_robots = 0,
available_construction_robots = 0,
for _, force in pairs(game.forces) do
--- @class RobotStatistics
--- @field all_construction_robots uint
--- @field available_construction_robot uint
--- @field all_logistic_robots uint
--- @field available_logistic_robots uint
--- @field charging_robot_count uint
--- @field to_charge_robot_count uint
--- @field items table<string, uint>
--- @field pickups table<string, uint>
--- @field deliveries table<string, uint>
local stats = {
all_construction_robots = 0,
available_construction_robots = 0,
all_logistic_robots = 0,
available_logistic_robots = 0,
all_logistic_robots = 0,
available_logistic_robots = 0,
charging_robot_count = 0,
to_charge_robot_count = 0,
charging_robot_count = 0,
to_charge_robot_count = 0,
items = {},
pickups = {},
deliveries = {},
}
for _, networks in pairs(force.logistic_networks) do
for _, network in pairs(networks) do
stats.available_construction_robots = network.available_construction_robots
stats.all_construction_robots = network.all_construction_robots
items = {},
pickups = {},
deliveries = {},
}
for _, networks in pairs(force.logistic_networks) do
for _, network in pairs(networks) do
stats.available_construction_robots = network.available_construction_robots
stats.all_construction_robots = network.all_construction_robots
stats.available_logistic_robots = network.available_logistic_robots
stats.all_logistic_robots = network.all_logistic_robots
stats.available_logistic_robots = network.available_logistic_robots
stats.all_logistic_robots = network.all_logistic_robots
stats.charging_robot_count = 0
stats.to_charge_robot_count = 0
for _, cell in pairs(network.cells) do
stats.charging_robot_count = (stats.charging_robot_count) + cell.charging_robot_count
stats.to_charge_robot_count = (stats.to_charge_robot_count) + cell.to_charge_robot_count
end
stats.charging_robot_count = 0
stats.to_charge_robot_count = 0
for _, cell in pairs(network.cells) do
stats.charging_robot_count = (stats.charging_robot_count) + cell.charging_robot_count
stats.to_charge_robot_count = (stats.to_charge_robot_count) + cell.to_charge_robot_count
end
if config.modules.logistorage then
for name, v in pairs(network.get_contents()) do
stats.items[name] = (stats.items[name] or 0) + v
end
if config.modules.logistorage then
for name, v in pairs(network.get_contents()) do
stats.items[name] = (stats.items[name] or 0) + v
end
-- pickups and deliveries of items
for _, point_list in pairs({ network.provider_points, network.requester_points, network.storage_points }) do
for _, point in pairs(point_list) do
for name, qty in pairs(point.targeted_items_pickup) do
stats.pickups[name] = (stats.pickups[name] or 0) + qty
end
for name, qty in pairs(point.targeted_items_deliver) do
stats.deliveries[name] = (stats.deliveries[name] or 0) + qty
end
end
end
end
end
end
general.data.output[force.name].robots = stats
end
-- pickups and deliveries of items
for _, point_list in pairs{ network.provider_points, network.requester_points, network.storage_points } do
for _, point in pairs(point_list) do
for name, qty in pairs(point.targeted_items_pickup) do
stats.pickups[name] = (stats.pickups[name] or 0) + qty
end
for name, qty in pairs(point.targeted_items_deliver) do
stats.deliveries[name] = (stats.deliveries[name] or 0) + qty
end
end
end
end
end
end
general.data.output[force.name].robots = stats
end
end
---@class Research
---@field name string
---@field level uint
---@field progress double
--- @class Research
--- @field name string
--- @field level uint
--- @field progress double
Event.add(defines.events.on_research_finished, function(evt)
local research = evt.research
if not general.data.output[research.force.name] then general.data.output[research.force.name] = {} end
if not general.data.output[research.force.name].research then general.data.output[research.force.name].research = {} end
local research = evt.research
if not general.data.output[research.force.name] then general.data.output[research.force.name] = {} end
if not general.data.output[research.force.name].research then general.data.output[research.force.name].research = {} end
local force_research = general.data.output[research.force.name].research or {}
table.remove(force_research, 1)
general.data.output[research.force.name].research = force_research
local force_research = general.data.output[research.force.name].research or {}
table.remove(force_research, 1)
general.data.output[research.force.name].research = force_research
end)
Event.add(defines.events.on_research_started, function(evt)
-- move queue up
local research = evt.research
if not general.data.output[research.force.name].research then general.data.output[research.force.name].research = {} end
-- move queue up
local research = evt.research
if not general.data.output[research.force.name].research then general.data.output[research.force.name].research = {} end
local force_research = general.data.output[research.force.name].research or {}
table.remove(force_research, 1)
general.data.output[research.force.name].research = force_research
local force_research = general.data.output[research.force.name].research or {}
table.remove(force_research, 1)
general.data.output[research.force.name].research = force_research
end)
Event.on_nth_tick(60, function()
for _, force in pairs(game.forces) do
if not general.data.output[force.name].research then general.data.output[force.name].research = {} end
for _, force in pairs(game.forces) do
if not general.data.output[force.name].research then general.data.output[force.name].research = {} end
local force_research = {}
-- this works even if the queue is disabled, but it will always be just 1 long in that case
for _, research in pairs(force.research_queue) do
table.insert(force_research, {
name = research.name,
level = research.level,
progress = force.get_saved_technology_progress(research) or 0,
})
end
local force_research = {}
-- this works even if the queue is disabled, but it will always be just 1 long in that case
for _, research in pairs(force.research_queue) do
table.insert(force_research, {
name = research.name,
level = research.level,
progress = force.get_saved_technology_progress(research) or 0,
})
end
general.data.output[force.name].research = force_research
end
general.data.output[force.name].research = force_research
end
end)
return lib

View File

@@ -4,60 +4,60 @@ local Storage = require("modules/exp_util/storage")
local lib = {}
lib.data = {
output = {}
output = {},
}
Storage.register(lib.data, function(tbl)
lib.data = tbl
lib.data = tbl
end)
---@class Statistics
---@field production ProductionStatistics?
---@field robots RobotStatistics?
---@field other OtherStatistics?
---@field research Research[]?
--- @class Statistics
--- @field production ProductionStatistics?
--- @field robots RobotStatistics?
--- @field other OtherStatistics?
--- @field research Research[]?
Event.on_init(function()
---@type table<string, Statistics>
lib.data.output = {}
for _, force in pairs(game.forces) do
lib.data.output[force.name] = {}
end
--- @type table<string, Statistics>
lib.data.output = {}
for _, force in pairs(game.forces) do
lib.data.output[force.name] = {}
end
end)
---@class OtherStatistics
---@field tick uint
---@field evolution EvolutionStatistics
--- @class OtherStatistics
--- @field tick uint
--- @field evolution EvolutionStatistics
---@class EvolutionStatistics
---@field evolution_factor double
---@field evolution_factor_by_pollution double
---@field evolution_factor_by_time double
---@field evolution_factor_by_killing_spawners double
--- @class EvolutionStatistics
--- @field evolution_factor double
--- @field evolution_factor_by_pollution double
--- @field evolution_factor_by_time double
--- @field evolution_factor_by_killing_spawners double
lib.collect_other = function()
for _, force in pairs(game.forces) do
---@type OtherStatistics
local other = lib.data.output[force.name].other or {}
for _, force in pairs(game.forces) do
--- @type OtherStatistics
local other = lib.data.output[force.name].other or {}
other.evolution = {
evolution_factor = force.evolution_factor,
evolution_factor_by_pollution = force.evolution_factor_by_pollution,
evolution_factor_by_time = force.evolution_factor_by_time,
evolution_factor_by_killing_spawners = force.evolution_factor_by_killing_spawners
}
for k, v in pairs(other) do
lib.data.output[force.name].other[k] = v
end
end
other.evolution = {
evolution_factor = force.evolution_factor,
evolution_factor_by_pollution = force.evolution_factor_by_pollution,
evolution_factor_by_time = force.evolution_factor_by_time,
evolution_factor_by_killing_spawners = force.evolution_factor_by_killing_spawners,
}
for k, v in pairs(other) do
lib.data.output[force.name].other[k] = v
end
end
end
Event.add(defines.events.on_force_created, function(evt)
lib.data.output[evt.force.name] = {}
lib.data.output[evt.force.name] = {}
end)
Event.add(defines.events.on_forces_merged, function(evt)
lib.data.output[evt.source_name] = nil
lib.data.output[evt.source_name] = nil
end)
return lib

View File

@@ -5,23 +5,23 @@ local general = require("modules.exp_legacy.modules.graftorio.general")
local forcestats = nil
if config.modules.forcestats then
forcestats = require("modules.exp_legacy.modules.graftorio.forcestats")
forcestats = require("modules.exp_legacy.modules.graftorio.forcestats")
end
Commands.new_command("collectdata", "Collect data for RCON usage")
:add_param("location", true)
:register(function()
-- this must be first as it overwrites the stats
-- also makes the .other table for all forces
statics.collect_statics()
if config.modules.other then
general.collect_other()
end
if config.modules.forcestats then
---@cast forcestats -nil
forcestats.collect_production()
forcestats.collect_loginet()
end
rcon.print(game.table_to_json(general.data.output))
return Commands.success()
end)
:add_param("location", true)
:register(function()
-- this must be first as it overwrites the stats
-- also makes the .other table for all forces
statics.collect_statics()
if config.modules.other then
general.collect_other()
end
if config.modules.forcestats then
--- @cast forcestats -nil
forcestats.collect_production()
forcestats.collect_loginet()
end
rcon.print(game.table_to_json(general.data.output))
return Commands.success()
end)

View File

@@ -2,34 +2,35 @@ local general = require("modules.exp_legacy.modules.graftorio.general")
local lib = {}
---@class StaticStatistics
---@field tick uint
---@field online_players string[]
---@field mods table<string, string>
---@field seed table<string, uint>
--- @class StaticStatistics
--- @field tick uint
--- @field online_players string[]
--- @field mods table<string, string>
--- @field seed table<string, uint>
lib.collect_statics = function()
local stats = {}
stats.tick = game.tick
local stats = {}
stats.tick = game.tick
stats.online_players = {}
for _, player in pairs(game.connected_players) do
table.insert(stats.online_players, player.name)
end
stats.online_players = {}
for _, player in pairs(game.connected_players) do
table.insert(stats.online_players, player.name)
end
stats.mods = {}
for name, version in pairs(game.active_mods) do
stats.mods[name] = version
end
stats.mods = {}
for name, version in pairs(game.active_mods) do
stats.mods[name] = version
end
-- reason behind this is that the map gen settings can be changed during runtime so just get them fresh
stats.seed = {}
for _, surface in pairs(game.surfaces) do
stats.seed[surface.name] = surface.map_gen_settings.seed
end
for _, force in pairs(game.forces) do
general.data.output[force.name].other = stats
end
-- reason behind this is that the map gen settings can be changed during runtime so just get them fresh
stats.seed = {}
for _, surface in pairs(game.surfaces) do
stats.seed[surface.name] = surface.map_gen_settings.seed
end
for _, force in pairs(game.forces) do
general.data.output[force.name].other = stats
end
end
return lib