Matches.py 676 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python2
  2. import Combinations
  3. matches = {}
  4. def AddMatch(teams):
  5. global matches
  6. if len(teams) < 2:
  7. raise ValueError("Match has less than two teams")
  8. for teamPair in Combinations.GetAllCombinations(teams, 2):
  9. for i in [0, 1]:
  10. try:
  11. try:
  12. matches[teamPair[i]][teamPair[1-i]] += 1
  13. except KeyError:
  14. matches[teamPair[i]][teamPair[1-i]] = 1
  15. except KeyError:
  16. matches[teamPair[i]] = { teamPair[1-i] : 1 }
  17. def GetMatchCount(team1, opposition):
  18. try:
  19. return matches[team1][opposition]
  20. except KeyError:
  21. return 0