diff --git a/src/telem/lib/input.lua b/src/telem/lib/input.lua index b80329c..07f4699 100644 --- a/src/telem/lib/input.lua +++ b/src/telem/lib/input.lua @@ -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', } -} \ No newline at end of file +} diff --git a/src/telem/lib/input/mekanism/BioGeneratorInputAdapter.lua b/src/telem/lib/input/mekanism/BioGeneratorInputAdapter.lua new file mode 100644 index 0000000..66a4520 --- /dev/null +++ b/src/telem/lib/input/mekanism/BioGeneratorInputAdapter.lua @@ -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 = { + '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 + 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 + diff --git a/src/telem/lib/input/mekanism/ChemicalTankInputAdapter.lua b/src/telem/lib/input/mekanism/ChemicalTankInputAdapter.lua new file mode 100644 index 0000000..9d071be --- /dev/null +++ b/src/telem/lib/input/mekanism/ChemicalTankInputAdapter.lua @@ -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 + diff --git a/src/telem/lib/input/mekanism/DigitalMinerInputAdapter.lua b/src/telem/lib/input/mekanism/DigitalMinerInputAdapter.lua new file mode 100644 index 0000000..5f5b594 --- /dev/null +++ b/src/telem/lib/input/mekanism/DigitalMinerInputAdapter.lua @@ -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 = { + '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 + 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 \ No newline at end of file diff --git a/src/telem/lib/input/mekanism/DynamicTankInputAdapter.lua b/src/telem/lib/input/mekanism/DynamicTankInputAdapter.lua new file mode 100644 index 0000000..d55a15e --- /dev/null +++ b/src/telem/lib/input/mekanism/DynamicTankInputAdapter.lua @@ -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:' + + -- TODO make these constants + local allCategories = { + '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 + 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 diff --git a/src/telem/lib/input/mekanism/GasGeneratorInputAdapter.lua b/src/telem/lib/input/mekanism/GasGeneratorInputAdapter.lua new file mode 100644 index 0000000..5a53f33 --- /dev/null +++ b/src/telem/lib/input/mekanism/GasGeneratorInputAdapter.lua @@ -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 = { + '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 + 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 + diff --git a/src/telem/lib/input/mekanism/IsotopicCentrifugeInputAdapter.lua b/src/telem/lib/input/mekanism/IsotopicCentrifugeInputAdapter.lua new file mode 100644 index 0000000..e5a106e --- /dev/null +++ b/src/telem/lib/input/mekanism/IsotopicCentrifugeInputAdapter.lua @@ -0,0 +1,77 @@ +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 IsotopicCentrifugeInputAdapter = o.class(InputAdapter) +IsotopicCentrifugeInputAdapter.type = 'IsotopicCentrifugeInputAdapter' + +function IsotopicCentrifugeInputAdapter:constructor (peripheralName, categories) + self:super('constructor') + + -- TODO this will be a configurable feature later + self.prefix = 'mekunicable:' + + -- TODO make these constants + local allCategories = { + 'basic', + 'input', + 'output' + } + + 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 IsotopicCentrifugeInputAdapter:read () + self:boot() + + local source, centrifuge = 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 .. 'energy', value = centrifuge.getEnergy(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_needed', value = centrifuge.getEnergyNeeded(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_usage', value = centrifuge.getEnergyUsage(), unit = "FE/t", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_filled_percentage', value = centrifuge.getEnergyFilledPercentage(), unit = nil, source = source }) + elseif v == 'input' then + metrics:insert(Metric{ name = self.prefix .. 'input', value = centrifuge.getInput().amount / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'input_capacity', value = centrifuge.getInputCapacity() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'input_filled_percentage', value = centrifuge.getInputFilledPercentage(), unit = nil, source = source }) + elseif v == 'output' then + metrics:insert(Metric{ name = self.prefix .. 'output', value = centrifuge.getOutput().amount / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'output_capacity', value = centrifuge.getOutputCapacity() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'output_filled_percentage', value = centrifuge.getOutputFilledPercentage(), unit = nil, source = source }) + end + + loaded[v] = true + end + + return metrics +end + +return IsotopicCentrifugeInputAdapter + diff --git a/src/telem/lib/input/mekanism/LaserAmplifierInputAdapter.lua b/src/telem/lib/input/mekanism/LaserAmplifierInputAdapter.lua new file mode 100644 index 0000000..af754e5 --- /dev/null +++ b/src/telem/lib/input/mekanism/LaserAmplifierInputAdapter.lua @@ -0,0 +1,67 @@ +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 LaserAmplifierInputAdapter = o.class(InputAdapter) +LaserAmplifierInputAdapter.type = 'LaserAmplifierInputAdapter' + +function LaserAmplifierInputAdapter:constructor (peripheralName, categories) + self:super('constructor') + + -- TODO this will be a configurable feature later + self.prefix = 'meklaseramp:' + + -- 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 LaserAmplifierInputAdapter:read () + self:boot() + + local source, laser = 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 .. 'energy', value = laser.getEnergy(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_max', value = laser.getMaxEnergy(), unit = "FE", source = source }) -- might error might not, no clue! + metrics:insert(Metric{ name = self.prefix .. 'energy_needed', value = laser.getEnergyNeeded(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_filled_percentage', value = laser.getEnergyFilledPercentage(), unit = nil, source = source }) + end + + loaded[v] = true + end + + return metrics +end + +return LaserAmplifierInputAdapter + diff --git a/src/telem/lib/input/mekanism/LaserInputAdapter.lua b/src/telem/lib/input/mekanism/LaserInputAdapter.lua new file mode 100644 index 0000000..3536643 --- /dev/null +++ b/src/telem/lib/input/mekanism/LaserInputAdapter.lua @@ -0,0 +1,67 @@ +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 LaserInputAdapter = o.class(InputAdapter) +LaserInputAdapter.type = 'LaserInputAdapter' + +function LaserInputAdapter:constructor (peripheralName, categories) + self:super('constructor') + + -- TODO this will be a configurable feature later + self.prefix = 'meklaser:' + + -- 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 LaserInputAdapter:read () + self:boot() + + local source, laser = 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 .. 'energy', value = laser.getEnergy(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_max', value = laser.getMaxEnergy(), unit = "FE", source = source }) -- might error might not, no clue! + metrics:insert(Metric{ name = self.prefix .. 'energy_needed', value = laser.getEnergyNeeded(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_filled_percentage', value = laser.getEnergyFilledPercentage(), unit = nil, source = source }) + end + + loaded[v] = true + end + + return metrics +end + +return LaserInputAdapter + diff --git a/src/telem/lib/input/mekanism/MechanicalPipeInputAdapter.lua b/src/telem/lib/input/mekanism/MechanicalPipeInputAdapter.lua new file mode 100644 index 0000000..94f667d --- /dev/null +++ b/src/telem/lib/input/mekanism/MechanicalPipeInputAdapter.lua @@ -0,0 +1,67 @@ +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 MechanicalPipeInputAdapter = o.class(InputAdapter) +MechanicalPipeInputAdapter.type = 'MechanicalPipeInputAdapter' + +function MechanicalPipeInputAdapter:constructor (peripheralName, categories) + self:super('constructor') + + -- TODO this will be a configurable feature later + self.prefix = 'mekmechpipe:' + + -- 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 MechanicalPipeInputAdapter:read () + self:boot() + + local source, tube = 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 .. 'buffer', value = tube.getBuffer() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'capacity', value = tube.getCapacity() / 1000, unit = "B", source = source }) -- might error might not, no clue! + metrics:insert(Metric{ name = self.prefix .. 'needed', value = tube.getNeeded() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'filled_percentage', value = tube.getFilledPercentage(), unit = nil, source = source }) + end + + loaded[v] = true + end + + return metrics +end + +return MechanicalPipeInputAdapter + diff --git a/src/telem/lib/input/mekanism/PressurizedTubeInputAdapter.lua b/src/telem/lib/input/mekanism/PressurizedTubeInputAdapter.lua new file mode 100644 index 0000000..5cd57f7 --- /dev/null +++ b/src/telem/lib/input/mekanism/PressurizedTubeInputAdapter.lua @@ -0,0 +1,67 @@ +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 PressurizedTubeInputAdapter = o.class(InputAdapter) +PressurizedTubeInputAdapter.type = 'PressurizedTubeInputAdapter' + +function PressurizedTubeInputAdapter:constructor (peripheralName, categories) + self:super('constructor') + + -- TODO this will be a configurable feature later + self.prefix = 'mekpressurizedtube:' + + -- 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 PressurizedTubeInputAdapter:read () + self:boot() + + local source, tube = 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 .. 'buffer', value = tube.getBuffer() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'capacity', value = tube.getCapacity() / 1000, unit = "B", source = source }) -- might error might not, no clue! + metrics:insert(Metric{ name = self.prefix .. 'needed', value = tube.getNeeded() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'filled_percentage', value = tube.getFilledPercentage(), unit = nil, source = source }) + end + + loaded[v] = true + end + + return metrics +end + +return PressurizedTubeInputAdapter + diff --git a/src/telem/lib/input/mekanism/QuantumEntangloporterInputAdapter.lua b/src/telem/lib/input/mekanism/QuantumEntangloporterInputAdapter.lua new file mode 100644 index 0000000..89853ed --- /dev/null +++ b/src/telem/lib/input/mekanism/QuantumEntangloporterInputAdapter.lua @@ -0,0 +1,103 @@ +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 QuantumEntangloporterInputAdapter = o.class(InputAdapter) +QuantumEntangloporterInputAdapter.type = 'QuantumEntangloporterInputAdapter' + +function QuantumEntangloporterInputAdapter:constructor (peripheralName, categories) + self:super('constructor') + + -- TODO this will be a configurable feature later + self.prefix = 'mekquantumentanglo:' + + -- TODO make these constants + local allCategories = { + 'basic', + 'fluid', + 'gas', + 'infuse', + 'item', + 'pigment', + 'slurry', + 'loss', + } + + 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 QuantumEntangloporterInputAdapter:read () + self:boot() + + local source, quantum_entangloporter = 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 .. 'energy_amount', value = quantum_entangloporter.getEnergy(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_needed', value = quantum_entangloporter.getEnergyNeeded(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_filled_percentage', value = quantum_entangloporter.getEnergyFilledPercentage(), unit = nil, source = source }) + elseif v == 'fluid' then + metrics:insert(Metric{ name = self.prefix .. 'fluid_amount', value = quantum_entangloporter.getBufferFluid().amount / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'fluid_capacity', value = quantum_entangloporter.getBufferFluidCapacity() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'fluid_filled_percentage', value = quantum_entangloporter.getBufferFluidFilledPercentage(), unit = nil, source = source }) + metrics:insert(Metric{ name = self.prefix .. 'fluid_needed', value = quantum_entangloporter.getBufferFluidNeeded() / 1000, unit = "B", source = source }) + elseif v == 'gas' then + metrics:insert(Metric{ name = self.prefix .. 'gas_amount', value = quantum_entangloporter.getBufferGas().amount / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'gas_capacity', value = quantum_entangloporter.getBufferGasCapacity() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'gas_filled_percentage', value = quantum_entangloporter.getBufferGasFilledPercentage(), unit = nil, source = source }) + metrics:insert(Metric{ name = self.prefix .. 'gas_needed', value = quantum_entangloporter.getBufferGasNeeded() / 1000, unit = "B", source = source }) + elseif v == 'infuse' then + metrics:insert(Metric{ name = self.prefix .. 'infuse_amount', value = quantum_entangloporter.getBufferInfuse().amount / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'infuse_capacity', value = quantum_entangloporter.getBufferInfuseCapacity() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'infuse_filled_percentage', value = quantum_entangloporter.getBufferInfuseFilledPercentage(), unit = nil, source = source }) + metrics:insert(Metric{ name = self.prefix .. 'infuse_needed', value = quantum_entangloporter.getBufferInfuseNeeded() / 1000, unit = "B", source = source }) + elseif v == 'item' then + metrics:insert(Metric{ name = self.prefix .. 'item_amount', value = quantum_entangloporter.getBufferItem().count, unit = nil, source = source }) + elseif v == 'pigment' then + metrics:insert(Metric{ name = self.prefix .. 'pigment_amount', value = quantum_entangloporter.getBufferPigment().amount / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'pigment_capacity', value = quantum_entangloporter.getBufferPigmentCapacity() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'pigment_filled_percentage', value = quantum_entangloporter.getBufferPigmentFilledPercentage(), unit = nil, source = source }) + metrics:insert(Metric{ name = self.prefix .. 'pigment_needed', value = quantum_entangloporter.getBufferPigmentNeeded() / 1000, unit = "B", source = source }) + elseif v == 'slurry' then + metrics:insert(Metric{ name = self.prefix .. 'slurry_amount', value = quantum_entangloporter.getBufferSlurry().amount / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'slurry_capacity', value = quantum_entangloporter.getBufferSlurryCapacity() / 1000, unit = "B", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'slurry_filled_percentage', value = quantum_entangloporter.getBufferSlurryFilledPercentage(), unit = nil, source = source }) + metrics:insert(Metric{ name = self.prefix .. 'slurry_needed', value = quantum_entangloporter.getBufferSlurryNeeded() / 1000, unit = "B", source = source }) + elseif v == 'loss' then + metrics:insert(Metric{ name = self.prefix .. 'transfer_loss', value = quantum_entangloporter.getTransferLoss(), unit = nil, source = source }) + metrics:insert(Metric{ name = self.prefix .. 'environmental_loss', value = quantum_entangloporter.getEnvironmentalLoss(), unit = nil, source = source }) + end + + loaded[v] = true + end + + return metrics +end + +return QuantumEntangloporterInputAdapter + diff --git a/src/telem/lib/input/mekanism/UniversalCableInputAdapter.lua b/src/telem/lib/input/mekanism/UniversalCableInputAdapter.lua new file mode 100644 index 0000000..52f3b2d --- /dev/null +++ b/src/telem/lib/input/mekanism/UniversalCableInputAdapter.lua @@ -0,0 +1,67 @@ +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 UniversalCableInputAdapter = o.class(InputAdapter) +UniversalCableInputAdapter.type = 'UniversalCableInputAdapter' + +function UniversalCableInputAdapter:constructor (peripheralName, categories) + self:super('constructor') + + -- TODO this will be a configurable feature later + self.prefix = 'mekunicable:' + + -- 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 UniversalCableInputAdapter:read () + self:boot() + + local source, cable = 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 .. 'buffer', value = cable.getBuffer(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_capacity', value = cable.getCapacity(), unit = "FE", source = source }) -- might error might not, no clue! + metrics:insert(Metric{ name = self.prefix .. 'energy_needed', value = cable.getNeeded(), unit = "FE", source = source }) + metrics:insert(Metric{ name = self.prefix .. 'energy_filled_percentage', value = cable.getFilledPercentage(), unit = nil, source = source }) + end + + loaded[v] = true + end + + return metrics +end + +return UniversalCableInputAdapter +