Update version to 0.2.2, improve network cache handling, and enhance train state tracking
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"Lua.workspace.userThirdParty": [
|
"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",
|
"Lua.workspace.checkThirdParty": "ApplyInMemory",
|
||||||
"factorio.versions": [
|
"factorio.versions": [
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ script.on_configuration_changed(function()
|
|||||||
storage.playerDeathCause = storage.playerDeathCause or {}
|
storage.playerDeathCause = storage.playerDeathCause or {}
|
||||||
storage.constructedEntites = storage.constructedEntites or {}
|
storage.constructedEntites = storage.constructedEntites or {}
|
||||||
storage.deconstructedEntities = storage.deconstructedEntities or{}
|
storage.deconstructedEntities = storage.deconstructedEntities or{}
|
||||||
storage.networkCache =storage.networkCache or {}
|
storage.networkCache = storage.networkCache or {}
|
||||||
storage.trains = storage.trains or {}
|
storage.trains = storage.trains or {}
|
||||||
---@type table<uint, trainStat>
|
---@type table<uint, trainStat>
|
||||||
storage.trainStats = storage.trainStats or {}
|
storage.trainStats = storage.trainStats or {}
|
||||||
@@ -230,10 +230,11 @@ function SendAll(event)
|
|||||||
isInitialized = true
|
isInitialized = true
|
||||||
|
|
||||||
if scannedGrids == false then
|
if scannedGrids == false then
|
||||||
|
storage.networkCache = nil
|
||||||
ScanNetworks()
|
ScanNetworks()
|
||||||
scannedGrids = true
|
scannedGrids = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if scannedLabs == false then
|
if scannedLabs == false then
|
||||||
ScanLabs()
|
ScanLabs()
|
||||||
scannedLabs = true
|
scannedLabs = true
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "factorio-metrics-exporter",
|
"name": "factorio-metrics-exporter",
|
||||||
"version": "0.2.1",
|
"version": "0.2.2",
|
||||||
"title": "Prometheus Metrics Exporter",
|
"title": "Prometheus Metrics Exporter",
|
||||||
"author": "Jan Grießhaber",
|
"author": "Jan Grießhaber",
|
||||||
"contact": "jan@griesshaber.systems",
|
"contact": "jan@griesshaber.systems",
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ function AddPowerPole(event)
|
|||||||
if e then
|
if e then
|
||||||
storage.representativePoles[e.unit_number] = e
|
storage.representativePoles[e.unit_number] = e
|
||||||
-- Update cache with new network
|
-- Update cache with new network
|
||||||
if e.electric_network_id then
|
storage.networkCache = nil
|
||||||
storage.networkCache[e.electric_network_id] = e
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -50,7 +48,7 @@ function ScanNetworks()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function SendPowerStats()
|
function SendPowerStats()
|
||||||
if options.enablePower then
|
if options.enablePower then
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ function UpdateLabs(event)
|
|||||||
if lab and lab.valid then
|
if lab and lab.valid then
|
||||||
storage.labs[lab.unit_number] = lab
|
storage.labs[lab.unit_number] = lab
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function RemoveLab(event)
|
function RemoveLab(event)
|
||||||
@@ -43,7 +42,7 @@ function GetEstimatedResearchTime()
|
|||||||
|
|
||||||
local totalSpeed = storage.totalResearchSpeed
|
local totalSpeed = storage.totalResearchSpeed
|
||||||
|
|
||||||
local remainingPercentage = 1-playerForce.research_progress
|
local remainingPercentage = 1-math.min(playerForce.research_progress,1)
|
||||||
local remainingUnits = remainingPercentage*researchTotalCost
|
local remainingUnits = remainingPercentage*researchTotalCost
|
||||||
local estimatedSeconds = remainingUnits/totalSpeed
|
local estimatedSeconds = remainingUnits/totalSpeed
|
||||||
|
|
||||||
@@ -51,10 +50,11 @@ function GetEstimatedResearchTime()
|
|||||||
local returnTime = "---research-time---\n"..estimatedSeconds.."\n"
|
local returnTime = "---research-time---\n"..estimatedSeconds.."\n"
|
||||||
local returnNameID = "---research-info---\n"..researchName.."\n"
|
local returnNameID = "---research-info---\n"..researchName.."\n"
|
||||||
local returnProgress = "---research-progress---\n"..playerForce.research_progress.."\n"
|
local returnProgress = "---research-progress---\n"..playerForce.research_progress.."\n"
|
||||||
|
local returnCost = "---research-cost---\n"..researchTotalCost.."\n"
|
||||||
|
|
||||||
log("Reseach remaining "..returnTime)
|
log("Reseach remaining "..returnTime)
|
||||||
|
|
||||||
return returnSpeed..returnTime..returnNameID..returnProgress
|
return returnSpeed..returnTime..returnNameID..returnProgress..returnCost
|
||||||
end
|
end
|
||||||
|
|
||||||
function UpdateLabInfos()
|
function UpdateLabInfos()
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ function GetTrainStates()
|
|||||||
|
|
||||||
elseif train.state == defines.train_state.on_the_path
|
elseif train.state == defines.train_state.on_the_path
|
||||||
or train.state == defines.train_state.arrive_signal
|
or train.state == defines.train_state.arrive_signal
|
||||||
|
or train.state == defines.train_state.arrive_station
|
||||||
or train.state == defines.train_state.wait_signal
|
or train.state == defines.train_state.wait_signal
|
||||||
then trainsDriving = trainsDriving + 1
|
then trainsDriving = trainsDriving + 1
|
||||||
|
|
||||||
@@ -167,6 +168,7 @@ function onTrainStateChange(event)
|
|||||||
if event.train.state == defines.train_state.wait_station then
|
if event.train.state == defines.train_state.wait_station then
|
||||||
|
|
||||||
if train.station.unit_number == stat.lastStationUnitNumber then return end
|
if train.station.unit_number == stat.lastStationUnitNumber then return end
|
||||||
|
|
||||||
stat.lastStationUnitNumber = stat.currentStationUnitNumber
|
stat.lastStationUnitNumber = stat.currentStationUnitNumber
|
||||||
stat.lastInventory = stat.currentInventory
|
stat.lastInventory = stat.currentInventory
|
||||||
stat.lastArrivalTime = stat.currentArrivalTime
|
stat.lastArrivalTime = stat.currentArrivalTime
|
||||||
@@ -176,7 +178,8 @@ function onTrainStateChange(event)
|
|||||||
stat.currentArrivalTime = game.tick
|
stat.currentArrivalTime = game.tick
|
||||||
|
|
||||||
if stat.lastStationUnitNumber
|
if stat.lastStationUnitNumber
|
||||||
and stat.currentStationUnitNumber then
|
and stat.currentStationUnitNumber
|
||||||
|
and (stat.lastStationUnitNumber ~= stat.currentStationUnitNumber) then
|
||||||
local tripIdentifier = tostring(stat.lastStationUnitNumber) .. tostring(stat.currentStationUnitNumber)
|
local tripIdentifier = tostring(stat.lastStationUnitNumber) .. tostring(stat.currentStationUnitNumber)
|
||||||
stat.trips[tripIdentifier] = {
|
stat.trips[tripIdentifier] = {
|
||||||
startStation = game.get_entity_by_unit_number(stat.lastStationUnitNumber),
|
startStation = game.get_entity_by_unit_number(stat.lastStationUnitNumber),
|
||||||
|
|||||||
Reference in New Issue
Block a user