Private
Public Access
1
0

Update version to 0.2.2, improve network cache handling, and enhance train state tracking

This commit is contained in:
Jan Grießhaber
2026-01-04 10:37:10 +01:00
parent f40e219a2e
commit a44d27c386
6 changed files with 14 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
{
"Lua.workspace.userThirdParty": [
"c:\\Users\\jangr\\AppData\\Roaming\\Code\\User\\workspaceStorage\\f0146bacf23a7548830b73867851c66a\\justarandomgeek.factoriomod-debug\\sumneko-3rd"
"c:\\Users\\jangr\\AppData\\Roaming\\Code\\User\\workspaceStorage\\3b31e6f4ee2e6f815dd0701fecf3b460\\justarandomgeek.factoriomod-debug\\sumneko-3rd"
],
"Lua.workspace.checkThirdParty": "ApplyInMemory",
"factorio.versions": [

View File

@@ -103,7 +103,7 @@ script.on_configuration_changed(function()
storage.playerDeathCause = storage.playerDeathCause or {}
storage.constructedEntites = storage.constructedEntites or {}
storage.deconstructedEntities = storage.deconstructedEntities or{}
storage.networkCache =storage.networkCache or {}
storage.networkCache = storage.networkCache or {}
storage.trains = storage.trains or {}
---@type table<uint, trainStat>
storage.trainStats = storage.trainStats or {}
@@ -230,10 +230,11 @@ function SendAll(event)
isInitialized = true
if scannedGrids == false then
storage.networkCache = nil
ScanNetworks()
scannedGrids = true
end
if scannedLabs == false then
ScanLabs()
scannedLabs = true

View File

@@ -1,6 +1,6 @@
{
"name": "factorio-metrics-exporter",
"version": "0.2.1",
"version": "0.2.2",
"title": "Prometheus Metrics Exporter",
"author": "Jan Grießhaber",
"contact": "jan@griesshaber.systems",

View File

@@ -3,9 +3,7 @@ function AddPowerPole(event)
if e then
storage.representativePoles[e.unit_number] = e
-- Update cache with new network
if e.electric_network_id then
storage.networkCache[e.electric_network_id] = e
end
storage.networkCache = nil
end
end
@@ -50,7 +48,7 @@ function ScanNetworks()
end
end
end
end
end
function SendPowerStats()
if options.enablePower then

View File

@@ -19,7 +19,6 @@ function UpdateLabs(event)
if lab and lab.valid then
storage.labs[lab.unit_number] = lab
end
end
function RemoveLab(event)
@@ -43,7 +42,7 @@ function GetEstimatedResearchTime()
local totalSpeed = storage.totalResearchSpeed
local remainingPercentage = 1-playerForce.research_progress
local remainingPercentage = 1-math.min(playerForce.research_progress,1)
local remainingUnits = remainingPercentage*researchTotalCost
local estimatedSeconds = remainingUnits/totalSpeed
@@ -51,10 +50,11 @@ function GetEstimatedResearchTime()
local returnTime = "---research-time---\n"..estimatedSeconds.."\n"
local returnNameID = "---research-info---\n"..researchName.."\n"
local returnProgress = "---research-progress---\n"..playerForce.research_progress.."\n"
local returnCost = "---research-cost---\n"..researchTotalCost.."\n"
log("Reseach remaining "..returnTime)
return returnSpeed..returnTime..returnNameID..returnProgress
return returnSpeed..returnTime..returnNameID..returnProgress..returnCost
end
function UpdateLabInfos()

View File

@@ -64,6 +64,7 @@ function GetTrainStates()
elseif train.state == defines.train_state.on_the_path
or train.state == defines.train_state.arrive_signal
or train.state == defines.train_state.arrive_station
or train.state == defines.train_state.wait_signal
then trainsDriving = trainsDriving + 1
@@ -167,6 +168,7 @@ function onTrainStateChange(event)
if event.train.state == defines.train_state.wait_station then
if train.station.unit_number == stat.lastStationUnitNumber then return end
stat.lastStationUnitNumber = stat.currentStationUnitNumber
stat.lastInventory = stat.currentInventory
stat.lastArrivalTime = stat.currentArrivalTime
@@ -176,7 +178,8 @@ function onTrainStateChange(event)
stat.currentArrivalTime = game.tick
if stat.lastStationUnitNumber
and stat.currentStationUnitNumber then
and stat.currentStationUnitNumber
and (stat.lastStationUnitNumber ~= stat.currentStationUnitNumber) then
local tripIdentifier = tostring(stat.lastStationUnitNumber) .. tostring(stat.currentStationUnitNumber)
stat.trips[tripIdentifier] = {
startStation = game.get_entity_by_unit_number(stat.lastStationUnitNumber),