21

I just downloaded OpenSTV after seeing the most recent SO blog post, regarding the results of the moderator election. Jeff wrote that he used OpenSTV to conduct the election, and supplied a ballot file (.blt) along with it that contains the voting data.

My question is: how do you create a .BLT file in C#?

Here are two ways that I can think of that the voting page did it:

  • The voting page added each vote into a SQL database, and then somehow, these votes were exported into a .BLT file after voting had ended. How though? How can I do this?
  • Or, the voting page created the file and then added to it each time someone voted. I'm sure that this is NOT how the voting page worked, because it's completely unscalable, but how could I do this in C#?

I'm interested in finding out how both possibilities work and how I can do that in C#. Thanks in advance. Oh, and I hope Jeff sees this question, because he'd probably have a great answer...

Tim Post
  • 33,371
  • 15
  • 110
  • 174
Maxim Zaslavsky
  • 17,787
  • 30
  • 107
  • 173

1 Answers1

28

The best explanation of the BLT file format is here:

    4 2          # four candidates are competing for two seats
    -2           # Bob has withdrawn (optional)
    1 4 1 3 2 0  # first ballot
    1 2 4 1 3 0
    1 1 4 2 3 0  # The first number is the ballot weight (>= 1).
    1 1 2 4 3 0  # The last 0 is an end of ballot marker.
    1 1 4 3 0    # Numbers in between correspond to the candidates
    1 3 2 4 1 0  # on the ballot.
    1 3 4 1 2 0
    1 3 4 1 2 0  # Chuck, Diane, Amy, Bob
    1 4 3 2 0
    1 2 3 4 1 0  # last ballot
    0            # end of ballots marker
    "Amy"        # candidate 1
    "Bob"        # candidate 2
    "Chuck"      # candidate 3
    "Diane"      # candidate 4
    "Gardening Club Election"  # title

All I did was

  1. Perform an ad-hoc query in SQL Management Studio to get the voting results
  2. Copy-pasted results into a text file (output is tab-delimited by default)
  3. Wrote a small 50 line C# app to convert from the query to BLT format
Tim Post
  • 33,371
  • 15
  • 110
  • 174
Jeff Atwood
  • 63,320
  • 48
  • 150
  • 153
  • Jeff, when OpenSTV converted to the more restrictive proprietary license, they basically took down all code & wiki entries (the source code to the GPL version of OpenSTV we distribute is no longer available either). I removed the link since (thankfully) you summarized it. The format of that file is extremely difficult to find. – Tim Post Jun 16 '12 at 05:40
  • I think we should also repeat what we discussed in chat for the benefit of those coming along to simplify the "format" of a given line: `(comment goes here) W v v ... v 0` where `W` is the ballot weight and `v v ... v` are the individual votes, from 1..N votes. – jcolebrand Jun 16 '12 at 05:44
  • 3
    I'm also a bit confused on the ballot weight. If we take the SO election as an example, under what circumstances would the ballot weight not be the same for every ballot? – Tim Post Jun 16 '12 at 05:55
  • 2
    Slightly more detailed description of the file format is available in Section 3 of this [paper](http://www.dia.govt.nz/diawebsite.NSF/Files/meekm/$file/meekm.pdf). – hlidka Sep 13 '12 at 13:26
  • 2
    To address @TimPost's question, the format specifies that identical ballots should be tallied up, and this tally becomes the weight. This isn't done for the Stack Exchange election files currently, but OpenSTV at least is flexible in allowing either tallied or repeated ballot entries. – Tim Stone May 14 '15 at 04:05