Improving quality and maintenance of election result boxes on Wikipedia

By

I've spent a decent amount of time reading Wikipedia articles about Senate, House, and state races this week. And...there were inconsistencies. Specifically in the election box result templates:

Before I updated the article

That's what it looked like before I updated the article to use my template instead. There are a few different issues. First, Mike Thompson isn't marked as the incumbent. And second, the total number of votes is wrong - if you do the math, it adds up to 292,091. There are two more cosmetic issues: 1) the % column should go to one decimal point, and 2) the empty turnout field should be hidden since we don't have that data available.

The fixed version

That's the fixed version, that's using my template. So what's different? The main thing that most editors will notice is the amount of wikitext it took to generate my version: {{election box US auto|California|2016|United States Representative District 5|Mike Thompson link=Mike Thompson (California politician)}}. Compare that to what was needed previously. I think it's a pretty big improvement. Oh, and if you set the year to a comma separated list, like "2012,2014,2016", it'll generate all three boxes at once, so it becomes even easier to use.

This will also reduce the maintenance burden significantly. These boxes are copied to other articles, including Mike Thompson (California politician), which is using the wrong styles and missing the 2016 general election entirely, and on United States House of Representatives elections in California, 2016, which actually looks correct!

This is all being generated by a single Lua module called Module:Election box US auto, and a tabular data spreadsheet that's available on Commons. The Lua code isn't the cleanest, but it proves that we can replace things that were manually maintained with smarter templates that do most of the heavy lifting. To the best of my knowledge, this appears to be the first usage of the new tabular data system in English Wikipedia articles. I've updated the California's 1st congressional district through 8th district articles to use the "auto" template so far.

What's next? I'm going to import the MIT Election Data for the US House dataset to Commons so we can start using this in more articles outside of California soon (waiting on bot approval). The only thing that's missing from that dataset is incumbency data - it doesn't indicate whether the candidate was running as an incumbent (so if you know of incumbency data, please let me know!). And once we get the House in good shape, we can move onto the Senate and then state races. Aaaand I've even had someone ask me about expanding this to other countries, which should totally be doable! Anything is possible with Lua+tabular data.