local categoryData = require("Module:Storm categories/categories")
local colors = require("Module:Storm categories/colors").colors
local icons = require("Module:Storm categories/icons").icons
local cats = categoryData.cats
local defaultCategory = categoryData.defaultCategory
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 defs = {
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 = "00faf4",
name = "Subtropical depression",
sortkey = 60
},
subdisturbance = {
color = "00faf4",
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 = 10010
},
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 = 10008
},
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 = 10006
},
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 = 10004
},
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 = 10002
},
supertyphoon = {
color = "ff6060",
name = "Category 4 super typhoon",
sortkey = 10015
},
typhoon = {
color = "fdaf9a",
name = "Typhoon",
sortkey = 20010
},
sprcyclstorm = {
color = "ff6060",
name = "Super cyclonic storm",
sortkey = 30020
},
esvrcyclstorm = {
color = "ff6060",
name = "Extremely severe cyclonic storm",
sortkey = 30015
},
vsvrcyclstorm = {
color = "ff6060",
name = "Very severe cyclonic storm",
sortkey = 30010
},
svrcyclstorm = {
color = "ccffff",
name = "Severe cyclonic storm",
sortkey = 30008
},
niocyclone = {
color = "00faf4",
name = "Cyclonic storm",
sortkey = 30006
},
deepdepression = {
color = "5ebaff",
name = "Deep depression",
sortkey = 30002
},
niodepression = {
color = "80ccff",
name = "Depression",
sortkey = 30001
},
nioland = {
color = "80ccff",
name = "Land depression",
sortkey = 30000
},
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 = 50010
},
intense = {
color = "ffc140",
name = "Intense tropical cyclone",
sortkey = 50008
},
tropicalcyclone = {
color = "ffffcc",
name = "Tropical cyclone",
sortkey = 50006
},
mstorm = {
color = "00faf4",
name = "Moderate tropical storm"
},
zodw = {
color = "80ccff",
name = "Zone of disturbed weather",
sortkey = 50000
},
shemsvrtc = {
color = "ffe775",
name = "Severe tropical cyclone",
sortkey = 60020
},
shem5 = {
color = "ff6060",
name = "Severe tropical cyclone",
sortkey = 60010
},
shem4 = {
color = "ffc140",
name = "Tropical cyclone",
sortkey = 60008
},
shem2 = {
color = "ccffff",
name = "Tropical cyclone",
sortkey = 60008
},
shem1 = {
color = "00faf4",
name = "Tropical cyclone",
sortkey = 60008
}
}
-- 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.
defs["sty"] = defs["supertyphoon"]
defs["strong"] = defs["severe"]
defs["swiosts"] = defs["severe"]
defs["sts"] = defs["severe"]
defs["severets"] = defs["severe"]
defs["ty"] = defs["typhoon"]
defs["td"] = defs["depression"]
defs["ts"] = defs["storm"]
defs["nwpstorm"] = defs["storm"]
defs["d"] = defs["depression"]
defs["spdepression"] = defs["depression"]
defs["shemdepression"] = defs["depression"]
defs["swiodepression"] = defs["depression"]
defs["spdepression"] = defs["depression"]
defs["nwpdepression"] = defs["depression"]
defs["swsubdep"] = defs["subdepression"]
defs["sd"] = defs["subdepression"]
defs["ss"] = defs["subtropical"]
defs["md"] = defs["monsoondepression"]
defs["pt"] = defs["potential"]
defs["post"] = defs["potential"]
defs["potentialtropicalcyclone"] = defs["potential"]
defs["potentialtropicalcyclone"] = defs["potential"]
defs["remnantlow"] = defs["remnant"]
defs["rl"] = defs["remnant"]
defs["sucs"] = defs["sprcyclstorm"]
defs["escs"] = defs["esvrcyclstorm"]
defs["vscs"] = defs["vsvrcyclstorm"]
defs["scs"] = defs["svrcyclstorm"]
defs["cs"] = defs["niocyclone"]
defs["dd"] = defs["deepdepression"]
defs["cyclstorm"] = defs["niocyclone"]
defs["landdepression"] = defs["nioland"]
defs["land"] = defs["nioland"]
defs["fiji5"] = defs["aus5"]
defs["fiji4"] = defs["aus4"]
defs["fiji3"] = defs["aus3"]
defs["fiji2"] = defs["aus2"]
defs["fiji1"] = defs["aus1"]
defs["di"] = defs["disturbance"]
defs["swiodisturbance"] = defs["disturbance"]
defs["mts"] = defs["mstorm"]
defs["sub"] = defs["mstorm"]
defs["swiotc"] = defs["tropicalcyclone"]
defs["shem3"] = defs["tropicalcyclone"]
defs["shemtc"] = defs["tropicalcyclone"]
function p.color(frame)
return p._color(frame.args[1] or frame:getParent().args[1], false)
end
function p.name(frame)
return p._name( frame.args[1], or frame:getParent().args[21]),
frame.args[2] or frame:getParent().args[2],
false
)
end
function p.sortkey(frame)
return p._sortkey(frame.args[1] or frame:getParent().args[1], false)
end
function p._coloricon(categoryframe)
return p._icon(frame.args[1] or frame:getParent().args[1], false)
end
function p.isEqual(frame)
return p._isEqual(
frame.args[1] or frame:getParent().args[1],
frame.args[2] or frame:getParent().args[2]
) and "yes" or ""
end
function p._normalizeId(category, fallback)
-- Normalize if normalizable, fall back to default if not.
return (category ~= nil and string.len(category) ~= 0) and
string.gsub(string.lower(category), "[^%w]", "") or fallback
end
function p._color(category, nilIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
local color = p._normalizeId(category, defaultCategory)
return (defs[
string.len(category) ~= 0 and
return colors[color] or ((cats[color] or (
string.gsub(string.lower(category), "[^%w]", "")
nilIfMissing
or defaultCategory
and { color = nil }
] or defs[defaultCategory]).color
or cats[defaultCategory]
)).color)
end
function p._name(category, basin, nilIfMissing)
local name_def = (defscats[
stringp.len_normalizeId(category, defaultCategory) ~= 0 and
] or (nilIfMissing and { name = nil } or cats[defaultCategory])).name
string.gsub(string.lower(category), "[^%w]", "")
or defaultCategory
] or defs[defaultCategory]).name
return type(name_def) == "table" and
(
name_def[string.lower(basin] or "default")]
or name_def["default"]
or (not nilIfMissing and error("No default name for basin-based category name.") or nil)
)
or name_def
end
function p._sortkey(category, nilIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
return (defscats[
stringp.len_normalizeId(category, defaultCategory) ~= 0 and
] or (nilIfMissing and { sortkey = nil } or cats[defaultCategory])).sortkey
string.gsub(string.lower(category), "[^%w]", "")
end
or defaultCategory
] or defs[defaultCategory]).sortkey
function p._icon(category, nilIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
local icon = p._normalizeId(category, defaultCategory)
return icons[icon] or (cats[icon] ~= nil and (
cats[icon].icon or cats["tropicalcyclone"].icon
) or (not nilIfMissing and cats[defaultCategory].icon) or nil)
end
function p._isEqual(category1, category2)
-- Checks if two IDs are equal.
-- An {{#ifeq}} check does not consider aliases. This function compares two
-- IDs in a way that considers category aliases. This works because alias
-- assignments are references to the actual table containing the category
-- info found in the main category table.
--
-- `false` will be returned if at least one of the categories are nil or
-- if the category is not defined.
local _category1 = p._normalizeId(category1)
local _category2 = p._normalizeId(category2)
return (_category1 == _category2 and _category1 ~= nil) or
cats[ _category1 ] == cats[ _category2 ] and
-- `false` if categories are undefined and not equal.
cats[ _category1 ] ~= nil
end
function p.demo(frame)
return require("Module:Storm categories/demo").demo(frame)
end
|