3 Jan 2011 JoeNotCharles   » (Journeyer)

The Best Albums of 2010, part 3: Counting Votes With Pyvote

Part 1

Part 2

First, a correction: for the last two posts, I’ve been linking to pyvote as the program to automatically count votes. Except I actually used VoteEngine. Natural mistake – they’re both Python programs used to count votes, and “pywhatever” is a common naming scheme for Python.

Short one this time. Last time, we turned 9 end-of-year best album lists into preferential ballots in a standard format. In order to count these ballots with VoteEngine, though, we need one more thing: as well as the file of ballots, VoteEngine needs a complete list of all candidates, which can either be passed on the command line with the “-cands” parameter or added to the ballot file itself. Our candidates are named with numbers counting up from 1, so this is easy for us to generate.

Another parameter that’s helpful is “-tie”, which takes a list of candidates in an order to use as tiebreakers. Whenever a voting system returns a tie between two candidates, the one that appears first in the -tie list is counted as the winner. I’m not actually sure what order is used if a candidate doesn’t appear in the tiebreaker list, but since we’re autogenerating the candidate list anyway it’s easy to always fill in a complete -tie list. We’ll break ties in alphabetical order based on song name.

Since we plan to count the same list of ballots over and over again with different voting methods, it will make things much easier to add these two parameters to the ballot file itself. This is a simple edit to the script we wrote last time. First, since “-cands” needs to come at the start of the file, we delay actually writing lines to the ballot file until after all ballots have been read. Then, after reading all input files and filling in the candidate map (which records candidate numbers mapped to song names), we write all the ballot lines plus two last lines: “-cands ” and “-tie “.

Here is the updated script, with the new lines highlighted.

This will output a ballots.txt that looks like this: identical to the one from last post, but with two more lines at the start.

-cands 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

-tie 85 167 195 229 255 257 119 1 20 171 26 74 187 213 3 207 37 246 23 15 162 114 216 239 200 154 142 72 102 161 143 116 13 184 79 147 63 182 219 222 137 209 89 18 243 68 118 210 82 258 6 87 228 122 196 47 179 256 108 145 35 232 175 141 101 230 56 58 211 103 129 40 203 24 42 251 194 39 186 252 238 217 98 105 21 155 138 33 204 80 242 100 16 19 225 198 223 38 131 169 62 206 69 163 134 244 120 73 192 8 248 9 41 67 123 208 91 153 254 235 10 201 177 121 127 241 53 83 159 236 181 2 30 188 249 148 44 126 170 220 176 29 12 247 173 112 93 50 109 139 151 34 95 146 52 99 117 90 110 28 140 150 45 189 250 106 66 104 174 202 46 61 96 149 71 115 190 234 135 233 86 22 17 183 130 132 259 43 136 212 199 81 111 157 215 180 14 197 164 237 49 97 245 25 76 64 36 133 107 32 124 165 92 178 11 253 158 78 54 221 75 231 125 152 113 214 144 84 5 31 226 185 65 57 168 77 70 260 27 227 94 224 205 240 166 59 191 160 4 60 128 218 51 88 48 193 156 172 7 55

41 > 1 > 12 > 35 > 11 > 46 > 52 > 71 > 78 > 122 > 6 > 95 > 9 > 50 > 26 > 20 > 130 > 13 > 132 > 19 > 134 > 136 > 81 > 144 > 42 > 16 > 40 > 68 > 21 > 8 > 28 > 22 > 31 > 60 > 29 > 2 > 92 > 100 > 172 > 175 > 94 > 177 > 178 > 36 > 183 > 96 > 192 > 67 > 195 > 34

1 > 22 > 115 > 30 > 4 > 41 > 16 > 5 > 46 > 12 > 11 > 21 > 3 > 38 > 7 > 42 > 67 > 50 > 19 > 133 > 74 > 137 > 2 > 143 > 53 > 83 > 52 > 26 > 69 > 154 > 158 > 75 > 166 > 54 > 93 > 31 > 78 > 8 > 62 > 96 > 37 > 94 > 180 > 60 > 182 > 9 > 191 > 35 > 6 > 97

70 > 1 > 3 > 2 > 30 > 42 > 55 > 43 > 44 > 75 > 5 > 13 > 105 > 125 > 7 > 19 > 129 > 51 > 12 > 6 > 8 > 36 > 20 > 4 > 26 > 148 > 23 > 150 > 45 > 83 > 18 > 163 > 109 > 10 > 33 > 169 > 170 > 15 > 173 > 14 > 97 > 110 > 93 > 50 > 39 > 46 > 190 > 90 > 64 > 98 > 63 > 108 > 201 > 203 > 206 > 99 > 9 > 89 > 211 > 37 > 24 > 21 > 61 > 218 > 17 > 16 > 221 > 35 > 225 > 102 > 40 > 112 > 69 > 25 > 231

13 > 21 > 70 > 116 > 71 > 118 > 63 > 80 > 48 > 32 > 72 > 26 > 5 > 56 > 3 > 128 > 61 > 89 > 11 > 84 > 1 > 43 > 142 > 145 > 9 > 34 > 51 > 44 > 2 > 41 > 159 > 164 > 64 > 60 > 18 > 99 > 24 > 23 > 174 > 30 > 4 > 35 > 7 > 52 > 185 > 14 > 189 > 33 > 55 > 198 > 199 > 62 > 202 > 59 > 100 > 207 > 20 > 209 > 210 > 212 > 213 > 215 > 91 > 108 > 37 > 219 > 222 > 223 > 226 > 227 > 228 > 229 > 36 > 112 > 232 > 66 > 236 > 237 > 238 > 25 > 241 > 19 > 243 > 245 > 107 > 65 > 39 > 247 > 109 > 110 > 114 > 68 > 251 > 252 > 255 > 256 > 257 > 40 > 38 > 260

10 > 6 > 1 > 2 > 73 > 8 > 19 > 29 > 121 > 17 > 4 > 7 > 15 > 23 > 27 > 47 > 3 > 76 > 45 > 12 > 18 > 79 > 16 > 88 > 106 > 5 > 33 > 28 > 14 > 11 > 49 > 162 > 165 > 167 > 22 > 113 > 57 > 58 > 13 > 92

10 > 11 > 101 > 1 > 73 > 4 > 47 > 22 > 58 > 2 > 54 > 123 > 124 > 17 > 5 > 127 > 3 > 53 > 29 > 28 > 15 > 49 > 141 > 146 > 76 > 7 > 149 > 90 > 31 > 86

10 > 1 > 3 > 25 > 17 > 14 > 4 > 119 > 48 > 6 > 9 > 18 > 2 > 7 > 77 > 5 > 104 > 85 > 24 > 20 > 44 > 139 > 43 > 107 > 147 > 32 > 8 > 87 > 34 > 82 > 51 > 59 > 12 > 27 > 36 > 84 > 62 > 171 > 80 > 33 > 66 > 176 > 15 > 40 > 61 > 186 > 187 > 111 > 197 > 56

1 > 11 > 5 > 117 > 72 > 2 > 4 > 25 > 3 > 10 > 16 > 14 > 91 > 126 > 74 > 65 > 6 > 49 > 8 > 7 > 135 > 140 > 102 > 9 > 79 > 12 > 81 > 151 > 153 > 155 > 157 > 161 > 37 > 15 > 23 > 168 > 68 > 13 > 31 > 53 > 98 > 28 > 179 > 24 > 184 > 54 > 188 > 57 > 196 > 113 > 64 > 200 > 19 > 204 > 205 > 22 > 208 > 27 > 58 > 17 > 214 > 216 > 217 > 18 > 38 > 29 > 220 > 224 > 32 > 69 > 39 > 95 > 63 > 230 > 233 > 234 > 235 > 67 > 239 > 240 > 30 > 242 > 244 > 106 > 103 > 20 > 246 > 248 > 111 > 101 > 104 > 249 > 250 > 253 > 254 > 105 > 258 > 114 > 259 > 21

10 > 2 > 6 > 15 > 3 > 4 > 9 > 120 > 20 > 27 > 1 > 8 > 45 > 24 > 17 > 14 > 13 > 103 > 131 > 66 > 57 > 138 > 82 > 38 > 25 > 59 > 39 > 5 > 152 > 77 > 156 > 160 > 65 > 18 > 16 > 56 > 55 > 86 > 23 > 85 > 87 > 47 > 32 > 181 > 21 > 34 > 193 > 194 > 48 > 88

With this file, we can count the votes using a given method by running “voteengine.py -m < ballots.txt" – giving ballots.txt on stdin. For a complete list of voting methods, see the VoteEngine docs

Ok, preparations out of the way, tomorrow I’ll start evaluating voting systems!


Syndicated 2011-01-03 05:11:48 from I Am Not Charles

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!