Module:FuelBurnTime

local cargo = mw.ext.cargo local p = {}

p.getBurnTime = function(frame) local fuelName = frame.args.name ~= nil and frame.args.name or frame.args[1] if fuelName == nil then return end local fuelEnergy = (frame.args.energy ~= nil and frame.args.energy or frame.args[2]) or 0 local stackSize = (frame.args.stack ~= nil and tonumber(frame.args.stack) or tonumber(frame.args[3])) or 1 local isFluid = mw.getCurrentFrame:expandTemplate{title='IsFluid', args={[1]=fuelName}} isFluid = not (isFluid == '\n' or isFluid == nil or isFluid == '') local tables = 'fuel_consumers' local fields = 'power, consumer' local args = { where = 'acceptedFuel HOLDS "' .. fuelName .. '"', orderBy = 'power ASC' } local result = cargo.query(tables, fields, args) local text = '' for i=1, #result, 1 do   local usage = result[i] if i ~= 1 then text = text .. ' ' end local burnTime = fuelEnergy / usage.power * stackSize local ipm = 60 / burnTime local displayText = "'''" .. mw.getCurrentFrame:expandTemplate{title='Duration', args={[1]=burnTime}} .. "'''"   -- don't create a tooltip for stack burn time (because something like 0.126 stacks/min is a silly metric) if stackSize == 1 then -- note: power of 3 is made with html/unicode &sup3; instead of tag because inside of tooltip tags do not work local tooltipText = string.format('%.1f', ipm) .. (isFluid and ' m&sup3;/min' or '/min') text = text .. mw.getCurrentFrame:expandTemplate{title='Tooltip', args={[1]=displayText, [2]=tooltipText}} .. ' in ' .. usage.consumer .. '' else text = text .. displayText .. ' in ' .. usage.consumer .. '' end end return text end

return p