Merge branch 'master' of git.hjp.at:hjp/meeat
This commit is contained in:
commit
b88b0724c7
6
app.py
6
app.py
|
@ -412,7 +412,8 @@ def get_ballots(meet_id, kind):
|
|||
csr = get_cursor()
|
||||
|
||||
q = f"""
|
||||
select {kind}.*, bod, position, email
|
||||
select {kind}.*, bod, position, email,
|
||||
min(w) over(partition by bod order by position) as vote_w
|
||||
from {kind}
|
||||
join {kind}_vote on {kind}.id = {kind}_vote.{kind}
|
||||
join bod on bod = bod.id
|
||||
|
@ -447,11 +448,12 @@ def runoff(ballots, direction):
|
|||
count[r.id] = [0] * len(ballot)
|
||||
candidates[r.id] = r
|
||||
for ballot in ballots:
|
||||
weight = max(r.vote_w for r in ballot)
|
||||
for pos, r in enumerate(ballot):
|
||||
log.debug("count = %s", count)
|
||||
log.debug("r.id = %s", r.id)
|
||||
log.debug("pos = %s", pos)
|
||||
count[r.id][pos] += 1
|
||||
count[r.id][pos] += weight
|
||||
log.debug("count[%d][%d]) = %d", r.id, pos, count[r.id][pos])
|
||||
if direction == "backward":
|
||||
result = sorted(count.keys(), key=lambda i: list(reversed(count[i])), reverse=True)
|
||||
|
|
|
@ -21,7 +21,8 @@ def get_ballots():
|
|||
|
||||
kind = args.kind
|
||||
q = f"""
|
||||
select {kind}.*, bod, position
|
||||
select {kind}.*, bod, position,
|
||||
min(w) over(partition by bod order by position) as vote_w
|
||||
from {kind} join {kind}_vote on {kind}.id = {kind}_vote.{kind}
|
||||
where meet = %s
|
||||
order by bod, position
|
||||
|
@ -52,8 +53,9 @@ def runoff(ballots):
|
|||
count[r.id] = [0] * len(ballot)
|
||||
candidates[r.id] = r
|
||||
for ballot in ballots:
|
||||
weight = max(r.vote_w for r in ballot)
|
||||
for pos, r in enumerate(ballot):
|
||||
count[r.id][pos] += 1
|
||||
count[r.id][pos] += weight
|
||||
if args.reverse:
|
||||
result = sorted(count.keys(), key=lambda i: list(reversed(count[i])), reverse=True)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue