মডিউল:সূর্যগ্রহণ
অবয়ব
This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
ব্যবহার
[সম্পাদনা]{{#invoke:সূর্যগ্রহণ|box}}
local p = {}
local args = {}
local data_module_prefix = "মডিউল:সূর্যগ্রহণ/উপাত্তভাণ্ডার/"
local convert = require('মডিউল:সংখ্যা রূপান্তরকারী').convert
local function ifnotempty(s,a,b)
if (s and s ~= '') then
return a
else
return b
end
end
local function ifexist(page)
if not page then return false end
if mw.title.new(page).exists then return true end
return false
end
local function parsedate(y,m,d)
local lang = mw.language.getContentLanguage()
d = convert('en', tostring(d))
m = convert('en', tostring(m))
y = convert('en', tostring(y))
d = (tonumber(d) < 10) and ('0' .. tonumber(d)) or (d)
m = (tonumber(m) < 10) and ('0' .. tonumber(m)) or (m)
local success, result = pcall(lang.formatDate, lang, 'j F Y', y .. '-' .. m .. '-' .. d)
return success and result or nil
end
local function parsecoord(frame, s)
local lat = s:match('^%s*([%d][%d.]*)%s*[NS]%s*[%d][%d.]*[EW]%s*$')
local NS = s:match('^%s*[%d][%d.]*%s*([NS])%s*[%d][%d.]*[EW]%s*$')
local lon = s:match('^%s*[%d][%d.]*%s*[NS]%s*([%d][%d.]*)[EW]%s*$')
local EW = s:match('^%s*[%d][%d.]*%s*[NS]%s*[%d][%d.]*([EW])%s*$')
if( lat and NS and lon and EW ) then
return frame:expandTemplate{ title = 'coord', args = {lat, NS, lon, EW, 'type:landmark'} }
else
return s
end
end
local function parsekm(frame, s)
if(s and s:match('^%s*[%d][%d.]*%s*$')) then
return frame:expandTemplate{ title = 'convert', args = {s, 'km', 'mi', abbr = 'on'} }
else
if(s and s ~= '') then
return s .. ' km'
else
return nil
end
end
end
local function parsetime(s)
if(s and s ~= '') then
local min = s:match('^%s*([%d][%d]*)m%s*[%d][%d]*s%s*$')
local sec = s:match('^%s*[%d][%d]*m%s*([%d][%d]*)s%s*$')
if( min and sec ) then
return convert('bn', tostring(tonumber(min)*60 + tonumber(sec))) .. ' সেকেন্ড' ..
' (' .. convert('bn', tostring(min)) .. ' মি ' .. convert('bn', tostring(sec)) .. ' সে)'
end
end
return s
end
local function cataloglink(c, y, m, d)
y, m, d = tonumber(y), tonumber(m), tonumber(d)
if tonumber(c) and y and m and d then
d = (d < 10) and ('0' .. d) or d
m = (m < 10) and ('0' .. m) or m
return '[https://eclipse.gsfc.nasa.gov/SEsearch/SEdata.php?Ecl=+' .. y .. m .. d .. ' ' .. convert('bn', tostring(c)) .. ']'
else
return c
end
end
local function loadsolardb(frame, s)
local yearstr = s:match('^%s*([%d][%d][%d][%d])[A-Z][a-z][a-z][%d][%d]%s*$') or ''
local function setarg(k, v)
if(v and v ~= '') then args[k] = v end
end
if( yearstr ~= '' ) then
local dbsubpage = math.floor( (tonumber(yearstr) - 1) / 50 ) * 5
local dbpage = data_module_prefix .. tostring( dbsubpage )
if (ifexist(dbpage)) then
local data = mw.loadData(dbpage)
local dargs = data[s] or error('ত্রুটি: তথ্যছক সূর্যগ্রহণে অজানা তারিখ ' .. s .. ' দেয়া হয়েছে' , 0)
setarg('date', parsedate(dargs['y'], dargs['m'] or dargs['m3'] or dargs['m2'], dargs['d'] or dargs['d2']))
setarg('image', (dargs['Ph'] and dargs['Ph'] ~= '') and '[[File:' .. dargs['Ph'] .. '|320px]]' or nil)
setarg('caption', dargs['PhCap'])
setarg('map', (dargs['Map'] and dargs['Map'] ~= '') and '[[File:' .. dargs['Map'] .. '|320px]]' or nil)
setarg('map_caption', 'মানচিত্র')
setarg('type_ref', '')
setarg('cat', cataloglink(dargs['Cat'], dargs['y'], dargs['m'] or dargs['m3'] or dargs['m2'], dargs['d'] or dargs['d2']) )
setarg('nature', dargs['Ty'])
setarg('gamma', dargs['Gam'])
setarg('magnitude', dargs['Mag'])
setarg('saros', dargs['Saros'] and '[[সৌর সারোস ' .. convert('bn', tostring(dargs['Saros'])) .. '|' .. convert('bn', tostring(dargs['Saros'])) .. ']]')
setarg('saros_sequence', dargs['Mem'])
setarg('saros_total', dargs['Max'])
setarg('max_eclipse_ref', '')
setarg('duration', parsetime(dargs['Dur']))
setarg('location', '')
setarg('coords', parsecoord(frame,dargs['Loc']))
setarg('max_width', parsekm(frame,dargs['Wid']))
setarg('times_ref', '')
setarg('start_partial', dargs['TiPB'])
setarg('start_total', dargs['TiTB'])
setarg('start_central', '')
setarg('greatest_eclipse', dargs['TiG'])
setarg('end_central', '')
setarg('end_total', dargs['TiTE'])
setarg('end_partial', dargs['TiPE'])
end
end
end
local function infobox(frame)
local abovestr = ifnotempty(args['date'],
(args['date'] or '') .. "-এর সূর্যগ্রহণ",
"ব্যবহারের নির্দেশাবলীর জন্য, [[টেমপ্লেট:তথ্যছক সূর্যগ্রহণ]] দেখুন")
local bgcolor = args['background'] or args['bgcolour'] or ''
local mapstr = ifnotempty(args['map'],
"<div style='padding-bottom:0.5em;'>" ..
(args['map'] or '') .. ifnotempty(args['map_caption'],
"<div style='line-height:1.2em; padding-top:0.1em;'>" ..
(args['map_caption'] or '') .. "</div>", '') .. '</div>')
return frame:expandTemplate{ title = 'infobox', args = {
["bodyclass"] = "vevent",
["bodystyle"] = "width:25em; text-align:left; font-size:90%;",
["above"] = abovestr,
["aboveclass"] = "summary",
["abovestyle"] = "padding-bottom:0.25em; background:" .. bgcolor .. "; line-height:1.2em; text-align:center; font-size:115%;",
------------------ Images and maps ------------------
["image"] = args['image'] or '',
["imagestyle"] = "padding-bottom:0.5em;",
["caption"] = args['caption'] or '',
["headerstyle"] = "background:#eee; font-size:105%;",
["data1"] = mapstr,
------------- Type of eclipse and saros -------------
["header2"] = "সূর্যগ্রহণের ধরন" .. (args['type_ref'] or ''),
["label3"] = "প্রকৃতি",
["data3"] = args['nature'] or '',
["label4"] = "[[গামা (সূর্যগ্রহণ) | গামা]]",
["data4"] = convert('bn', args['gamma']) or '',
["label5"] = "[[সূর্যগ্রহণের মাত্রা| মাত্রা]]",
["data5"] = convert('bn', args['magnitude']) or '',
------------------ Maximum eclipse ------------------
["header7"] = "সর্বোচ্চ সূর্যগ্রহণ" .. (args['max_eclipse_ref'] or ''),
["label8"] = "স্থিতিকাল",
["data8"] = args['duration'] or '',
["label9"] = "অবস্থান",
["data9"] = args['location'] or '',
["class9"] = "location",
["label10"] = "স্থানাঙ্ক",
["data10"] = args['coords'] or '',
["label11"] = "বলয়ের সর্বোচ্চ প্রস্থ",
["data11"] = args['max_width'] or '',
----------------------- Times -----------------------
["header12"] = "সময় ([[ইউটিসি]])" .. (args['times_ref'] or ''),
["label13"] = "(P১) আংশিক শুরু",
["data13"] = convert('bn', args['start_partial']) or '',
["label14"] = "(U১) পূর্ণ শুরু",
["data14"] = convert('bn', args['start_total']) or '',
["label15"] = "(U২) কেন্দ্রীয় শুরু",
["data15"] = convert('bn', args['start_central']) or '',
["label16"] = "সর্বাধিক সূর্যগ্রহণ",
["data16"] = convert('bn', args['greatest_eclipse']) or '',
["label17"] = "(U৩) কেন্দ্রীয় শেষ",
["data17"] = convert('bn', args['end_central']) or '',
["label18"] = "(U৪) পূর্ণ শেষ",
["data18"] = convert('bn', args['end_total']) or '',
["label19"] = "(P৪) আংশিক শেষ",
["data19"] = convert('bn', args['end_partial']) or '',
------------------------ Event references -------------------------
["header20"] = "সূত্র",
["label21"] = "[[সারোস (জ্যোতির্বিজ্ঞান) | সারোস]]",
["data21"] = (args['saros'] or '')
.. " (" .. (convert('bn', tostring(args['saros_total'])) or '') .. "টির মধ্যে " .. (convert('bn', tostring(args['saros_sequence'])) or '') .. ")",
["label22"] = "তালিকাভুক্তি # (SE5000)",
["data22"] = args['cat'] or '',
} }
end
function p.box(frame)
args = require('Module:Arguments').getArgs(frame, {
wrappers = 'টেমপ্লেট:তথ্যছক সূর্যগ্রহণ'
})
if( args['2'] and args['2'] ~= '') then
loadsolardb(frame,args['2'])
elseif( args['1'] and args['1'] ~= '') then
loadsolardb(frame,args['1'])
end
return infobox(frame)
end
return p