Module:Sandbox/Terasail

local p = {}

function colorCell(val) local cell = '\n|style="text-align:center; background-color:#'	if val > 48 then		cell = cell .. '000'	elseif val >= 37 then		cell = cell .. '602000'	elseif val >= 28 then		cell = cell .. '804020'	elseif val >= 23 then		cell = cell .. 'b06030'	elseif val >= 19 then		cell = cell .. 'CC5500'	elseif val >= 16 then		cell = cell .. 'E9692C'	elseif val >= 13 then		cell = cell .. 'FF8C00'	elseif val >= 10 then		cell = cell .. 'FFA500'	elseif val >= 7 then		cell = cell .. 'FCC200'	elseif val >= 4 then		cell = cell .. 'FFDF00'	elseif val >= 1 then		cell = cell .. 'FBEC5D'	else		cell = cell .. 'FFF'	end	if val >= 19 then		cell = cell .. ';color:#FF0'	end	cell = cell .. ';"|' .. val return cell end

function noval return '\n|style="text-align:center;|—' end

function cell(val) return '\n|style="text-align:center;"|' .. val end

function redgreen(val) local temp = '\n|style="text-align:center;'	if val < 0 then		temp = temp .. 'background-color:#FFC7C7;"|' .. val elseif val > 0 then temp = temp .. 'background-color:#BFD;"|+' .. val	else		temp = temp .. '"|0' end return temp end

function p.main(frame) local args = frame:getParent.args local year = args.year local months = {args.jan, args.feb, args.mar, args.apr, args.may, args.jun, args.jul, args.aug, args.sep, args.oct, args.nov, args.dec} local refs = {args.janref, args.febref, args.marref, args.aprref, args.mayref, args.junref, args.julref, args.augref, args.sepref, args.octref, args.novref, args.decref} local restored = tonumber(args.restored) or 0 local rfas = tonumber(args.rfas) or 0 local output = '|-\n!|' .. year local counter = 0 local total = 0 for i = 1, 12 do		local month = tonumber(months[i]) if month ~= nil and month >= 0 then output = output .. colorCell(month) if (refs[i] ~= nil) then local efn = frame:expandTemplate{title='efn', args={name=refs[i]}} output = output .. efn end total = total + month counter = counter + 1 else output = output .. noval end end local mean = math.floor((total / counter) * 10) / 10 if counter == 0 then mean = 0 end output = output .. colorCell(mean) .. cell(total) .. cell(restored) .. cell(rfas) local change = restored + rfas - total output = output .. redgreen(change) return output end

return p