Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. async def outputResults(mentionPlayers):
  2. """Outputs the results from the race
  3.  
  4. Results format: 1. racerName racerTime racerComments
  5. racerTime can also be 'Forfeited' if the racer did not finish the race.
  6. racerTime and racerComments can be empty if the racer did not set an
  7. end status on the race. Also outputs results in the same format to a textfile
  8. in comma-delimited rows (with the comments on new lines).
  9. """
  10. racerNotFinished = {}
  11. racerForfeited = {}
  12. racerDone = {}
  13. for racer in racerDict:
  14. if racerDict[racer] is None:
  15. racerNotFinished[racer] = ''
  16. elif racerDict[racer] == 'Forfeited':
  17. racerForfeited[racer] = 'Forfeited'
  18. else:
  19. racerDone[racer] = racerDict[racer]
  20.  
  21. sortedRacerDone = sorted(racerDone.items(), key=operator.itemgetter(1))
  22.  
  23. if mentionPlayers:
  24. resultLine = '{}{}. <@{}> {} {}\n'
  25. else:
  26. resultLine = '{}{}. {} {} {}\n'
  27. fileLine = '{}{}.|{}|{}\n{}\n'
  28.  
  29. resultsString = ''
  30. fileString = ''
  31. count = 1
  32. for racer in sortedRacerDone:
  33. if mentionPlayers:
  34. resultsString = resultLine.format(resultsString, count, racer[0].id,
  35. roundTime(racer[1]), racerComments[racer[0]])
  36. else:
  37. resultsString = resultLine.format(resultsString, count, trimMemberName('{}'.format(racer[0])),
  38. roundTime(racer[1]), racerComments[racer[0]])
  39. fileString = fileLine.format(fileString, count, trimMemberName('{}'.format(racer[0])),
  40. roundTime(racer[1]), racerComments[racer[0]])
  41. count += 1
  42. for racer in racerForfeited:
  43. if mentionPlayers:
  44. resultsString = resultLine.format(resultsString, count, racer.id, 'Forfeited', racerComments[racer])
  45. else:
  46. resultsString = resultLine.format(resultsString, count,
  47. trimMemberName('{}'.format(racer)), 'Forfeited', racerComments[racer])
  48. fileString = fileLine.format(fileString, count,
  49. trimMemberName('{}'.format(racer)), 'Forfeited', racerComments[racer])
  50. count += 1
  51. for racer in racerNotFinished:
  52. if mentionPlayers:
  53. resultsString = '{}{}. <@{}>\n'.format(resultsString, count, racer.id)
  54. else:
  55. resultsString = '{}{}. {}\n'.format(resultsString, count, trimMemberName('{}'.format(racer)))
  56. fileString = '{}{}.|{}\n'.format(fileString, count, trimMemberName('{}'.format(racer)))
  57. count += 1
  58.  
  59. if resultsString:
  60. await bot.say('Race game: {}'.format(raceGame))
  61. await bot.say('Race goal: {}'.format(raceGoal))
  62. await bot.say('Race results:')
  63. await bot.say(resultsString)
  64. if fileString:
  65. raceFile = open(raceFileName, 'w+')
  66. raceFile.write(fileString)
  67. raceFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement