Module:FuelBurnTime

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

p.getBurnTime = function(x, isForStack) local itemName = x.args.item ~= nil and x.args.item or x.args[1] local tables = 'fuel_consumers=fc, items=i' local fields = 'i.mEnergyValue=energy, fc.power=power, fc.consumer=consumer, i.mForm=mForm, i.mStackSize=stackSize' local args = { join = 'fc.acceptedFuel HOLDS i.mDisplayName', where = 'i.mDisplayName="' .. itemName .. '" and fc.consumer IS NOT NULL' } local result = cargo.query(tables, fields, args) local text = '' for i, usage in pairs(result) do   if i ~= 1 then text = text .. ' ' end local isFluid = usage.mForm == 'RF_LIQUID' local stackSize = isForStack and usage.stackSize or 1 local burnTime = usage.energy / usage.power * (isFluid and 1000 or 1) * 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 not isForStack 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

p.getStackBurnTime = function(x) return p.getBurnTime(x, true) end

return p