Module:Events

local p = {}

local event = mw.loadData('Module:Events/data')

function range(a, b, step) if not b then b = a   a = 1 end step = step or 1 local f = step > 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue <= b then return nextvalue end end or   step < 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue >= b then return nextvalue end end or     function(_, lastvalue) return lastvalue end return f, nil, a - step end

function compareLess(x, y)   return x[1] < y[1] end function compareMore(x, y)   return x[1] > y[1] end function tableSort(table1,table2,more) for i,v in ipairs(table1) do       table1[i] = {table1[i], table2[i]} end if more == 'less' then table.sort(table1, compareLess) else table.sort(table1, compareMore) end for i, v in ipairs(table1) do       table1[i] = v[1] table2[i] = v[2] end return table2 end function eventSorted(datas, var) local key = {} local keydata = {} local more for name, data in pairs(datas) do       if var == nil then table.insert(key, eventStartDate(data)) else table.insert(key, data.lvl) more='less' end table.insert(keydata, name) end return tableSort(key,keydata,more) end function eventEndDate(data) if data.ends[1] ~= nil then return ((((data.ends[3]*100)+data.ends[2])*100)+data.ends[1])*10000 + 1400 else return 0 end end

function eventStartDate(data) if data.starts[1] ~= nil then return ((((data.starts[3]*100)+data.starts[2])*100)+data.starts[1])*10000 + 1400 else return 0 end end

function eventDate(data) return eventStartDate(data), eventEndDate(data) end function active active_events = {} local currentDate = os.date('!%Y%m%d%H%M', os.time) for name, data in pairs(event) do       if currentDate - eventEndDate(data)   < 0 and currentDate - eventStartDate(data) > 0 then table.insert(active_events, name) end end return active_events end

p.range = range p.tableSort = tableSort p.eventSorted = eventSorted p.eventDate = eventDate p.active = missingImage

function missingImage(picture) local img = '' if picture == "" or picture == nil then img = 'Missing.jpg' else img = picture end return img end

-- Not sure what it is used for? function p.infobox(frame) local event_data = event[mw.title.getCurrentTitle.text] local start_date = os.date("%a, %d %b %Y",os.time{year=event_data.starts[3], month=event_data.starts[2], day=event_data.starts[1]}) local end_date = os.date("%a, %d %b %Y",os.time{year=event_data.ends[3], month=event_data.ends[2], day=event_data.ends[1]}) local data = { image=missingImage(event_data.image), starts=start_date, ends=end_date, next=nil, prev=nil }   return  table.concat({frame:expandTemplate { title = 'Event infobox', args = data },event_data.text,}, "\n") end

function p.missions(frame) return end function p.rewards(frame) return end

function finished(event_data) local currentDate = tonumber(os.date('!%Y%m%d%H%M', os.time)) return eventEndDate(event_data) < currentDate end

function p.events(frame) local page = frame.args[1] local data = {' '} local sorted = eventSorted(event) local active = active local c = 0 if table.getn(active) > 0 then if table.getn(active) == 1 then table.insert(data, '==Current Event==') else table.insert(data, '==Current Events==') end for _, curr in ipairs(active) do           if event[curr].event_type == "D" then table.insert(data, '') else table.insert(data, '') end end end -- Past Events for name, dat in pairs(sorted) do       event_data=event[dat] if finished(event_data) then if c == 0 then table.insert(data, '==Past Event==') end c = c + 1 if event_data.event_type == "D" and (c < 9 or page ~= 'mainPage') then table.insert(data, '') elseif (c < 9 or page ~= 'mainPage') then table.insert(data, '') end end end if page == 'mainPage' then table.insert(data," Show more ") end table.insert(data,' ') --for i, dat in pairs(data) do mw.log(dat) end return table.concat(data,"\n") end

function date_format(date, format) format = format or "%d %B, %Y" local current_time = os.time{day = date[0], month = date[1], year = date[2]} return os.time(format, current_time) end

function p.past_events(frame) local args = getArgs(frame, {parentFirst = true}) if args[1] == nil then return "Please provide type of past events to generate. Module:Events p.past_events" end --   D - Daily    C - Clicking    P - Private Shows    G - Gains Week    S - Sexpedition local event_type = args[1] local data = {'') return table.concat(data, "\n") end

return p