55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
# Metoda Sainte-Lague
|
|
|
|
|
|
import os, sys
|
|
proj_path = "C:/inzynierski/ordynacje"
|
|
# This is so Django knows where to find stuff.
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ordynacje.settings")
|
|
sys.path.append(proj_path)
|
|
|
|
# This is so my local_settings.py gets loaded.
|
|
os.chdir(proj_path)
|
|
|
|
# This is so models get loaded.
|
|
from django.core.wsgi import get_wsgi_application
|
|
application = get_wsgi_application()
|
|
|
|
|
|
|
|
def sainteLague (nr_okregu, liczba_mandatow):
|
|
from ordynacja.models import Glos
|
|
pobrane_glosy = Glos.objects.filter(okreg=nr_okregu).order_by("komitet")
|
|
|
|
glosy = []
|
|
uzyskane_mandaty = []
|
|
for Glos in pobrane_glosy:
|
|
glosy.append(Glos.liczba)
|
|
uzyskane_mandaty.append(0)
|
|
#print(glosy)
|
|
|
|
|
|
|
|
for j in range(liczba_mandatow):
|
|
imax = 0
|
|
for i in range(len(glosy)):
|
|
if (glosy[i]/(2 * uzyskane_mandaty[i] + 1)) > (glosy[imax]/(2 * uzyskane_mandaty[imax] + 1)):
|
|
imax = i
|
|
|
|
uzyskane_mandaty[imax] = uzyskane_mandaty[imax] + 1
|
|
|
|
#print(uzyskane_mandaty)
|
|
return uzyskane_mandaty;
|
|
|
|
from ordynacja.models import Komitet
|
|
liczba_komitetow = Komitet.objects.count()
|
|
suma = [0] * liczba_komitetow
|
|
|
|
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] #zgodnie z wyborami parlamentarnymi 2015
|
|
|
|
for i in range(liczba_okregow):
|
|
mandaty = sainteLague(i+1, mandaty_w_okregach[i])
|
|
for j in range (len(mandaty)):
|
|
suma[j] = suma[j] + mandaty[j]
|
|
|
|
print(suma) |