Update version to 0.1.20 and enhance train name retrieval in statistics
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "factorio-metrics-exporter",
|
||||
"version": "0.1.19",
|
||||
"version": "0.1.20",
|
||||
"title": "Prometheus Metrics Exporter",
|
||||
"author": "Jan Grießhaber",
|
||||
"contact": "jan@griesshaber.systems",
|
||||
|
||||
@@ -5,13 +5,25 @@ function ScanTrains()
|
||||
end
|
||||
end
|
||||
|
||||
---comment Get the first locomotive in the front, if non, in the back, if none empty string
|
||||
---@param train LuaTrain
|
||||
function GetTrainName(train)
|
||||
if train.locomotives.front_movers[1] then
|
||||
return train.locomotives.front_movers[1].backer_name
|
||||
else if train.locomotives.back_movers[1] then
|
||||
return train.locomotives.back_movers[1].backer_name
|
||||
end
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
function GetTrainPlayerKills()
|
||||
local trainKills = {}
|
||||
trainKills[#trainKills+1] = "---train-player-kills---"
|
||||
---@type LuaTrain
|
||||
for _, train in pairs(storage.trains ) do
|
||||
for killedPlayerID,killedPlayerCount in pairs(train.killed_players) do
|
||||
trainKills[#trainKills+1] = ("%d%s%s%d"):format(train.id,killedPlayerID,game.players[killedPlayerID].name,killedPlayerCount)
|
||||
trainKills[#trainKills+1] = ("%s:%s:%s:%s:%d"):format(train.id,GetTrainName(train),killedPlayerID,game.players[killedPlayerID].name,killedPlayerCount)
|
||||
end
|
||||
end
|
||||
return table.concat(trainKills,"\n")
|
||||
@@ -23,7 +35,7 @@ function GetTrainTotalKills()
|
||||
trainKills[#trainKills+1] = "---train-total-kills---"
|
||||
---@type LuaTrain
|
||||
for _, train in pairs(storage.trains) do
|
||||
trainKills[#trainKills+1] = ("%d:%d"):format(train.id,train.kill_count)
|
||||
trainKills[#trainKills+1] = ("%s:%s:%d"):format(train.id,GetTrainName(train),train.kill_count)
|
||||
end
|
||||
return table.concat(trainKills,"\n")
|
||||
end
|
||||
@@ -35,13 +47,13 @@ function GetTrainStates()
|
||||
local trainsManual = 0
|
||||
for _, train in pairs(storage.trains) do
|
||||
if train.state == defines.train_state.wait_station
|
||||
or train.state ==defines.train_state.destination_full
|
||||
or train.state == defines.train_state.destination_full
|
||||
or train.state == defines.train_state.no_schedule
|
||||
then trainsWaiting = trainsWaiting + 1 end
|
||||
|
||||
if train.state == defines.train_state.on_the_path
|
||||
or train.state ==defines.train_state.arrive_signal
|
||||
or train.state ==defines.train_state.wait_signal
|
||||
or train.state == defines.train_state.arrive_signal
|
||||
or train.state == defines.train_state.wait_signal
|
||||
then trainsDriving = trainsDriving + 1 end
|
||||
|
||||
if train.state == defines.train_state.manual_control
|
||||
@@ -140,15 +152,13 @@ function onTrainStateChange(event)
|
||||
|
||||
|
||||
if stat.currentInventory and stat.lastInventory then
|
||||
|
||||
--Get Total Cargo
|
||||
for key, value in pairs(inventoryDiff(stat.lastInventory,stat.currentInventory)) do
|
||||
for key, value in pairs(inventoryDiff(stat.lastInventory,stat.currentInventory)) do
|
||||
stat.totalCargoCount = (stat.totalCargoCount or 0) + value.delta
|
||||
end
|
||||
end
|
||||
|
||||
storage.trainStats[trainID] = stat
|
||||
|
||||
end
|
||||
end
|
||||
--log("inEvent")
|
||||
end
|
||||
@@ -157,7 +167,7 @@ function GetTrainStatistics()
|
||||
local trainParts = {}
|
||||
trainParts[#trainParts+1] = "---train-total-statistics---\n"
|
||||
for trainID, stat in pairs(storage.trainStats) do
|
||||
trainParts[#trainParts+1] = ("%d:%d"):format(trainID,stat.totalCargoCount)
|
||||
trainParts[#trainParts+1] = ("%d:%s:%d"):format(trainID,GetTrainName(storage.trains[trainID]),stat.totalCargoCount)
|
||||
end
|
||||
return table.concat(trainParts,"\n")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user