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

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. jamdir = "jam0001"
  3. votesfile = "rawvotes.txt"
  4. teams = {}
  5. users = {}
  6. for realTeamName in os.listdir(jamdir):
  7. if not os.path.exists(f"{jamdir}/{realTeamName}/TEAM"): continue
  8. teamName = realTeamName.lower()
  9. team = {"name": teamName, "users": [], "tally": 0}
  10. teams[teamName] = team
  11. with open(f"{jamdir}/{realTeamName}/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["users"].append(name)
  19. with open(votesfile) as f:
  20. for line in f:
  21. issueName, count, voters = line[:-1].split(";")
  22. if not issueName.startswith("Team: "): continue
  23. voters = voters.strip()
  24. if voters == "": continue
  25. teamName = issueName.replace("Team: ", "")
  26. teamName = teamName.lower()
  27. voters = map(lambda x: x.strip().lower(), voters.split(":"))
  28. team = teams[teamName]
  29. for voter in voters:
  30. if voter not in users:
  31. print("Vote from non-participant:", voter, "voted for", team["name"])
  32. elif users[voter] == teamName:
  33. print("Self-vote:", voter, "voted for their own team", team["name"])
  34. else:
  35. team['tally'] += 1
  36. for team in sorted(teams.values(), key=lambda team: team["tally"]):
  37. print(f"{team['name']}: {team['tally']}")