Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Elli/CountyResults
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} function sumRow(row) total = 0 for i, j in ipairs(row) do if (i ~= 1) then -- ignore the first entry total = total + j end end return total end function electionTable(data) local fileToGet = "Michigan/Washtenaw" -- location or local fileFullPath = "Election results/County/" .. fileToGet .. ".tab" local electionData = mw.ext.data.get(fileFullPath) local electionResults = electionData["data"] resultsWikitable = "{| align=\"center\" border=\"2\" cellpadding=\"4\" cellspacing=\"0\" style=\"float:right; margin: 1em 1em 1em 0; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;\"\n|+ '''Presidential election results'''\n|- bgcolor=lightgrey\n! Year\n! [[Democratic Party (United States)|Democratic]]\n! [[Republican Party (United States)|Republican]]\n! [[Third Party (United States)|Third Parties]]" for _, resultsRow in ipairs (electionResults) do year = resultsRow[1] demVotes = resultsRow[2] repVotes = resultsRow[3] otherVotes = resultsRow[4] -- winner is 0 for dems, 1 for republicans, -1 if tied if demVotes > repVotes then winner = 0 elseif repVotes > demVotes then winner = 1 else winner = -1 end totalVotes = demVotes + repVotes + otherVotes demPct = string.format("%.1f%%", (demVotes/totalVotes)*100) repPct = string.format("%.1f%%", (repVotes/totalVotes)*100) otherPct = string.format("%.1f%%", (otherVotes/totalVotes)*100) resultsRowWikitext = "\n|-\n| style=\"text-align:center;\" {{Party shading/" if winner == 0 then resultsRowWikitext = resultsRowWikitext .. "Democratic" elseif winner == 1 then resultsRowWikitext = resultsRowWikitext .. "Republican" else resultsRowWikitext = resultsRowWikitext .. "Independent" end resultsRowWikitext = resultsRowWikitext .. "}}|'''[[" .. tostring(year) .. " United States presidential election|" .. tostring(year) .. "]]'''\n" resultsRowWikitext = resultsRowWikitext .. "| style=\"text-align:center;\" {{Party shading/Democratic}}|" if winner == 0 then resultsRowWikitext = resultsRowWikitext .. "'''" .. demPct .. "'''" else resultsRowWikitext = resultsRowWikitext .. demPct end resultsRowWikitext = resultsRowWikitext .. " ''" .. tostring(demVotes) .. "''\n" resultsRowWikitext = resultsRowWikitext .. "| style=\"text-align:center;\" {{Party shading/Republican}}|" if winner == 1 then resultsRowWikitext = resultsRowWikitext .. "'''" .. repPct .. "'''" else resultsRowWikitext = resultsRowWikitext .. repPct end resultsRowWikitext = resultsRowWikitext .. " ''" .. tostring(repVotes) .. "''\n" resultsRowWikitext = resultsRowWikitext .. "| style=\"text-align:center;\" {{Party shading/Other}}|" resultsRowWikitext = resultsRowWikitext .. otherPct resultsRowWikitext = resultsRowWikitext .. " ''" .. tostring(otherVotes) .. "''\n" resultsWikitable = resultsWikitable .. resultsRowWikitext end return resultsWikitable .. "|}" end function p.electionTable(frame) return electionTable(frame.args.data) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Module other
(
edit
)
Template:Module rating
(
edit
)
Template:Ombox
(
edit
)
Template:Sandbox other
(
edit
)
Module:Arguments
(
edit
)
Module:Message box
(
edit
)
Module:Message box/configuration
(
edit
)
Module:Message box/ombox.css
(
edit
)
Module:Sandbox/Elli/CountyResults/doc
(
edit
)
Module:String
(
edit
)
Module:Yesno
(
edit
)