mirror of
https://github.com/S4mpsa/InfOS.git
synced 2025-08-03 18:06:04 -04:00
32 lines
1.0 KiB
Lua
Executable File
32 lines
1.0 KiB
Lua
Executable File
-- Import section
|
|
local getConsumption = require("domain.energy.get-consumption-usecase")
|
|
local getProduction = require("domain.energy.get-production-usecase")
|
|
--
|
|
|
|
local function exec(energyProducers, energyBuffer)
|
|
-- local comsumption = getConsumption(energyBuffer)
|
|
-- local production = getProduction(energyBuffer)
|
|
local consumption = energyBuffer:getAverageInput()
|
|
local production = energyBuffer:getAverageOutput()
|
|
|
|
local changeRate = production - consumption
|
|
|
|
local totalEnergy = energyBuffer:getTotalEnergy()
|
|
local maximumEnergy = totalEnergy.maximum
|
|
local currentEnergy = totalEnergy.current
|
|
|
|
local energyLimit = changeRate > 0 and maximumEnergy or 0
|
|
|
|
local timeToFull = changeRate > 0 and (energyLimit - currentEnergy) / changeRate or nil
|
|
local timeToEmpty = changeRate < 0 and (energyLimit - currentEnergy) / changeRate or nil
|
|
|
|
return {
|
|
consumption = consumption,
|
|
production = production,
|
|
timeToFull = timeToFull,
|
|
timeToEmpty = timeToEmpty
|
|
}
|
|
end
|
|
|
|
return exec
|