<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FElli%2FResultsTable</id>
	<title>Module:Sandbox/Elli/ResultsTable - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FElli%2FResultsTable"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Elli/ResultsTable&amp;action=history"/>
	<updated>2026-04-09T23:42:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/Elli/ResultsTable&amp;diff=145367&amp;oldid=prev</id>
		<title>imported&gt;Elli at 14:09, 20 March 2021</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Elli/ResultsTable&amp;diff=145367&amp;oldid=prev"/>
		<updated>2021-03-20T14:09:41Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- this is a Lua module for working with [[mw:Help:Tabular Data|Tabular Data]] from Wikimedia Commons. the goal is to consistently display &amp;quot;election results by county&amp;quot; tables&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function sumRow(row)&lt;br /&gt;
	total = 0&lt;br /&gt;
	for i, j in ipairs(row) do&lt;br /&gt;
		if (i ~= 1) then -- ignore the first entry&lt;br /&gt;
			total = total + j&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return total&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function electionTable(data)&lt;br /&gt;
	local fileToGet = data or &amp;quot;2020 United States presidential election/Connecticut&amp;quot;&lt;br /&gt;
	local fileFullPath = &amp;quot;Election results/&amp;quot; .. fileToGet .. &amp;quot;.tab&amp;quot;&lt;br /&gt;
	local electionData = mw.ext.data.get(fileFullPath)&lt;br /&gt;
	local electionResults = electionData[&amp;quot;data&amp;quot;]&lt;br /&gt;
	local electionSchema = electionData[&amp;quot;schema&amp;quot;][&amp;quot;fields&amp;quot;]&lt;br /&gt;
	resultsWikitable = &amp;quot;{| class=\&amp;quot;wikitable sortable\&amp;quot;&amp;quot; .. &amp;quot;\n! rowspan=2 |&amp;quot; .. electionSchema[1][&amp;quot;title&amp;quot;]&lt;br /&gt;
	for _, schemaRow in ipairs(electionSchema) do&lt;br /&gt;
		if (_ ~= 1) then -- this is to avoid duplicating the county entry&lt;br /&gt;
			resultsWikitable = resultsWikitable .. &amp;quot;\n! colspan=2 |&amp;quot; .. schemaRow[&amp;quot;title&amp;quot;]&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	resultsWikitable = resultsWikitable .. &amp;quot;\n! rowspan=2 |Total\n|-&amp;quot;&lt;br /&gt;
	for _, schemaRow in ipairs(electionSchema) do&lt;br /&gt;
		if (_ ~= 1) then -- this is to avoid duplicating the county entry&lt;br /&gt;
			resultsWikitable = resultsWikitable .. &amp;quot;\n ! # \n ! %&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	for _, resultsRow in ipairs(electionResults) do&lt;br /&gt;
		resultsLocal = &amp;quot;\n|-\n|&amp;quot; .. resultsRow[1] -- start of this row&amp;#039;s table syntax and the row&amp;#039;s name&lt;br /&gt;
		rowTotal = sumRow(resultsRow)&lt;br /&gt;
		for _, column in ipairs(resultsRow) do &lt;br /&gt;
			if (_ ~= 1) then -- this is to avoid duplicating the county entry&lt;br /&gt;
				resultsLocal = resultsLocal .. &amp;quot;||&amp;quot; .. column -- raw&lt;br /&gt;
				resultsLocal = resultsLocal .. &amp;quot;||&amp;quot; .. math.floor(column*1000/rowTotal)/10 .. &amp;quot;%&amp;quot; -- one decimal of precision&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		resultsWikitable = resultsWikitable .. resultsLocal .. &amp;quot;||&amp;quot; .. rowTotal&lt;br /&gt;
	end&lt;br /&gt;
	return resultsWikitable .. &amp;quot;\n|}&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.electionTable(frame)&lt;br /&gt;
	return electionTable(frame.args.data)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Elli</name></author>
	</entry>
</feed>