„Modul:Weatherbox” változatai közötti eltérés

A Wikipédiából, a szabad enciklopédiából
[nem ellenőrzött változat][ellenőrzött változat]
Tartalom törölve Tartalom hozzáadva
A veryhigh az, amit a neve is mutat: *nagyon* magas, ezt teljesen normális nem elérni. Arról nem is beszélve, hogy teleszemeteli a kategóriát olyan lapokkal, ahol egész egyszerűen nincs napsütés megadva. Mondjuk ha nem semmitmondó nevű globális változóval számolnánk összevissza elhelyezett értékadásokkal, akkor talán feltűnne ez az eshetőség…
random értékadás ki
34. sor: 34. sor:
return 'peri-unknown'
return 'peri-unknown'
end
end
a = nil
local cat = math.max(0, math.floor(val / 10) * 10)
local cat = math.max(0, math.floor(val / 10) * 10)
if cat > 140 then
if cat > 140 then

A lap 2019. január 23., 03:05-kori változata

Weatherbox[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

require('Modul:No globals')

local p = {}
local getArgs = require('Modul:Arguments').getArgs
local frame = mw.getCurrentFrame()

local month_lengths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }

local function getParams(args, suffix)
	local months = { 'Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec' }
	local ret = {}
	for i, month in ipairs(months) do
		ret[i] = tonumber(args[month .. '_' .. suffix])
	end
	return ret
end

local getColor = {}
function getColor.t(val)
	if type(val) ~= 'number' then
		return 'temp-unknown'
	end
	local cat = math.floor(val / 3) * 3
	if cat < -15 then
		cat = 'low'
	elseif cat > 42 then
		cat = 'high'
	end
	return 'temp-' .. tostring(cat)
end

function getColor.p(val)
	if type(val) ~= 'number' then
		return 'peri-unknown'
	end
	local cat = math.max(0, math.floor(val / 10) * 10)
	if cat > 140 then
		cat = 'high'
	end
	return 'peri-' .. tostring(cat)
end

function getColor.s(val)	
	if type(val) ~= 'number' then
		return 'sun-unknown'
	end
	local cat = math.max(5, math.floor((val-5) / 20) * 20 + 5)
	if cat >= 320 then
		cat = 'veryhigh'
	elseif cat > 245 then
		cat = 'high'
	end
	return 'sun-' .. tostring(cat)
end

function getColor.d(val)
	if type(val) ~= 'number' then
		return 'dailysun-unknown'
	end
	local cat = math.max(0, math.floor(val / 2) * 2)
	if cat >= 24 then
		cat = 'veryhigh'
	elseif cat > 20 then
		cat = 'high'
	end
	return 'dailysun-' .. tostring(cat)
end

local function cell(value, colorType, colorValue)
	local rounded = ''
	if value then
		rounded = frame:expandTemplate{
			title = (colorType == 't') and 'szám 0,0' or 'szám 0',
			args = { tostring(value) }
		}
	end
	return string.format('<td class="%s">%s</td>', getColor[colorType](colorValue or value), rounded)
end

local function row(title, data, colorType, summation)
	local hasData = false
	for i = 1, 12 do
		if data[i] then
			hasData = true
		end
	end
	if not hasData then
		return ''
	end
	local html = '<tr><th scope="row">' .. frame:preprocess(title) .. '</th>'
	for i = 1, 12 do
		html = html .. cell(data[i], colorType)
	end
	if summation == 'sum' then
		local sum = 0
		for i = 1, 12 do
			sum = sum + (data[i] or 0)
		end
		html = html .. cell(sum, colorType, sum/12)
	elseif summation == 'avg' then
		local sum = 0
		for i = 1, 12 do
			sum = sum + (data[i] or 0) * month_lengths[i]
		end
		html = html .. cell(sum/365, colorType)
	elseif summation == 'min' then
		local min = nil
		for i = 1, 12 do
			if data[i] and (not min or min > data[i]) then
				min = data[i]
			end
		end
		html = html .. cell(min, colorType)
	elseif summation == 'max' then
		local max = nil
		for i = 1, 12 do
			if data[i] and (not max or max < data[i]) then
				max = data[i]
			end
		end
		html = html .. cell(max, colorType)
	end
	return html .. '</tr>\n'
end

local function main(args)
	local ret = {}
	table.insert(ret, frame:extensionTag('templatestyles', '', {src='Éghajlattáblázat/style.css'}) .. '\n')
	table.insert(ret, '<table class="wikitable weatherbox">\n')
	table.insert(ret, '<tr><th class="title" colspan="14">' .. (args['város'] or args['név'] or '') .. ' éghajlati jellemzői</th></tr>\n')
	table.insert(ret, '<tr><th scope="row">Hónap</th><th>[[Január|Jan.]]</th><th>[[Február|Feb.]]</th><th>[[Március|Már.]]</th>'
		.. '<th>[[Április|Ápr.]]</th><th>[[Május|Máj.]]</th><th>[[Június|Jún.]]</th><th>[[Július|Júl.]]</th><th>[[Augusztus|Aug.]]</th>'
		.. '<th>[[Szeptember|Szep.]]</th><th>[[Október|Okt.]]</th><th>[[November|Nov.]]</th><th>[[December|Dec.]]</th><th>Év</th></tr>\n')
	table.insert(ret, row('Rekord {{Eszközleírás|max.|maximum}} hőmérséklet (°C)', getParams(args, 'max'), 't', 'max'))
	table.insert(ret, row('Átlagos {{Eszközleírás|max.|maximum}} hőmérséklet (°C)', getParams(args, 'átl_max'), 't', 'avg'))
	table.insert(ret, row('Átlaghőmérséklet (°C)', getParams(args, 'átl'), 't', 'avg'))
	table.insert(ret, row('Átlagos {{Eszközleírás|min.|minimum}} hőmérséklet (°C)', getParams(args, 'átl_min'), 't', 'avg'))
	table.insert(ret, row('Rekord {{Eszközleírás|min.|minimum}} hőmérséklet (°C)', getParams(args, 'min'), 't', 'min'))
	table.insert(ret, row('Átl.&nbsp;csapadékmennyiség&nbsp;(mm)', getParams(args, 'átl_csapadék'), 'p', 'sum'))
	table.insert(ret, row('Havi napsütéses órák száma', getParams(args, 'napos'), 's', 'sum'))
	table.insert(ret, row('Napi napsütéses órák száma', getParams(args, 'naposnap'), 'd', 'avg'))
	if args['forrás'] then
		table.insert(ret, '<tr><td class="footnote" colspan="14">Forrás: ' .. args['forrás'] .. '</td></tr>\n')
	end
	table.insert(ret, '</table>\n')
	return table.concat(ret)
end

function p.main(frame)
	local args = getArgs(frame)
	return main(args)
end

function p.col(frame)
	local args = getArgs(frame)
	return getColor[args[1]](tonumber(args[2]))
end

return p