team/Generating election results


Instructions for generating election results once an election is completed. In this example, the election ID is 8.

  1. Go to
  2. Click on election link - get to
  3. Click on "List of all votes"
  4. Click on "Download the ballots"
  5. Browser proposes open or save - save the file (election.blt)
  6. Launch OpenSTV (version 1.5 is latest as of writing)
  7. File->New election
  8. Load election.blt file - Method: Fractional transfer STV (for the character survey, I chose the Borda method, because fractional transfer didn't make any sense)
  9. Election options: Seat number = number of desired elected candidates (1 for referendum, 5 for council, etc); Threshold = Droop, Static, Whole; Delay surplus transfer = Off; Batch elimination = Zero; click OK
  10. Election results generated - you can see the winners & count details. To generate HTML version: Results->Save results as HTML - save file election_results.html
  11. Edit HTML file to take care of MySQL formating (escape quotes, backslashes, etc) and remove HTML headers - manual process
    • remove <html> and <head>,
    • change <body> into <div>
    • sed/\'center\'/\"center\"/g
    • Ensure HTML attributes are quoted (colspan, rowspan, border, cellspacing)
    • Massage output as necessary (removing "symbols are elected" for characters survey, replacing characters with HTML entities, etc)
  12. Insert results in non-production database to test (ensure that the file is world readable & the directory hierarchy is world executable, and that the DB user has the FILE privilege):
    mysql -uelection -p election
    $ insert into election_results values (8 <the election_id on the results URL above>, LOAD_FILE('/path/to/html/file');
  13. Check that results display correctly, and massage results field if needed.
  14. Dump insert from non-prod DB to send for insertion in prod DB (as an SQL statement, to make it as easy as possible - ensures quoting & character escaping is done correctly):
    mysqldump -uelection -p -t -w 'election_results.election_id=8' election election_results > results.sql
  15. On production database, mysql -u<db user> -p < results.sql