Compare commits
No commits in common. "b92f8490a1a758b2e36a239c1bc59b92d33f7959" and "b88b0724c7a8ad1a69f78cfa98731b41f4b97181" have entirely different histories.
b92f8490a1
...
b88b0724c7
2
app.py
2
app.py
|
@ -10,7 +10,7 @@ import psycopg.rows
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Flask, session, redirect, url_for, request, render_template,
|
Flask, session, redirect, url_for, request, render_template,
|
||||||
g, abort, flash
|
g, abort
|
||||||
)
|
)
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
|
@ -45,14 +45,12 @@ def dump_ballots(ballots):
|
||||||
for r in ballot:
|
for r in ballot:
|
||||||
print(r)
|
print(r)
|
||||||
|
|
||||||
def runoff_forward(ballots):
|
def runoff(ballots):
|
||||||
count = {}
|
count = {}
|
||||||
candidates = {}
|
candidates = {}
|
||||||
for ballot in ballots:
|
for ballot in ballots:
|
||||||
for r in ballot:
|
for r in ballot:
|
||||||
if r.id not in count or len(count[r.id]) < len(ballot):
|
count[r.id] = [0] * len(ballot)
|
||||||
log.debug("count[%d] <- %d elements", r.id, len(ballot))
|
|
||||||
count[r.id] = [0] * len(ballot)
|
|
||||||
candidates[r.id] = r
|
candidates[r.id] = r
|
||||||
for ballot in ballots:
|
for ballot in ballots:
|
||||||
weight = max(r.vote_w for r in ballot)
|
weight = max(r.vote_w for r in ballot)
|
||||||
|
@ -74,21 +72,6 @@ def runoff_forward(ballots):
|
||||||
]
|
]
|
||||||
return loser, new_ballots
|
return loser, new_ballots
|
||||||
|
|
||||||
der runoff_backward(ballot):
|
|
||||||
for ballot in ballots:
|
|
||||||
for r in ballot:
|
|
||||||
if r.id not in count or len(count[r.id]) < len(ballot):
|
|
||||||
log.debug("count[%d] <- %d elements", r.id, len(ballot))
|
|
||||||
count[r.id] = [0] * len(ballot)
|
|
||||||
candidates[r.id] = r
|
|
||||||
pprint(candidates)
|
|
||||||
for ballot in ballots:
|
|
||||||
for pos, r in enumerate(ballot):
|
|
||||||
count[r.id][pos] += 1
|
|
||||||
|
|
||||||
pprint(count)
|
|
||||||
return loser, new_ballots
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = get_args()
|
args = get_args()
|
||||||
|
|
||||||
|
@ -97,7 +80,7 @@ if __name__ == "__main__":
|
||||||
result = []
|
result = []
|
||||||
while max(len(b) for b in ballots):
|
while max(len(b) for b in ballots):
|
||||||
dump_ballots(ballots)
|
dump_ballots(ballots)
|
||||||
loser, ballots = runoff_forward(ballots)
|
loser, ballots = runoff(ballots)
|
||||||
result.append(loser)
|
result.append(loser)
|
||||||
result = reversed(result)
|
result = reversed(result)
|
||||||
print("final result")
|
print("final result")
|
||||||
|
|
Loading…
Reference in New Issue