Update version to 0.2.5, add train trip statistics option feature, and improve train state handling and null safety
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\\3b31e6f4ee2e6f815dd0701fecf3b460\\justarandomgeek.factoriomod-debug\\sumneko-3rd"
|
"c:\\Users\\jangr\\AppData\\Roaming\\Code\\User\\workspaceStorage\\6d87f11bcadf77c8bf3a32c6545bb9a5\\justarandomgeek.factoriomod-debug\\sumneko-3rd"
|
||||||
],
|
],
|
||||||
"Lua.workspace.checkThirdParty": "ApplyInMemory",
|
"Lua.workspace.checkThirdParty": "ApplyInMemory",
|
||||||
"factorio.versions": [
|
"factorio.versions": [
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ options = {
|
|||||||
enableRobots = false,
|
enableRobots = false,
|
||||||
enableResearch = false,
|
enableResearch = false,
|
||||||
enablePower = false,
|
enablePower = false,
|
||||||
enableTrains = false
|
enableTrains = false,
|
||||||
|
enableTrainTrips = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@ script.on_init(function ()
|
|||||||
options.enableResearch = settings.global["factorio-metrics-exporter-export_research_stats"].value
|
options.enableResearch = settings.global["factorio-metrics-exporter-export_research_stats"].value
|
||||||
options.enableRobots = settings.global["factorio-metrics-exporter-export_logistic_stats"].value
|
options.enableRobots = settings.global["factorio-metrics-exporter-export_logistic_stats"].value
|
||||||
options.enableTrains = settings.global["factorio-metrics-exporter-export_train_stats"].value
|
options.enableTrains = settings.global["factorio-metrics-exporter-export_train_stats"].value
|
||||||
|
options.enableTrainTrips = settings.global["factorio-metrics-exporter-export_train_trips"].value
|
||||||
autotrainGroupName = settings.global["factorio-metrics-exporter-autotrain_group_name"].value
|
autotrainGroupName = settings.global["factorio-metrics-exporter-autotrain_group_name"].value
|
||||||
autotrainDepotName = settings.global["factorio-metrics-exporter-autotrain_depot_name"].value
|
autotrainDepotName = settings.global["factorio-metrics-exporter-autotrain_depot_name"].value
|
||||||
|
|
||||||
@@ -84,6 +86,7 @@ script.on_load(function ()
|
|||||||
options.enableResearch = settings.global["factorio-metrics-exporter-export_research_stats"].value
|
options.enableResearch = settings.global["factorio-metrics-exporter-export_research_stats"].value
|
||||||
options.enableRobots = settings.global["factorio-metrics-exporter-export_logistic_stats"].value
|
options.enableRobots = settings.global["factorio-metrics-exporter-export_logistic_stats"].value
|
||||||
options.enableTrains = settings.global["factorio-metrics-exporter-export_train_stats"].value
|
options.enableTrains = settings.global["factorio-metrics-exporter-export_train_stats"].value
|
||||||
|
options.enableTrainTrips = settings.global["factorio-metrics-exporter-export_train_trips"].value
|
||||||
autotrainGroupName = settings.global["factorio-metrics-exporter-autotrain_group_name"].value
|
autotrainGroupName = settings.global["factorio-metrics-exporter-autotrain_group_name"].value
|
||||||
autotrainDepotName = settings.global["factorio-metrics-exporter-autotrain_depot_name"].value
|
autotrainDepotName = settings.global["factorio-metrics-exporter-autotrain_depot_name"].value
|
||||||
end)
|
end)
|
||||||
@@ -163,6 +166,9 @@ script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
|
|||||||
if event.setting == "factorio-metrics-exporter-autotrain_group_name" then
|
if event.setting == "factorio-metrics-exporter-autotrain_group_name" then
|
||||||
autotrainGroupName = settings.global["factorio-metrics-exporter-autotrain_group_name"].value
|
autotrainGroupName = settings.global["factorio-metrics-exporter-autotrain_group_name"].value
|
||||||
end
|
end
|
||||||
|
if event.setting == "factorio-metrics-exporter-export_train_trips" then
|
||||||
|
options.enableTrainTrips = settings.global["factorio-metrics-exporter-export_train_trips"].value
|
||||||
|
end
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "factorio-metrics-exporter",
|
"name": "factorio-metrics-exporter",
|
||||||
"version": "0.2.3",
|
"version": "0.2.6",
|
||||||
"title": "Prometheus Metrics Exporter",
|
"title": "Prometheus Metrics Exporter",
|
||||||
"author": "Jan Grießhaber",
|
"author": "Jan Grießhaber",
|
||||||
"contact": "jan@griesshaber.systems",
|
"contact": "jan@griesshaber.systems",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ factorio-metrics-exporter-export_train_stats=Enable Train
|
|||||||
factorio-metrics-exporter-enable_denkmalschutz=Enable Denkmalschutz
|
factorio-metrics-exporter-enable_denkmalschutz=Enable Denkmalschutz
|
||||||
factorio-metrics-exporter-autotrain_group_name=AutoTrain metrics group name
|
factorio-metrics-exporter-autotrain_group_name=AutoTrain metrics group name
|
||||||
factorio-metrics-exporter-autotrain_depot_name=AutoTrain metrics depot name
|
factorio-metrics-exporter-autotrain_depot_name=AutoTrain metrics depot name
|
||||||
|
factorio-metrics-exporter-export_train_trips=Enable Train trip statistics
|
||||||
[mod-setting-description]
|
[mod-setting-description]
|
||||||
factorio-metrics-exporter-export_production_stats=Enables sending of the production statistics per surface. Not very expensive
|
factorio-metrics-exporter-export_production_stats=Enables sending of the production statistics per surface. Not very expensive
|
||||||
factorio-metrics-exporter-enable=Enable sending of the UDP packets
|
factorio-metrics-exporter-enable=Enable sending of the UDP packets
|
||||||
@@ -29,4 +30,5 @@ factorio-metrics-exporter-export_player_stats=Enable sending of player statistic
|
|||||||
factorio-metrics-exporter-export_train_stats=Enable sending of train statistics. Inexpensive unless very many trains are in use
|
factorio-metrics-exporter-export_train_stats=Enable sending of train statistics. Inexpensive unless very many trains are in use
|
||||||
factorio-metrics-exporter-enable_denkmalschutz=Enable the fun option of Denkmalschutz. In multiplayer, the player who deconstructs the starter spaceship entity will get banned
|
factorio-metrics-exporter-enable_denkmalschutz=Enable the fun option of Denkmalschutz. In multiplayer, the player who deconstructs the starter spaceship entity will get banned
|
||||||
factorio-metrics-exporter-autotrain_group_name=Set the name of the traingroup you want to use for the autotrain metric
|
factorio-metrics-exporter-autotrain_group_name=Set the name of the traingroup you want to use for the autotrain metric
|
||||||
factorio-metrics-exporter-autotrain_depot_name=Set the name of the depot you want to use for the autotrain metric
|
factorio-metrics-exporter-autotrain_depot_name=Set the name of the depot you want to use for the autotrain metric
|
||||||
|
factorio-metrics-exporter-export_train_trips=Enable sending of train trup statistics.
|
||||||
@@ -46,7 +46,7 @@ function GetEstimatedResearchTime()
|
|||||||
local remainingUnits = remainingPercentage*researchTotalCost
|
local remainingUnits = remainingPercentage*researchTotalCost
|
||||||
local estimatedSeconds = remainingUnits/totalSpeed
|
local estimatedSeconds = remainingUnits/totalSpeed
|
||||||
|
|
||||||
log("Remaining Perc: %d\nCost: %d\nSpeed: %d\nRem Units: %d\n")
|
log(("Remaining Perc: %d\nCost: %d\nSpeed: %d\nRem Units: %d\n"):format(remainingPercentage,researchTotalCost,totalSpeed,remainingUnits))
|
||||||
|
|
||||||
local returnSpeed = "---research-speed---\n"..totalSpeed.."\n"
|
local returnSpeed = "---research-speed---\n"..totalSpeed.."\n"
|
||||||
local returnTime = "---research-time---\n"..estimatedSeconds.."\n"
|
local returnTime = "---research-time---\n"..estimatedSeconds.."\n"
|
||||||
|
|||||||
@@ -105,5 +105,12 @@ data:extend({
|
|||||||
setting_type = "runtime-global",
|
setting_type = "runtime-global",
|
||||||
default_value = "[virtual-signal=signal-pink][item=locomotive]",
|
default_value = "[virtual-signal=signal-pink][item=locomotive]",
|
||||||
order = "zb"
|
order = "zb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "bool-setting",
|
||||||
|
name = "factorio-metrics-exporter-export_train_trips",
|
||||||
|
setting_type = "runtime-global",
|
||||||
|
default_value = false,
|
||||||
|
order = "zz"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -167,6 +167,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 not train.station then return end
|
||||||
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
|
||||||
@@ -198,12 +199,28 @@ function onTrainStateChange(event)
|
|||||||
end
|
end
|
||||||
--log("inEvent")
|
--log("inEvent")
|
||||||
end
|
end
|
||||||
|
--Checks if trip is still valid by checking of st
|
||||||
|
function isTripValid(trip,tripID,trainID)
|
||||||
|
if trip.startStation == nil
|
||||||
|
or trip.endStation==nil
|
||||||
|
or trip.startStation.valid == false
|
||||||
|
or trip.endStation.valid == false then
|
||||||
|
--One station is nil so we delete this trip
|
||||||
|
log("Deleting trip"..tripID)
|
||||||
|
storage.trainStats[trainID].trips[tripID] = nil
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
--Stations are valid, so we true
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function GetTrainTripStats()
|
function GetTrainTripStats()
|
||||||
local tripParts = {}
|
local tripParts = {}
|
||||||
|
local tripCount = 0
|
||||||
tripParts[#tripParts+1] = "---train-trips---\n"
|
tripParts[#tripParts+1] = "---train-trips---\n"
|
||||||
for trainID,stats in pairs(storage.trainStats) do
|
for trainID,stats in pairs(storage.trainStats) do
|
||||||
for _,trip in pairs(stats.trips or {}) do
|
for tripIndex,trip in pairs(stats.trips or {}) do
|
||||||
|
if isTripValid(trip,tripIndex,trainID) then
|
||||||
tripParts[#tripParts+1] =
|
tripParts[#tripParts+1] =
|
||||||
("%d:%s:%s:%s:%d"):format(
|
("%d:%s:%s:%s:%d"):format(
|
||||||
trainID,
|
trainID,
|
||||||
@@ -211,9 +228,17 @@ function GetTrainTripStats()
|
|||||||
trip.startStation.backer_name,
|
trip.startStation.backer_name,
|
||||||
trip.endStation.backer_name,
|
trip.endStation.backer_name,
|
||||||
trip.timeTaken)
|
trip.timeTaken)
|
||||||
|
tripCount = tripCount + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #tripParts > 400 then
|
||||||
|
log("Sending at "..tripCount.." trips")
|
||||||
|
helpers.send_udp(udpAddress,table.concat(tripParts,"\n"),serverIndex)
|
||||||
|
tripParts = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return table.concat(tripParts,"\n")
|
log("Counted "..tripCount.." trips")
|
||||||
|
--return table.concat(tripParts,"\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
function GetTrainStatistics()
|
function GetTrainStatistics()
|
||||||
@@ -255,10 +280,10 @@ function SendTrainStats()
|
|||||||
returnParts[#returnParts+1] = GetTrainTotalKills()
|
returnParts[#returnParts+1] = GetTrainTotalKills()
|
||||||
returnParts[#returnParts+1] = GetTrainStates()
|
returnParts[#returnParts+1] = GetTrainStates()
|
||||||
returnParts[#returnParts+1] = GetTrainStatistics()
|
returnParts[#returnParts+1] = GetTrainStatistics()
|
||||||
helpers.send_udp(udpAddress,table.concat(returnParts,"\n"),serverIndex)
|
|
||||||
returnParts = {}
|
|
||||||
returnParts[#returnParts+1] = GetTrainsInDepot()
|
returnParts[#returnParts+1] = GetTrainsInDepot()
|
||||||
returnParts[#returnParts+1] = GetTrainTripStats()
|
if options.enableTrainTrips then
|
||||||
|
GetTrainTripStats()
|
||||||
|
end
|
||||||
log("Sending Train statistics")
|
log("Sending Train statistics")
|
||||||
helpers.send_udp(udpAddress,table.concat(returnParts,"\n"),serverIndex)
|
helpers.send_udp(udpAddress,table.concat(returnParts,"\n"),serverIndex)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user