Guest User

Untitled

a guest
Sep 9th, 2022
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | Source Code | 0 0
  1. import json
  2.  
  3. #bring data in
  4. with open(r'C:\bigfiles\CvrExport.json', "r") as cvrfile:
  5. cvrstr = cvrfile.read()
  6. fullcvr = json.loads(cvrstr)
  7.  
  8. #make empty array to receive data about the special general, strip the rest
  9. receiver = []
  10. for i in fullcvr.get("Sessions"):
  11. for j in i.get("Original").get("Cards"):
  12. for k in j.get("Contests"):
  13. if k.get("Id") == 69:
  14. receiver.append(k)
  15.  
  16. #if a candidate is already given an early rank, strip the candidate from later ranks, sweep a couple times
  17. grandtotal = len(receiver)
  18. for i in receiver:
  19. duplicatesweeps=3
  20. while duplicatesweeps>0:
  21. for m in i.get("Marks"):
  22. for n in i.get("Marks"):
  23. if m.get("CandidateId") == n.get("CandidateId"):
  24. if m.get("Rank") < n.get("Rank"):
  25. i.get("Marks").remove(n)
  26. duplicatesweeps-=1
  27.  
  28. #special receiver and count, for items in main receiver with overvotes
  29. overvotes = 0
  30. ovreceiver = []
  31.  
  32. container = []
  33. for i in receiver:
  34. vote = [0,0,0,0]
  35. filled = [0,0,0,0]
  36. for j in i.get("Marks"):
  37. spot = j.get("Rank") - 1
  38. if j.get("CandidateId") != 214:
  39. vote[spot] = j.get("CandidateId")
  40. filled[spot] += 1
  41. if 2 not in filled:
  42. container.append(vote)
  43. else:
  44. overvotes += 1
  45. ovreceiver.append(i)
  46.  
  47. ovcontainer = []
  48.  
  49. for i in ovreceiver:
  50. ovote = [[],[],[],[]]
  51. for mark in i.get("Marks"):
  52. rank = mark.get("Rank") - 1
  53. if mark.get("CandidateId") != 214:
  54. ovote[rank].append(mark.get("CandidateId"))
  55. ovcontainer.append(ovote)
  56.  
  57. missedwriteins=0
  58. for m in container:
  59. for n in m:
  60. if n == 214:
  61. m[m.index(n)]=0
  62. missedwriteins+=1
  63. print(missedwriteins," write-ins escaped sweep")
  64.  
  65. for m in container:
  66. already = [0]
  67. for n in range(len(m)):
  68. if m[n] in already:
  69. m[n] = 0
  70. else:
  71. already.append(m[n])
  72.  
  73.  
  74. for m in container:
  75. count=0
  76. while 0 in m:
  77. count += 1
  78. m.remove(0)
  79. m.extend([0]*count)
  80.  
  81. for m in container:
  82. m.remove(m[2])
  83. m.remove(m[2])
  84. for n in m:
  85. if 0 in m:
  86. m.remove(0)
  87.  
  88. perms = []
  89. tally = []
  90. for m in container:
  91. if m not in perms:
  92. perms.append(m)
  93. tally.append(0)
  94.  
  95. for a in range(len(perms)):
  96. for m in container:
  97. if perms[a] == m:
  98. tally[a]+=1
  99.  
  100. #overvote info
  101. operms = []
  102. otally = []
  103.  
  104. #pick one block to uncomment
  105.  
  106. #raw totals
  107. # for m in ovcontainer:
  108. # if m not in operms:
  109. # operms.append(m)
  110. # otally.append(0)
  111.  
  112. #where did people place their overvotes in a "if it were cardinal" sense
  113. # for m in ovcontainer:
  114. # for n in range(len(m)):
  115. # m[n]=len(m[n])
  116. # if m not in operms:
  117. # operms.append(m)
  118. # otally.append(0)
  119.  
  120. #strip empty arrays to push everything to the front of the line
  121. for m in ovcontainer:
  122. for n in range(len(m)):
  123. m.remove([]) if [] in m else ()
  124. for n in range(len(m)):
  125. if len(m[n]) != 1:
  126. m[n] = "other"
  127.  
  128. if m not in operms:
  129. if len(m) > 1 or "other" in m:
  130. operms.append(m)
  131. otally.append(0)
  132.  
  133. #end pick one
  134.  
  135. for a in range(len(operms)):
  136. for m in ovcontainer:
  137. if operms[a] == m:
  138. otally[a]+=1
  139.  
  140.  
  141. votes = sum([sum(otally),sum(tally)])
  142.  
  143. #printout
  144. print("---totals---")
  145. print(grandtotal," total votes")
  146. print(votes)
  147. print(sum(tally)," normal votes")
  148. print(overvotes," overvotes")
  149. print(sum(otally))
  150. print("---preferences from standard votes---")
  151. for a in range(len(perms)):
  152. print(str(tally[a]) + " votes of " + str(perms[a]))
  153. print("---recovered preferences from overvotes---")
  154. for a in range(len(operms)):
  155. print(str(otally[a]) + " votes of " + str(operms[a]))
  156.  
Advertisement
Add Comment
Please, Sign In to add comment