p =
function julian(date_string) jdate = mw.getCurrentFrame:getParent:expandTemplate return jdateend
function year(jdate) year = mw.getCurrentFrame:getParent:expandTemplate return year end
function historic_EVs(state, year) historic_EVs = tonumber(mw.getCurrentFrame:getParent:expandTemplate) + 2 return historic_EVsend
--Plots bar segmentsfunction p.bars(frame) local height = frame.args['height'] or 450 local max_tot = frame.args['max_tot'] local updated = frame.args['updated'] local parent = mw.getCurrentFrame:getParent running_dates = running_EVs = -- for index,date in pairs(running_dates) do-- running_totals[index] = 0 -- end
local i = 1 local bars = local totals = while parent:expandTemplate~= do state = parent:expandTemplate join1 = julian(parent:expandTemplate) drop1 = julian(parent:expandTemplate) join2 = julian(parent:expandTemplate) drop2 = julian(parent:expandTemplate) state_dates = state_ismember = state_EVs = for index,state_date in pairs(state_dates) do state_EVs[index] = 0 end if state
for running_index,running_date in pairs(running_dates) do for state_index,state_date in pairs(state_dates) do if running_date > state_dates[state_index] and not running_date > state_dates[state_index+1] then table.insert(state_dates, state_index+1, running_date) if state_ismember[state_index]
bars = bars .. parent:expandTemplate end
i = i+1 return barsend-- if i -- for each date in dates: date_EV_pairs([date]) = USHRseats(date)+2 (when a member); = 0 (when not a member)-- multiply a binary array of joined status by an array of EV values on those dates -- start1_EVs = parent:expandTemplate-- end1_EVs = parent:expandTemplate-- start2_EVs = parent:expandTemplate-- end2_EVs = parent:expandTemplate -- Generate table of dates and EVs, and insert Census and other change dates-- Add any new change dates (events other than start1) and expand running_totals table-- Sort dates and totals and send to bars template --Given a timespan from Jan 1, 2006 to a given end date "updated">, calculates the percentage of time elapsed as of a given intermediate date "date".function p.percent(frame) local parent = mw.getCurrentFrame:getParent local date = parent:expandTemplate local updated = parent:expandTemplate local start = parent:expandTemplate percent = 100 * (date - start)/(updated - start) return percent end --Draws interior gray bars on odd yearsfunction p.stripes(frame) local parent = mw.getCurrentFrame:getParent local updated = frame.args['updated'] local year_updated = parent:expandTemplate local stripes = for year = 2006, year_updated, 2 do stripes = stripes .. ' ' end return stripes end return p