Mô đun:Tropical cyclone season effects
Tài liệu mô đun[tạo]
-- Được sử dụng cho các bài viết mùa xoáy thuận nhiệt đới.
local invocation = require('Mô đun:Template invocation').invocation
local getArgs = require('Mô đun:Arguments').getArgs
local yesno = require('Mô đun:Yesno')
local dateperiod = require('Mô đun:Date period')._main
local Date = require('Mô đun:Date')._Date
local p = {}
function p.main(frame)
local args = getArgs(frame, {
trim = true,
removeBlanks = false
})
return p._main(frame, args)
end
function p._main(frame, args)
if not yesno(args["no-header"]) and (args["Basin"] or args["basin"]) == nil then
error("Lưu vực không được chỉ định")
elseif not yesno(args["no-header"]) and (args["start-year"] or args["year"]) == nil then
error("Năm (hoặc năm bắt đầu) không được chỉ định")
elseif not yesno(args["no-header"]) and args["start-year"] == nil and args["end-year"] ~= nil then
error("Năm kết thúc được chỉ định nhưng năm bắt đầu không được chỉ định")
end
local tableEntries = args[1] or ""
local totalStorms = 0
local strongestWinds = 0
local tableWindsUnit = nil
local lowestPressure = 2000
local tablePressureUnit = nil
local totalDamages = 0
local totalDeaths = 0
local earliestFormed = nil;
local earliestFormedDate = nil;
local latestDissipated = nil;
local latestDissipatedDate = nil;
for name, formed, dissipated, winds, windsUnit, pressure, pressureUnit, damages, deaths in string.gmatch(
tableEntries,
'data%-tcse%-entry="([^|]+)|([%w%-]+)|([%w%-]+)|([%d%.]+)|(%w+)|([%d%.]+)|(%w+)|([%d%.]+)|(%d+)"'
) do
totalStorms = totalStorms + 1
if latestDissipated ~= "đến nay" then
if dissipated == "đến nay" then
latestDissipated = "đến nay"
elseif latestDissipated == nil or latestDissipatedDate == nil then
latestDissipated = dissipated
latestDissipatedDate= Date(dissipated)
elseif latestDissipatedDate.gsd < Date(dissipated).gsd then
latestDissipated = dissipated
latestDissipatedDate = Date(dissipated)
end
end
if earliestFormed == nil then
earliestFormed = formed
earliestFormedDate = Date(formed)
elseif earliestFormedDate.gsd > Date(formed).gsd then
earliestFormed = formed
earliestFormedDate = Date(formed)
end
if tableWindsUnit == nil then
tableWindsUnit = windsUnit
elseif windsUnit ~= tableWindsUnit then
error("Đơn vị gió của một cơn bão không trùng với đơn vị gió của tất cả các cơn bão")
end
if tablePressureUnit == nil then
tablePressureUnit = pressureUnit
elseif pressureUnit ~= tablePressureUnit then
error("Đơn vị áp suất của một cơn bão không trùng với đơn vị áp suất của tất cả các cơn bão")
end
if strongestWinds == nil or strongestWinds < tonumber(winds) then
strongestWinds = tonumber(winds)
end
if lowestPressure == nil or lowestPressure > tonumber(pressure) then
lowestPressure = tonumber(pressure)
end
totalDamages = totalDamages + tonumber(damages)
totalDeaths = totalDeaths + tonumber(deaths)
end
local tcHeader = frame:expandTemplate{
title = "Tropical cyclone season effects (top)",
args = {
["no-sort"] = totalStorms == 0 and "yes" or nil,
["no-header"] = args["no-header"],
["basin"] = args["basin"],
["start-year"] = args["start-year"] or args["year"],
["end-year"] = args["end-year"],
["currency-link"] = args["currency-link"]
}
}
-- Template parameters not yet standardized. Hence the usage of capitalized
-- parameter names.
local tcFooter = frame:expandTemplate{
title = "Tropical cyclone season effects (bottom)",
args = {
["TC's"] = "Hệ thống " .. totalStorms .. (totalStorms == 1 and "" or ""),
["dates"] = totalStorms == 0 and "Mùa chưa bắt đầu" or
dateperiod(
earliestFormed,
(latestDissipated == "đến nay" or yesno(args["active"]))
and "Mùa đang diễn ra" or latestDissipated,
(latestDissipated == "đến nay" or yesno(args["active"]))
and nil or true
),
["winds"] = totalStorms == 0 and "" or
(
tableWindsUnit == "kn" and (
frame:expandTemplate{
title = "convert",
args = {
strongestWinds,
tableWindsUnit,
args["winds-target"] or "kph",
round = "5",
abbr = "on",
disp = "out"
}
} .. (args["winds-target2"] ~= "none" and " (" .. frame:expandTemplate{
title = "convert",
args = {
strongestWinds,
tableWindsUnit,
args["winds-target2"] or "mph",
round = "5",
abbr = "on",
disp = "out"
}
} .. ")" or "")
) or frame:expandTemplate{
title = "convert",
args = {
strongestWinds,
tableWindsUnit,
args["winds-target"] or "",
round = "5",
abbr = "on"
}
}
),
["pres"] = totalStorms == 0 and "" or
frame:expandTemplate{
title = "convert",
args = {
lowestPressure,
tablePressureUnit,
args["pressure-target"] or "inHg",
comma = "off",
sigfig = 4,
abbr = "on"
}
},
["damage"] = totalStorms == 0 and "" or
frame:expandTemplate{
title = totalDamages == 0 and "nts" or "ntsp",
args = { totalDamages, "", totalDamages ~= 0 and (args["currency-symbol"] or "$") }
},
["deaths"] = totalStorms == 0 and "" or
frame:expandTemplate{
title = "nts",
args = { totalDeaths }
},
["Refs"] = args["footer-refs"] or ""
}
}
return tcHeader .. "\n" .. tableEntries .. "\n" .. tcFooter
end
return p