Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more mekanism input adapters #19

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/telem/lib/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ return {
inductionMatrix = require 'telem.lib.input.mekanism.InductionMatrixInputAdapter',
industrialTurbine = require 'telem.lib.input.mekanism.IndustrialTurbineInputAdapter',
fusionReactor = require 'telem.lib.input.mekanism.FusionReactorInputAdapter',
chemicalTank = require 'telem.lib.input.mekanism.ChemicalTankInputAdapter',
bioGenerator = require 'telem.lib.input.mekanism.BioGeneratorInputAdapter',
dynamicTank = require 'telem.lib.input.mekanism.DynamicTankInputAdapter',
digitalMiner = require 'telem.lib.input.mekanism.DigitalMinerInputAdapter',
gasGenerator = require 'telem.lib.input.mekanism.GasGeneratorInputAdapter',
}
}
}
74 changes: 74 additions & 0 deletions src/telem/lib/input/mekanism/BioGeneratorInputAdapter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
local o = require 'telem.lib.ObjectModel'
local t = require 'telem.lib.util'

local InputAdapter = require 'telem.lib.InputAdapter'
local Metric = require 'telem.lib.Metric'
local MetricCollection = require 'telem.lib.MetricCollection'

local BioGeneratorInputAdapter = o.class(InputAdapter)
BioGeneratorInputAdapter.type = 'BioGeneratorInputAdapter'

function BioGeneratorInputAdapter:constructor (peripheralName, categories)
self:super('constructor')

-- TODO this will be a configurable feature later
self.prefix = 'mekbiogen:'

-- TODO make these constants
local allCategories = {
bananasov marked this conversation as resolved.
Show resolved Hide resolved
'basic',
'fuel',
'energy'
}

if not categories then
self.categories = { 'basic' }
elseif categories == '*' then
self.categories = allCategories
else
self.categories = categories
end

-- boot components
self:setBoot(function ()
self.components = {}

self:addComponentByPeripheralID(peripheralName)
end)()
end

function BioGeneratorInputAdapter:read ()
self:boot()

local source, generator = next(self.components)

local metrics = MetricCollection()

local loaded = {}

for _,v in ipairs(self.categories) do
-- skip, already loaded
if loaded[v] then
-- do nothing

-- Literally all we have lmao
elseif v == 'basic' then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to preserve API parity, fuel_* should be changed to bio_fuel_*.

Categories should be expanded:

Basic:

  • energy_filled_percentage
  • bio_fuel_filled_percentage
  • production_rate

Fuel:

  • bio_fuel_capacity
  • bio_fuel
  • bio_fuel_needed

Energy:

  • energy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blehhh my responses are gonna get sillier the more send it: 6814f0d

metrics:insert(Metric{ name = self.prefix .. 'energy_filled_percentage', value = (generator.getEnergyFilledPercentage()), unit = "FE", source = source })
metrics:insert(Metric{ name = self.prefix .. 'bio_fuel_filled_percentage', value = generator.getBioFuelFilledPercentage(), unit = "B", source = source })
metrics:insert(Metric{ name = self.prefix .. 'production_rate', value = mekanismEnergyHelper.joulesToFE(generator.getProductionRate()), unit = "FE/t", source = source })
elseif v == 'energy' then
metrics:insert(Metric{ name = self.prefix .. 'energy', value = mekanismEnergyHelper.joulesToFE(generator.getEnergy()), unit = "FE", source = source })
elseif v == 'fuel' then
metrics:insert(Metric{ name = self.prefix .. 'bio_fuel_capacity', value = (generator.getBioFuelCapacity() / 1000), unit = "B", source = source })
metrics:insert(Metric{ name = self.prefix .. 'bio_fuel', value = (generator.getBioFuel().amount / 1000), unit = "B", source = source }) -- might error might not, no clue!
metrics:insert(Metric{ name = self.prefix .. 'bio_fuel_needed', value = (generator.getBioFuelNeeded() / 1000), unit = 'B/t', source = source })
end

loaded[v] = true
end

return metrics
end

return BioGeneratorInputAdapter

66 changes: 66 additions & 0 deletions src/telem/lib/input/mekanism/ChemicalTankInputAdapter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
local o = require 'telem.lib.ObjectModel'
local t = require 'telem.lib.util'

local InputAdapter = require 'telem.lib.InputAdapter'
local Metric = require 'telem.lib.Metric'
local MetricCollection = require 'telem.lib.MetricCollection'

local ChemicalTankInputAdapter = o.class(InputAdapter)
ChemicalTankInputAdapter.type = 'ChemicalTankInputAdapter'

function ChemicalTankInputAdapter:constructor (peripheralName, categories)
self:super('constructor')

-- TODO this will be a configurable feature later
self.prefix = 'mekchemtank:'

-- TODO make these constants
local allCategories = {
'basic',
}

if not categories then
self.categories = { 'basic' }
elseif categories == '*' then
self.categories = allCategories
else
self.categories = categories
end

-- boot components
self:setBoot(function ()
self.components = {}

self:addComponentByPeripheralID(peripheralName)
end)()
end

function ChemicalTankInputAdapter:read ()
self:boot()

local source, tank = next(self.components)

local metrics = MetricCollection()

local loaded = {}

for _,v in ipairs(self.categories) do
-- skip, already loaded
if loaded[v] then
-- do nothing

-- Literally all we have lmao
elseif v == 'basic' then
metrics:insert(Metric{ name = self.prefix .. 'capacity', value = (tank.getCapacity() / 1000), unit = "B", source = source })
metrics:insert(Metric{ name = self.prefix .. 'stored', value = (tank.getStored().amount / 1000), unit = "B", source = source }) -- might error might not, no clue!
metrics:insert(Metric{ name = self.prefix .. 'filled_percentage', value = tank.getFilledPercentage(), unit = nil, source = source })
end

loaded[v] = true
end

return metrics
end

return ChemicalTankInputAdapter

69 changes: 69 additions & 0 deletions src/telem/lib/input/mekanism/DigitalMinerInputAdapter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
local o = require 'telem.lib.ObjectModel'
local t = require 'telem.lib.util'

local InputAdapter = require 'telem.lib.InputAdapter'
local Metric = require 'telem.lib.Metric'
local MetricCollection = require 'telem.lib.MetricCollection'

local DigitalMinerInputAdapter = o.class(InputAdapter)
DigitalMinerInputAdapter.type = 'DigitalMinerInputAdapter'

function DigitalMinerInputAdapter:constructor (peripheralName, categories)
self:super('constructor')

-- TODO this will be a configurable feature later
self.prefix = 'mekdigitalminer:'

-- TODO make these constants
local allCategories = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend basic and energy; may add advanced and formation in later updates.

'basic',
'energy'
}

if not categories then
self.categories = { 'basic' }
elseif categories == '*' then
self.categories = allCategories
else
self.categories = categories
end

-- boot components
self:setBoot(function ()
self.components = {}

self:addComponentByPeripheralID(peripheralName)
end)()
end

function DigitalMinerInputAdapter:read ()
self:boot()

local source, miner = next(self.components)

local metrics = MetricCollection()

local loaded = {}

for _,v in ipairs(self.categories) do
-- skip, already loaded
if loaded[v] then
-- do nothing

-- TODO: Maybe add `formation`and `advanced` later?
elseif v == 'basic' then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Categories should be expanded:

Basic:

  • energy_filled_percentage
  • energy_usage
  • get_to_mine
  • is_running

Energy:

  • energy

metrics:insert(Metric{ name = self.prefix .. 'energy_filled_percentage', value = (miner.getEnergyFilledPercentage()), unit = nil, source = source })
metrics:insert(Metric{ name = self.prefix .. 'energy_usage', value = mekanismEnergyHelper.joulesToFE(miner.getEnergyUsage()), unit = "FE/t", source = source })
metrics:insert(Metric{ name = self.prefix .. 'to_mine', value = miner.getToMine(), unit = "item", source = source })
metrics:insert(Metric{ name = self.prefix .. 'running', value = (miner.isRunning() and 1 or 0), unit = nil, source = source })
elseif v == 'energy'
metrics:insert(Metric{ name = self.prefix .. 'energy', value = mekanismEnergyHelper.joulesToFE(miner.getEnergy()), unit = "FE", source = source })
end

loaded[v] = true
end

return metrics
end

return DigitalMinerInputAdapter
68 changes: 68 additions & 0 deletions src/telem/lib/input/mekanism/DynamicTankInputAdapter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local o = require 'telem.lib.ObjectModel'
local t = require 'telem.lib.util'

local InputAdapter = require 'telem.lib.InputAdapter'
local Metric = require 'telem.lib.Metric'
local MetricCollection = require 'telem.lib.MetricCollection'

local DynamicTankInputAdapter = o.class(InputAdapter)
DynamicTankInputAdapter.type = 'DynamicTankInputAdapter'

function DynamicTankInputAdapter:constructor (peripheralName, categories)
self:super('constructor')

-- TODO this will be a configurable feature later
self.prefix = 'mekchemtank:'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend mekdynamictank: for prefix


-- TODO make these constants
local allCategories = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend basic category only, see comments in read()

'basic',
'chemical'
}

if not categories then
self.categories = { 'basic' }
elseif categories == '*' then
self.categories = allCategories
else
self.categories = categories
end

-- boot components
self:setBoot(function ()
self.components = {}

self:addComponentByPeripheralID(peripheralName)
end)()
end

function DynamicTankInputAdapter:read ()
self:boot()

local source, tank = next(self.components)

local metrics = MetricCollection()

local loaded = {}

for _,v in ipairs(self.categories) do
-- skip, already loaded
if loaded[v] then
-- do nothing

-- Literally all we have lmao
elseif v == 'basic' then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend putting everything in basic category to match Chemical Tank adapter layout.

I think tank_capacity and chemical_tank_capacity would be the most correct here. Dynamic Tanks can store more mB of chemical vs fluid for the same structure dimensions, so there are technically two maximum capacities depending on the contents. 🤷

metrics:insert(Metric{ name = self.prefix .. 'capacity', value = (tank.getTankCapacity() / 1000), unit = "B", source = source })
metrics:insert(Metric{ name = self.prefix .. 'stored', value = (tank.getStored().amount / 1000), unit = "B", source = source }) -- might error might not, no clue!
metrics:insert(Metric{ name = self.prefix .. 'filled_percentage', value = tank.getFilledPercentage(), unit = nil, source = source })
elseif v == 'chemical' then -- dunno what this does /shrug
metrics:insert(Metric{ name = self.prefix .. 'chemical_capacity', value = (tank.getChemicalTankCapacity() / 1000), unit = "B", source = source })
end

loaded[v] = true
end

return metrics
end

return DynamicTankInputAdapter
70 changes: 70 additions & 0 deletions src/telem/lib/input/mekanism/GasGeneratorInputAdapter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
local o = require 'telem.lib.ObjectModel'
local t = require 'telem.lib.util'

local InputAdapter = require 'telem.lib.InputAdapter'
local Metric = require 'telem.lib.Metric'
local MetricCollection = require 'telem.lib.MetricCollection'

local GasGeneratorInputAdapter = o.class(InputAdapter)
GasGeneratorInputAdapter.type = 'GasGeneratorInputAdapter'

function GasGeneratorInputAdapter:constructor (peripheralName, categories)
self:super('constructor')

-- TODO this will be a configurable feature later
self.prefix = 'mekgasgen:'

-- TODO make these constants
local allCategories = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend basic, fuel, energy

'basic',
}

if not categories then
self.categories = { 'basic' }
elseif categories == '*' then
self.categories = allCategories
else
self.categories = categories
end

-- boot components
self:setBoot(function ()
self.components = {}

self:addComponentByPeripheralID(peripheralName)
end)()
end

function GasGeneratorInputAdapter:read ()
self:boot()

local source, generator = next(self.components)

local metrics = MetricCollection()

local loaded = {}

for _,v in ipairs(self.categories) do
-- skip, already loaded
if loaded[v] then
-- do nothing

-- Literally all we have lmao
elseif v == 'basic' then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Categories should be expanded:

Basic:

  • energy_filled_percentage
  • fuel_filled_percentage
  • production_rate

Fuel:

  • fuel_amount
  • fuel_capacity
  • fuel_needed

Energy:

  • energy

metrics:insert(Metric{ name = self.prefix .. 'energy', value = mekanismEnergyHelper.joulesToFE(generator.getEnergy()), unit = "FE", source = source })
metrics:insert(Metric{ name = self.prefix .. 'energy_filled_percentage', value = (generator.getEnergyFilledPercentage()), unit = nil, source = source })
metrics:insert(Metric{ name = self.prefix .. 'production_rate', value = mekanismEnergyHelper.joulesToFE(generator.getProductionRate()), unit = nil, source = source })
metrics:insert(Metric{ name = self.prefix .. 'fuel_capacity', value = (generator.getFuelCapacity() / 1000), unit = "B", source = source })
metrics:insert(Metric{ name = self.prefix .. 'fuel_amount', value = (generator.getFuel().amount / 1000), unit = "B", source = source }) -- might error might not, no clue!
metrics:insert(Metric{ name = self.prefix .. 'fuel_filled_percentage', value = generator.getFuelFilledPercentage(), unit = nil, source = source })
metrics:insert(Metric{ name = self.prefix .. 'fuel_needed', value = (generator.getFuelNeeded() / 1000), unit = 'B/t', source = source })
end

loaded[v] = true
end

return metrics
end

return GasGeneratorInputAdapter

Loading