From 9256d2d317dd4988ef94100003fd797005d5a9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grie=C3=9Fhaber?= Date: Thu, 1 Jan 2026 16:39:34 +0100 Subject: [PATCH] Added Reserach Stats, still have to add power and research avg --- control.lua | 10 +++++--- research-stats.lua | 63 ++++++++++++++++++++++++++++++++++++++++++++++ storage.lua | 2 -- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/control.lua b/control.lua index 0e591b6..ce43072 100644 --- a/control.lua +++ b/control.lua @@ -4,7 +4,6 @@ require("pollution-stats") require("research-stats") require("power-stats") require("logistic-network-stats") -require("storage") tickInterval = tonumber(settings.global["factorio-prometheus-exporter-tick-interval"].value) or 300 udpAddress = tonumber(settings.startup["factorio-prometheus-exporter-udp-address"].value) or 52555 @@ -16,6 +15,9 @@ script.on_init(function () storage.electricGrids = {} storage.researchedTechnologies = {} storage.playerDeathCount = {} + storage.totalLabCount = 0 + storage.totalResearchSpeed = 0 + storage.totalReseachProductivity = 0 end) script.on_load(function () @@ -26,6 +28,7 @@ end) + -- Register the handler for the player movement event script.on_event(defines.events.on_player_died, function(event) local player = game.get_player(event.player_index) @@ -69,14 +72,15 @@ function SendAll(event) isInitialized = true - if (event.tick % math.floor(tickInterval/4) ~= 0) then return end + if (event.tick % math.floor(tickInterval/6) ~= 0) then return end - sendIndex = (sendIndex % 5) + 1 + sendIndex = (sendIndex % 6) + 1 if sendIndex == 1 then SendProductionStats() end if sendIndex == 2 then SendPollutionStats() end if sendIndex == 3 then SendKillStats() end if sendIndex == 4 then SendFluidProductionStats() end if sendIndex == 5 then SendBuildStats() end + if sendIndex == 6 then SendResearchStats() end if(event.tick % tickInterval*2 == 0) then SendGameStats(event) end end diff --git a/research-stats.lua b/research-stats.lua index e69de29..f21c0b9 100644 --- a/research-stats.lua +++ b/research-stats.lua @@ -0,0 +1,63 @@ +storage.totalLabCount = 0 +local labBaseSpeed = 1 +local biolabBaseSpeed = 2 + + +function GetEstimatedResearchTime() + -- Base time in seconds for research + local playerForce = game.forces["player"] + local currentResearch = playerForce.current_research + if not currentResearch then + return + end + local researchName = currentResearch.name.."-"..currentResearch.level + local researchTotalCost = currentResearch.research_unit_count * (currentResearch.research_unit_energy/60) + + local totalSpeed = storage.totalResearchSpeed + + local remainingPercentage = 1-playerForce.research_progress + local remainingUnits = remainingPercentage*researchTotalCost + local estimatedSeconds = remainingUnits/totalSpeed + + local returnSpeed = "---research-speed---\n"..totalSpeed.."\n" + local returnTime = "---research-time---\n"..estimatedSeconds.."\n" + local returnNameID = "---research-info---\n"..researchName.."\n" + + return returnSpeed..returnTime..returnNameID +end + +function UpdateLabInfos() + local totalLabs = 0 + local totalSpeed = 0 + local totalProd = 0 + for _, surface in pairs(game.surfaces) do + local labs = surface.find_entities_filtered{type="lab"} + totalLabs = totalLabs + #labs + for _, lab in pairs(labs) do + if lab.valid then + if lab.status == defines.entity_status.working then + local labBase + if lab.name == "biolab" then + labBase = biolabBaseSpeed + else + labBase = labBaseSpeed + end + local labSpeed = (labBase + (labBase * game.forces["player"].laboratory_speed_modifier)) * lab.effects.speed + totalSpeed = totalSpeed + (labSpeed* (1+lab.effects.productivity)) + --local labSpeed = labBaseSpeed * lab.effects.speed + end + end + end + end + storage.totalLabCount = totalLabs + storage.totalResearchSpeed = totalSpeed + storage.totalReseachProductivity = totalProd +end + +function SendResearchStats() + UpdateLabInfos() + local researchTimeInfo = GetEstimatedResearchTime() + if researchTimeInfo then + helpers.send_udp(udpAddress, researchTimeInfo, serverIndex) + end +end \ No newline at end of file diff --git a/storage.lua b/storage.lua index 7d091e6..e69de29 100644 --- a/storage.lua +++ b/storage.lua @@ -1,2 +0,0 @@ -storage.playerDeathCount = {} -storage.researchedTech = {} \ No newline at end of file