Jump to content

Module:Storm categories

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Chlod (talk | contribs) at 01:17, 5 November 2021 (MTS). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

-- Define categories

-- All sortkeys have been guessed. They may be changed by common sense
-- or consensus at [[Wikipedia talk:WikiProject Tropical cyclones]]
local cats = {
	severe = {
		color = "ccffff",
		name = "Severe tropical storm",
		sortkey = 120
	},
	mtstorm = {
		 color = "00faf4", -- {{storm colour}} did not support. Value guessed.
		 name = "Moderate tropical storm",
		 sortkey = 105
	},
	storm = {
		color = "00faf4",
		name = "Tropical storm",
		sortkey = 100
	},
	severedep = {
		color = "5ebaff", -- {{storm colour}} did not support. Value guessed.
		name = "Severe tropical depression",
		sortkey = 120
	},
	moddepression = {
		color = "5ebaff", -- {{storm colour}} did not support. Value guessed.
		name = "Moderate tropical depression",
		sortkey = 95
	},
	depression = {
		color = "5ebaff",
		name = "Tropical depression",
		sortkey = 90
	},
	disturbance = {
		color = "80ccff",
		name = "Tropical disturbance",
		sortkey = 80
	},
	subtropicalcyclone = {
		color = "00faf4",
		name = "Subtropical cyclone",
		sortkey = 70
	},
	subtropical = {
		color = "00faf4",
		name = "Subtropical storm",
		sortkey = 65
	},
	subdepression = {
		color = "5ebaff",
		name = "Subtropical depression",
		sortkey = 60
	},
	subdisturbance = {
		color = "80ccff",
		name = "Subtropical disturbance",
		sortkey = 55
	},
	extratropical = {
		color = "cccccc",
		name = "Extratropical cyclone",
		sortkey = 50
	},
	monsoondepression = {
		color = "5ebaff",
		name = "Monsoon depression",
		sortkey = 30
	},
	potential = {
		color = "80ccff",
		name = "Potential tropical cyclone",
		sortkey = 25
	},
	posttropical = {
		color = "cccccc",
		name = "Post-tropical depression",
		sortkey = 70
	},
	remnant = {
		color = "cccccc",
		name = "Post-tropical depression",
		sortkey = 70
	},
	unknown = {
		color = "c0c0c0",
		name = "Unknown strength tropical cyclone",
		sortkey = 0
	},
	cat5 = {
		color = "ff6060",
		name = {
			Atl = "Category 5 hurricane",
			EPac = "Category 5 hurricane",
			SAtl = "Category 5 hurricane",
			WPac = "Category 5 super typhoon",
			default = "Category 5 tropical cyclone"
		},
		sortkey = 80020
	},
	cat4 = {
		color = "ff8f20",
		name = {
			Atl = "Category 4 hurricane",
			EPac = "Category 4 hurricane",
			SAtl = "Category 4 hurricane",
			WPac = "Category 4 typhoon",
			default = "Category 4 tropical cyclone"
		},
		sortkey = 80008
	},
	cat3 = {
		color = "ffc140",
		name = {
			Atl = "Category 3 hurricane",
			EPac = "Category 3 hurricane",
			SAtl = "Category 3 hurricane",
			WPac = "Category 3 typhoon",
			default = "Category 3 tropical cyclone"
		},
		sortkey = 80006
	},
	cat2 = {
		color = "ffe775",
		name = {
			Atl = "Category 2 hurricane",
			EPac = "Category 2 hurricane",
			SAtl = "Category 2 hurricane",
			WPac = "Category 2 typhoon",
			default = "Category 2 tropical cyclone"
		},
		sortkey = 80004
	},
	cat1 = {
		color = "ffffcc",
		name = {
			Atl = "Category 1 hurricane",
			EPac = "Category 1 hurricane",
			SAtl = "Category 1 hurricane",
			WPac = "Category 1 typhoon",
			default = "Category 1 tropical cyclone"
		},
		sortkey = 80002
	},
	supertyphoon = {
		color = "ff6060",
		name = "Category 4 super typhoon",
		sortkey = 80015
	},
	typhoon = {
		color = "fdaf9a",
		name = "Typhoon",
		sortkey = 60010
	},
	sprcyclstorm = {
		color = "ff6060",
		name = "Super cyclonic storm",
		sortkey = 60020
	},
	esvrcyclstorm = {
		color = "ffc140",
		name = "Extremely severe cyclonic storm",
		sortkey = 50015
	},
	vsvrcyclstorm = {
		color = "ffffcc",
		name = "Very severe cyclonic storm",
		sortkey = 50010
	},
	svrcyclstorm = {
		color = "ccffff",
		name = "Severe cyclonic storm",
		sortkey = 50008
	},
	niocyclone = {
		color = "00faf4",
		name = "Cyclonic storm",
		sortkey = 50006
	},
	deepdepression = {
		color = "5ebaff",
		name = "Deep depression",
		sortkey = 50002
	},
	niodepression = {
		color = "80ccff",
		name = "Depression",
		sortkey = 50001
	},
	nioland = {
		color = "80ccff",
		name = "Land depression",
		sortkey = 50000
	},
	aus5 = {
		color = "ff6060",
		name = "Category 5 severe tropical cyclone",
		sortkey = 40015
	},
	aus4 = {
		color = "ffc140",
		name = "Category 4 severe tropical cyclone",
		sortkey = 40013
	},
	aus3 = {
		color = "ffffcc",
		name = "Category 3 severe tropical cyclone",
		sortkey = 40010
	},
	aus2 = {
		color = "ccffff",
		name = "Category 2 tropical cyclone",
		sortkey = 40008
	},
	aus1 = {
		color = "00faf4",
		name = "Category 1 tropical cyclone",
		sortkey = 40006
	},
	low = {
		color = "5ebaff",
		name = "Tropical low",
		sortkey = 40002
	},
	sublow = {
		color = "5ebaff",
		name = "Subtropical low",
		sortkey = 40000
	},
	vintense = {
		color = "ff6060",
		name = "Very intense tropical cyclone",
		sortkey = 30010
	},
	intense = {
		color = "ffc140",
		name = "Intense tropical cyclone",
		sortkey = 30008
	},
	tropicalcyclone = {
		color = "ffffcc",
		name = "Tropical cyclone",
		sortkey = 30006
	},
	mstorm = {
		color = "00faf4",
		name = "Moderate tropical storm",
		sortkey = 30004
	},
	zodw = {
		color = "80ccff",
		name = "Zone of disturbed weather",
		sortkey = 30000
	},
	shemsvrtc = {
		color = "ffe775",
		name = "Severe tropical cyclone",
		sortkey = 20020
	},
	shem5 = {
		color = "ff6060",
		name = "Severe tropical cyclone",
		sortkey = 20010
	},
	shem4 = {
		color = "ffc140",
		name = "Tropical cyclone",
		sortkey = 20008
	},
	shem2 = {
		color = "ccffff",
		name = "Tropical cyclone",
		sortkey = 20008
	},
	shem1 = {
		color = "00faf4",
		name = "Tropical cyclone",
		sortkey = 20008
	}
}

-- Default

local defaultCategory = "unknown"

-- Define aliases

-- All non-alphanumeric characters are already stripped, and the string is
-- already set to lowercase, so additional aliases for those are no longer
-- required.

cats["sty"] = cats["supertyphoon"]
cats["nwpsevere"] = cats["severe"]
cats["strong"] = cats["severe"]
cats["swiosts"] = cats["severe"]
cats["sts"] = cats["severe"]
cats["severets"] = cats["severe"]
cats["ty"] = cats["typhoon"]
cats["td"] = cats["depression"]
cats["ts"] = cats["storm"]
cats["nwpstorm"] = cats["storm"]
cats["d"] = cats["depression"]
cats["spdepression"] = cats["depression"]
cats["shdepression"] = cats["depression"]
cats["shemdepression"] = cats["depression"]
cats["swiodepression"] = cats["depression"]
cats["spdepression"] = cats["depression"]
cats["nwpdepression"] = cats["depression"]
cats["swsubdep"] = cats["subdepression"]
cats["sd"] = cats["subdepression"]
cats["ss"] = cats["subtropical"]
cats["et"] = cats["extratropical"]
cats["md"] = cats["monsoondepression"]
cats["pt"] = cats["potential"]
cats["potentialtropicalcyclone"] = cats["potential"]
cats["potentialtropicalcyclone"] = cats["potential"]
cats["post"] = cats["remnant"]
cats["remnantlow"] = cats["remnant"]
cats["rl"] = cats["remnant"]
cats["sucs"] = cats["sprcyclstorm"]
cats["escs"] = cats["esvrcyclstorm"]
cats["vscs"] = cats["vsvrcyclstorm"]
cats["scs"] = cats["svrcyclstorm"]
cats["cs"] = cats["niocyclone"]
cats["dd"] = cats["deepdepression"]
cats["cyclstorm"] = cats["niocyclone"]
cats["landdepression"] = cats["nioland"]
cats["land"] = cats["nioland"]
cats["ld"] = cats["nioland"]
cats["fiji5"] = cats["aus5"]
cats["fiji4"] = cats["aus4"]
cats["fiji3"] = cats["aus3"]
cats["fiji2"] = cats["aus2"]
cats["fiji1"] = cats["aus1"]
cats["tl"] = cats["low"]
cats["di"] = cats["disturbance"]
cats["swiodisturbance"] = cats["disturbance"]
cats["mts"] = cats["mstorm"]
cats["sub"] = cats["mstorm"]
cats["vitc"] = cats["vintense"]
cats["itc"] = cats["intense"]
cats["tc"] = cats["tropicalcyclone"]
cats["swiotc"] = cats["tropicalcyclone"]
cats["shem3"] = cats["tropicalcyclone"]
cats["shemtc"] = cats["tropicalcyclone"]

-- Ambiguous color names. This is because {[storm colour}} itself is extremely
-- ambiguous. This is also used to override the output of some codes.
local colors = {
	["5"] = cats["cat5"].color,
	["4"] = cats["cat4"].color,
	["3"] = cats["cat3"].color,
	["2"] = cats["cat2"].color,
	["1"] = cats["cat1"].color,
	["d"] = "80ccff",
	["a5"] = cats["aus5"].color,
	["a4"] = cats["aus4"].color,
	["a3"] = cats["aus3"].color,
	["a2"] = cats["aus2"].color,
	["a1"] = cats["aus1"].color
}

function p.color(frame)
	return p._color(frame.args[1])
end

function p.name(frame)
	return p._name(frame.args[1], frame.args[2])
end

function p.sortkey(frame)
	return p._sortkey(frame.args[1])
end

function p._color(colorCode)
	-- This looks confusing, but it's actually nested ternaries (for nil checks)
	local color = string.len(colorCode) ~= 0 and 
		string.gsub(string.lower(colorCode), "[^%w]", "")
		or defaultCategory;
		
	return colors[color] or ((cats[color] or cats[defaultCategory]).color)
end

function p._name(category, basin)
	local name_def = (cats[
		string.len(category) ~= 0 and 
			string.gsub(string.lower(category), "[^%w]", "")
			or defaultCategory
	] or cats[defaultCategory]).name
	return type(name_def) == "table" and 
		(
			name_def[basin] 
			or name_def["default"] 
			or error("No default name for basin-based category name.")
		) 
		or name_def
end

function p._sortkey(category)
	-- This looks confusing, but it's actually nested ternaries (for nil checks)
	return (cats[
		string.len(category) ~= 0 and 
			string.gsub(string.lower(category), "[^%w]", "")
			or defaultCategory
	] or cats[defaultCategory]).sortkey
end

return p