44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
#!/usr/bin/python
|
|
from ordynacja.models import Glos, Komitet
|
|
|
|
|
|
class obliczanieMandatow(object):
|
|
@staticmethod
|
|
def dhondta(komitety, glosy, mandaty):
|
|
glosy_kopia = list(glosy)
|
|
dzielniki_glosy = [ 1 for i in range(len(glosy_kopia)) ]
|
|
ilosc_mandatow = [ 0 for i in range(len(glosy_kopia)) ]
|
|
while(mandaty != 0):
|
|
index = 0
|
|
max = glosy_kopia[0]
|
|
for i in range(1,len(glosy_kopia)):
|
|
if(glosy_kopia[i]>=max):
|
|
if(glosy_kopia[i]==max):
|
|
if(glosy[i]>glosy[index]):
|
|
max = glosy_kopia[i]
|
|
index = i
|
|
else:
|
|
max = glosy_kopia[i]
|
|
index = i
|
|
dzielniki_glosy[index] = dzielniki_glosy[index] + 1
|
|
print glosy_kopia[index], '', komitety[index]
|
|
glosy_kopia[index] = glosy[index] / dzielniki_glosy[index]
|
|
mandaty = mandaty - 1
|
|
ilosc_mandatow[index] = ilosc_mandatow[index] + 1
|
|
return ilosc_mandatow
|
|
|
|
liczba_okregow = 41
|
|
mandaty_w_okregach = [12,8,14,12,13,15,12,12,10,9,12,8,14,10,9,10,9,12,20,12,12,11,15,14,12,14,9,7,9,9,12,9,16,8,10,12,9,9,10,8,12]
|
|
|
|
for i in range(liczba_okregow):
|
|
komitety = []
|
|
liczba_glosow = []
|
|
|
|
komitetyBaza = Komitet.objects().all()
|
|
for j in KomitetBaza:
|
|
komitety.append(j.name)
|
|
glosy = Glos.objects().filter(okreg=i+1).order_by("kw_id")
|
|
for g in glosy:
|
|
liczba_glosow.append(g.liczba)
|
|
obliczanieMandatow.dhondta(komitety, liczba_glosow, mandaty_w_okregach[i])
|