Revision aaba50db stv.py

b/stv.py
136 136
    logger = logging.getLogger(SVT_LOGGER)
137 137
    transferred = []
138 138
    # Keep a hash of ballot moves for logging purposes.
139
    # The hash comprises 
139
    # Keys are a tuple of the form (from_recipient, to_recipient, value)
140
    # where value is the current value of the ballot. Each tuple points
141
    # to the ballot being moved.
140 142
    moves = {}
141 143

  
142 144
    for ballot in allocated[selected]:
......
159 161
                vote_count[selected] -= current_value
160 162
                reallocated = True
161 163
                if (selected, recipient, current_value) in moves:
162
                    moves[(selected, recipient, current_value)] += 1
164
                    moves[(selected, recipient, current_value)].append(ballot)
163 165
                else:
164
                    moves[(selected, recipient, current_value)] = 1
166
                    moves[(selected, recipient, current_value)] = [ballot]
165 167
                transferred.append(ballot)
166 168
            else:
167 169
                i += 1
168
    for move, times in moves.iteritems():
170
    for move, ballots in moves.iteritems():
171
        times = len(ballots)
169 172
        description =  "from {0} to {1} {2}*{3}={4}".format(move[0],
170 173
                                                            move[1],
171 174
                                                            times,
172 175
                                                            move[2],
173
                                                            times*move[2])
176
                                                            times *move[2])
174 177
        logger.info(LOG_MESSAGE.format(action=Action.TRANSFER,
175 178
                                       desc=description))
176 179
    allocated[selected][:] = [x for x in allocated[selected]

Also available in: Unified diff