模組:PeriodicTable/utils
外观
local p = {}
p.element_lib = require( 'Module:Element' )
p.element_data = require( 'Module:Element/data' )
p.p_data = require( 'Module:PeriodicTable/data' )
p.table_models = require( 'Module:PeriodicTable/models' )
function p.getHalflifeStyle(element)
if element.stability then
local stability = element.stability
if stability.stableCount and stability.stableCount > 0 then
for v, stables in ipairs(p.p_data.halflifestyle.stables) do
if ( stability.stableCount >= stables.stables) then
return stables.styleclass
end
end
end
if stability.halflife then
local halflife = tonumber(stability.halflife)
for v, halflifes in ipairs(p.p_data.halflifestyle.halflifes) do
if ( halflife >= halflifes.halflife) then
return halflifes.styleclass
end
end
end
end
return '';
end
function p.getTimeDesc(seconds)
string.format( "%.2f", 0.2453435 )
if seconds < 1e-3 then
local digs = math.floor(math.log10( seconds ))
local first_dig = seconds / math.pow( 10, digs )
return string.format("%.2f",first_dig) .. '×10^' .. string.format( "%d",digs) .. '秒'
elseif seconds < 0.1 then --ms
local val = seconds / (1e-3)
return string.format( "%.2f", val) .. '豪秒'
elseif seconds < 60 then --seconds
return string.format( "%.2f", seconds) .. '秒'
elseif seconds < 3600 then --min
local val = seconds / 60.0
return string.format( "%.2f", val) .. '分鐘'
elseif seconds < 86400 then --hour
local val = seconds / 3600.0
return string.format( "%.2f", val) .. '小時'
elseif seconds < 2.592e6 then --day
local val = seconds / 86400.0
return string.format( "%.2f", val) .. '天'
elseif seconds < 3.1536e7 then --month
local val = seconds / 2.592e6
return string.format( "%.2f", val) .. '個月'
elseif seconds < 3.1536e11 then --years
local val = seconds / 3.1536e7
return string.format( "%.2f", val) .. '年'
elseif seconds < 3.1536e15 then --ten_KYear
local val = seconds / 3.1536e11
return string.format( "%.2f", val) .. '萬年'
elseif seconds < 3.1536e19 then --ten_MYear
local val = seconds / 3.1536e15
return string.format( "%.2f", val) .. '億年'
else
local years = seconds / 3.1536e7
local digs = math.floor(math.log10( years ))
local first_dig = years / math.pow( 10, digs )
return string.format( "%.2f", first_dig) .. '×10^' .. string.format( "%d",digs) .. '年'
end
end
function p.getSeriesData(input_name)
for v, x in ipairs(p.p_data.series_data) do
if (x.page == input_name) then
return p.p_data.series_data[v]
end
for v1, x1 in ipairs(x.name) do
if (x1 == input_name) then
return p.p_data.series_data[v]
end
end
end
end
function p.compareSeriesList(left_list, right_list)
for left_index, left_value in ipairs(left_list) do
for right_index, right_value in ipairs(right_list) do
if left_value.name and right_value.name then
if left_value.name[1] == right_value.name[1] then return true end
end
end
end
return false
end
function p.getSeriesDataByString(input_str)
local series_list = {}; local series_list_n = 0
local input_list = {}
if string.find( input_str, ',') then
input_list=mw.text.split(input_str, ',')
else input_list={input_str}
end
for v, x in ipairs(input_list) do
local result_series = p.getSeriesData(x)
if result_series then
series_list[series_list_n + 1] = result_series
series_list_n = series_list_n + 1
else
local ele_check = p.element_lib.getListID(x)
local predicted = false
if ele_check > 0 then
local ele1 = p.element_data[ele_check]
if ele1.series then
if (ele1.predictedSeries and ele1.predictedSeries ~= '') then predicted=true end
for v_ele, x_ele in ipairs(ele1.series) do
result_series = p.getSeriesData(x_ele)
if result_series.name and result_series.name[1] ~= "金屬" then
if predicted then result_series.predicted = true end
result_series.fromElement = ele1.name
if result_series then
series_list[series_list_n + 1] = result_series
series_list_n = series_list_n + 1
end
end
end
end
end
end
end
return series_list
end
function p.checkElementList(element, list)
local check_list = mw.text.split(table.concat(element.othername or {},',') .. ',' ..
element.name .. ',' .. (element.page or element.name) .. ',' .. element.Symbol, ',')
if(list)then
for vl, xl in ipairs(element.othername) do
for vr, xr in ipairs(list) do
if mw.text.trim(xl) == mw.text.trim(xr) then return true end
end
end
end
return false
end
return p