Tool to tally up langjam votes.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tally.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import os
  2. jamdir = "jam0001"
  3. votesfile = "rawvotes.txt"
  4. teams = {}
  5. users = {}
  6. for teamName in os.listdir(jamdir):
  7. if not os.path.exists(f"{jamdir}/{teamName}/TEAM"): continue
  8. teamName = teamName.lower()
  9. team = []
  10. teams[teamName] = team
  11. with open(f"{jamdir}/{teamName}/TEAM") as f:
  12. for line in f:
  13. for name in line.split():
  14. name = name.strip().lower()
  15. if name.startswith("[delete this line"): continue
  16. if name == "": continue
  17. users[name] = teamName
  18. team.append(name)
  19. tallies = []
  20. with open(votesfile) as f:
  21. for line in f:
  22. issueName, count, voters = line[:-1].split(";")
  23. if not issueName.startswith("Team: "): continue
  24. voters = voters.strip()
  25. if voters == "": continue
  26. teamName = issueName.replace("Team: ", "")
  27. rawTeamName = teamName
  28. teamName = teamName.lower()
  29. voters = map(lambda x: x.strip().lower(), voters.split(":"))
  30. tally = 0
  31. for voter in voters:
  32. if voter not in users:
  33. print("Vote from non-participant:", voter, "voted for", rawTeamName)
  34. elif users[voter] == teamName:
  35. print("Self-vote:", voter, "voted for their own team", rawTeamName)
  36. else:
  37. tally += 1
  38. tallies.append((rawTeamName, tally))
  39. tallies.sort(key=lambda x: x[1])
  40. for tally in tallies:
  41. print(tally[0] + ": " + str(tally[1]))