Модуль:Сонечнае зацьменне

Дакументацыю да гэтага модуля можна стварыць у Модуль:Сонечнае зацьменне/Дакументацыя

local eclipse = {}local args = {}local data_module_prefix = "Модуль:Сонечнае зацьменне/БД/"local function ifnotempty(s,a,b)if (s and s ~= '') thenreturn aelsereturn bendendlocal function ifexist(page)    if not page then return false end    if mw.title.new(page).exists then return true end    return falseendlocal function parsedate(y,m,d)local lang = mw.language.getContentLanguage()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 xg Y', y .. '-' .. m .. '-' .. d)return success and result or nilendlocal 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 ) thenreturn frame:expandTemplate{ title = 'coord', args = {lat, NS, lon, EW, 'type:landmark'} }elsereturn sendendlocal function parsetime(s)if(s and s ~= '') thenlocal 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 ) thenreturn tostring(tonumber(min)*60 + tonumber(sec)) .. '&nbsp;с.' ..' (' .. min .. '&nbsp;хв. ' .. sec .. '&nbsp;с.)'endendreturn sendlocal function cataloglink(c, y)if(c and tonumber(c)) thenlocal y1 = math.floor( (tonumber(y) - 1) / 100 ) * 100 + 1local y2 = y1 + 99return '[https://eclipse.gsfc.nasa.gov/SEcat5/SE' .. tostring(y1) .. '-' .. tostring(y2) .. '.html ' .. c .. ']'elsereturn cendendlocal function loadsolardb(frame, s)local yearstr = s:match('^%s*([%d][%d][%d][%d])%-[%d][%d]%-[%d][%d]%s*$') or ''local function setarg(k, v)if(v and v ~= '') then args[k] = v endendif( yearstr ~= '' ) thenlocal dbsubpage = math.floor( (tonumber(yearstr) - 1) / 50 ) * 5local dbpage  = data_module_prefix .. tostring( dbsubpage )if (ifexist(dbpage)) thenlocal data = mw.loadData(dbpage)local dargs = data[s]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 '[[Файл:' .. dargs['Ph']  .. '|320px]]' or nil)setarg('caption', dargs['PhCap'])setarg('map', (dargs['Map'] and dargs['Map'] ~= '') and '[[Файл:' .. dargs['Map']  .. '|320px]]' or nil)setarg('map_caption', 'Карта')setarg('type_ref', '')setarg('cat', cataloglink(dargs['Cat'], dargs['y']) )setarg('nature', dargs['Ty'])setarg('gamma', dargs['Gam'])setarg('magnitude', dargs['Mag'])setarg('saros', 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', 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'])endendendlocal function infobox(frame)local abovestr = ifnotempty(args['date'], "Сонечнае зацьменне " .. (args['date'] 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:#FFFFC0; line-height:1.2em; text-align:center; font-size:110%;",------------------ Выявы і мапы ------------------["image"] = args['image'] or '',["imagestyle"] = "padding-bottom:0.5em;",["caption"] = args['caption'] or '',["headerstyle"] = "background:#FFFFC0; font-size:105%;",["data1"] = mapstr,------------- Тып зацьмення і сарас -------------["header2"] = "Класіфікацыя" .. (args['type_ref'] or ''),["label3"] = "Тып",["data3"] = args['nature'] or '',["label4"] = "[[Сарас]]",["data4"] = "[[Сонечны сарас " .. args['saros'] .. "|" .. args['saros'] .. "]]" or '',["label5"] = "[[Гама (зацьменні)|Гама]]",["data5"] = args['gamma'] or '',["label6"] = "Велічыня",["data6"] = args['magnitude'] or '',------------------ Максімум зацьмення ------------------["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 '',----------------------- Час -----------------------["header12"] = "Час ([[Універсальны каардынаваны час|UTC]])" .. (args['times_ref'] or ''),["label13"] = "(P1) Пачатак частковага",["data13"] = args['start_partial'] or '',["label14"] = "(U1) Пачатак поўнага",["data14"] = args['start_total'] or '',["label15"] = "(U2) Пачатак цэнтральнага",["data15"] = args['start_central'] or '',["label16"] = "Найбольшая фаза",["data16"] = args['greatest_eclipse'] or '',["label17"] = "(U3) Канец цэнтральнага",["data17"] = args['end_central'] or '',["label18"] = "(U4) Канец поўнага",["data18"] = args['end_total'] or '',["label19"] = "(P4) Канец частковага",["data19"] = args['end_partial'] or '',------------------------ Спасылкі падзеі -------------------------["header20"] = "Спасылкі",["label21"] = "Каталог&nbsp;#&nbsp;(SE5000)",["data21"] = args['cat'] or '',} }endfunction eclipse.box(frame)args = require('Модуль:Arguments').getArgs(frame, {wrappers = 'Шаблон:Сонечнае зацьменне'})if( args['2'] and args['2'] ~= '') thenloadsolardb(frame,args['2'])elseif( args['1'] and args['1'] ~= '') thenloadsolardb(frame,args['1'])endreturn infobox(frame)endreturn eclipse