Created
February 18, 2024 17:13
-
-
Save altilunium/60c85f63071a12ac84f101b412f0579a to your computer and use it in GitHub Desktop.
Sirekap Quick Count - DPR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
# Specify the path to your JSON file | |
file_path = 'dpr_jateng_iv' | |
meta = 'dpr_jateng_iv_meta' | |
dpr_nasional = 'dprnasional' | |
print("DPR RI - Dapil Jawa Tengah IV (Wonogiri, Karanganyar, Sragen) : 7 Kursi") | |
available_kursi = 7 | |
init_kursi = 7 | |
with open(file_path, 'r') as file: | |
data = json.load(file) | |
with open(meta, 'r') as file: | |
datam = json.load(file) | |
with open(dpr_nasional, 'r') as file: | |
nasional = json.load(file) | |
npartai = dict() | |
npartai["1"] = "PKB" | |
npartai["2"] = "Gerindra" | |
npartai["3"] = "PDIP" | |
npartai["4"] = "Golkar" | |
npartai["5"] = "NasDem" | |
npartai["6"] = "Partai Buruh" | |
npartai["7"] = "Gelora" | |
npartai["8"] = "PKS" | |
npartai["9"] = "PKN" | |
npartai["10"] = "Hanura" | |
npartai["11"] = "Garuda" | |
npartai["12"] = "PAN" | |
npartai["13"] = "PBB" | |
npartai["14"] = "Demokrat" | |
npartai["15"] = "PSI" | |
npartai["16"] = "Perindo" | |
npartai["17"] = "PPP" | |
npartai["24"] = "Partai Ummat" | |
namedb = dict() | |
for i in datam: | |
for j in datam[i]: | |
#print(j,datam[i][j]["nama"]) | |
namedb[j] = datam[i][j]["nama"] | |
partainas = dict() | |
allvotenas = 0 | |
for i in nasional["chart"]: | |
if i != "persen": | |
allvotenas = allvotenas + nasional["chart"][i] | |
partainas[i] = nasional["chart"][i] | |
partainas = dict(sorted(partainas.items(), key=lambda x: x[1], reverse=True)) | |
kpartai = dict() | |
partai = dict() | |
partaiorig = dict() | |
allvote = 0 | |
for i in data["chart"]: | |
if i != "persen": | |
allvote = allvote + data["chart"][i] | |
partai[i] = data["chart"][i] | |
partaiorig[i] = partai[i] | |
partai = dict(sorted(partai.items(), key=lambda x: x[1], reverse=True)) | |
kaderpartai_all = dict() | |
kaderpartai_p = dict() | |
kaderpartai = dict() | |
divider = dict() | |
for i in data["table"]: | |
if i != "progres": | |
kaderpartai[i] = dict() | |
divider[i] = 1 | |
kpartai[i] = 0 | |
for j in data["table"][i]: | |
if j != "jml_suara_total" and j != "jml_suara_partai": | |
kaderpartai[i][j] = data["table"][i][j] | |
kaderpartai_all[j] = data["table"][i][j] | |
kaderpartai_p[j] = i | |
kaderpartai[i]= dict(sorted(kaderpartai[i].items(), key=lambda x: x[1], reverse=True)) | |
print() | |
nothres = set() | |
print("Tidak lolos ambang batas parlemen 4% : ") | |
for i in partainas: | |
thres = partainas[i]/allvotenas * 100 | |
if thres < 4: | |
print("%s (%.2f%% / %d suara)" % (npartai[i], thres, partainas[i])) | |
nothres.add(i) | |
del partai[i] | |
print() | |
lolos = set() | |
while available_kursi != 0: | |
''' | |
for i in partai: | |
print(npartai[i],partai[i]) | |
''' | |
# pick one | |
for i in partai: | |
divider[i] = divider[i] + 2 | |
partai[i] = partaiorig[i] / divider[i] | |
for x in kaderpartai[i]: | |
print("%s : %s (%d suara)" % (npartai[i], namedb[x],kaderpartai[i][x])) | |
lolos.add(x) | |
del kaderpartai[i][x] | |
kpartai[i] = kpartai[i] + 1 | |
break | |
break | |
available_kursi = available_kursi - 1 | |
partai = dict(sorted(partai.items(), key=lambda x: x[1], reverse=True)) | |
print() | |
partaiorig = dict(sorted(partaiorig.items(), key=lambda x: x[1], reverse=True)) | |
for i in partaiorig: | |
if kpartai[i] > 0 : | |
pc = round(partaiorig[i] / allvote * 100,2) | |
nya = init_kursi * partaiorig[i] / allvote | |
#print(npartai[i],":",partaiorig[i],"suara,",pc,"% ",kpartai[i],"kursi") | |
print("%s : %d suara (%.2f %%) -> %d kursi (%d x %.2f%% = %.2f)" % (npartai[i], partaiorig[i],pc,kpartai[i],init_kursi,pc,nya)) | |
else: | |
pc = round(partaiorig[i] / allvote * 100,2) | |
print("%s : %d suara (%.2f %%)" % (npartai[i], partaiorig[i],pc)) | |
print() | |
percent = data["progres"]["progres"] / data["progres"]["total"] * 100 | |
percent = round(percent, 2) | |
percents= nasional["progres"]["progres"] / nasional["progres"]["total"] * 100 | |
percents = round(percents, 2) | |
print("Data dari Situng KPU edisi",data["ts"]) | |
#print("Data dari Situng KPU edisi",nasional["ts"],"(batas ambang parlemen)") | |
print("Data masuk : %.2f%% (%d dari %d TPS)" % (percent, data["progres"]["progres"], data["progres"]["total"])) | |
print("Data batas ambang parlemen masuk : %.2f%% (%d dari %d TPS)" % (percents, nasional["progres"]["progres"], nasional["progres"]["total"])) | |
print() | |
kaderpartai_all= dict(sorted(kaderpartai_all.items(), key=lambda x: x[1], reverse=True)) | |
for i in kaderpartai_all: | |
calegid = i | |
partaiid = kaderpartai_p[i] | |
if (i in lolos): | |
print(" %s (%d suara %s + menang)" % (namedb[i],kaderpartai_all[i],npartai[partaiid])) | |
else: | |
print("%s (%d suara %s)" % (namedb[i],kaderpartai_all[i],npartai[partaiid])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment