Added Reserach Stats, still have to add power and research avg
This commit is contained in:
10
control.lua
10
control.lua
@@ -4,7 +4,6 @@ require("pollution-stats")
|
|||||||
require("research-stats")
|
require("research-stats")
|
||||||
require("power-stats")
|
require("power-stats")
|
||||||
require("logistic-network-stats")
|
require("logistic-network-stats")
|
||||||
require("storage")
|
|
||||||
|
|
||||||
tickInterval = tonumber(settings.global["factorio-prometheus-exporter-tick-interval"].value) or 300
|
tickInterval = tonumber(settings.global["factorio-prometheus-exporter-tick-interval"].value) or 300
|
||||||
udpAddress = tonumber(settings.startup["factorio-prometheus-exporter-udp-address"].value) or 52555
|
udpAddress = tonumber(settings.startup["factorio-prometheus-exporter-udp-address"].value) or 52555
|
||||||
@@ -16,6 +15,9 @@ script.on_init(function ()
|
|||||||
storage.electricGrids = {}
|
storage.electricGrids = {}
|
||||||
storage.researchedTechnologies = {}
|
storage.researchedTechnologies = {}
|
||||||
storage.playerDeathCount = {}
|
storage.playerDeathCount = {}
|
||||||
|
storage.totalLabCount = 0
|
||||||
|
storage.totalResearchSpeed = 0
|
||||||
|
storage.totalReseachProductivity = 0
|
||||||
end)
|
end)
|
||||||
|
|
||||||
script.on_load(function ()
|
script.on_load(function ()
|
||||||
@@ -26,6 +28,7 @@ end)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Register the handler for the player movement event
|
-- Register the handler for the player movement event
|
||||||
script.on_event(defines.events.on_player_died, function(event)
|
script.on_event(defines.events.on_player_died, function(event)
|
||||||
local player = game.get_player(event.player_index)
|
local player = game.get_player(event.player_index)
|
||||||
@@ -69,14 +72,15 @@ function SendAll(event)
|
|||||||
isInitialized = true
|
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 == 1 then SendProductionStats() end
|
||||||
if sendIndex == 2 then SendPollutionStats() end
|
if sendIndex == 2 then SendPollutionStats() end
|
||||||
if sendIndex == 3 then SendKillStats() end
|
if sendIndex == 3 then SendKillStats() end
|
||||||
if sendIndex == 4 then SendFluidProductionStats() end
|
if sendIndex == 4 then SendFluidProductionStats() end
|
||||||
if sendIndex == 5 then SendBuildStats() end
|
if sendIndex == 5 then SendBuildStats() end
|
||||||
|
if sendIndex == 6 then SendResearchStats() end
|
||||||
|
|
||||||
if(event.tick % tickInterval*2 == 0) then SendGameStats(event) end
|
if(event.tick % tickInterval*2 == 0) then SendGameStats(event) end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
storage.playerDeathCount = {}
|
|
||||||
storage.researchedTech = {}
|
|
||||||
Reference in New Issue
Block a user