Anti-Harassment Tools/SecurePoll Improvements/Test Results/100 so2020 elections

From mediawiki.org
Jump to navigation Jump to search

Comments[edit]

I used a script to generate 100 random elections. The popularity of the candidates followed the same distribution as first preference votes in the Stack Overflow 2020 moderator elections. My hope was to simulate re-running that election 100 times.

See also this simulation of the 2011 elections.

Election setup[edit]

  • Candidates: 6
  • Seats: 4 (the SO 2020 election actually had 2 seats, I made a mistake here)
  • Votes: 5000

Comparisons[edit]

A script compared the candidates SecurePoll and OpenSTV elected. No discrepancies in elected candidates were found in 100 elections.

R code used to generate test data[edit]

writeBallot <- function(filename, ballots, candidates, numSeats, totalVotes) {
    sink(filename)

    cat(sprintf("%s %s", length(candidates), numSeats))
    cat("\n")
    for (i in 1:totalVotes) {
        cat("1")
        for (cand in ballots[[i]]) {
            if (!is.na(cand)) {
                cat(" ")
                cat(cand)
            }
        }
        cat(" 0")
        cat("\n")
    }
    cat("0")
    cat("\n")
    for (candidate in candidates) {
        cat("\"")
        cat(candidate)
        cat("\"")
        cat("\n")
    }
    cat("\"")
    cat("ElectionTitle")
    cat("\"")
    cat("\n")

    sink()
}

candidates <- c(1, 2, 3, 4, 5, 6)
numSeats <- 4
totalVotes <- 5000

## stackoverflow-com-2020-election-results.csv comes from here: https://github.com/dominic998/SecurePoll-Test-Data/blob/main/test_data/stackoverflow-com-2020-election-results.csv
## so2020 <- read.csv("stackoverflow-com-2020-election-results.csv", header=TRUE)
distribution <- table(so2020$f)

for (j in 1:100) {

    ballots <- list()
    for (i in 1:totalVotes) {
        ballots[[i]] <- sample(1:length(candidates), sample(1:3, 1), replace=FALSE, distribution)
    }

    randomInt <- sample(1:9999999999, 1)
    filename <- sprintf("%s_%s_%s_%s.blt", length(candidates), numSeats, totalVotes, randomInt)

    writeBallot(filename, ballots, candidates, numSeats, totalVotes)

}

Files[edit]

All test data and output here: https://github.com/dominic998/SecurePoll-Test-Data/tree/main/test_data/100_so2020_elections

  • Test blt files: files ending in .blt
  • SecurePoll results: files ending _results.txt
  • OpenSTV results: files ending in .php

Environment[edit]

  • Where you tested: local docker using PHPUnit
  • Version of SecurePoll: 3.0.0 (58bf4c8) 11:07, 31 August 2021