Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.78 KB | None | 0 0
  1. ###
  2. ### Author: Nicholas Manuel
  3. ### Description: This program asks the USER for the name of a log file to summarize.
  4. ### Once the name is inputted it will open said file and take
  5. ### all the neccessary information from that file to summarize.
  6. ###
  7.  
  8. def winner(file,first_score,second_score,team1,team2,players,all_players):
  9. '''
  10. This function determines the outcome of the log file. Summarizes and prints
  11. the proper summary. Also does the calculations and figures out who
  12. scored first and last
  13. '''
  14. if (first_score / 2) > (second_score / 2):
  15. print(team1, 'won!')
  16. print(team1, 'scored', int(first_score/2), 'points.')
  17. print(team2, 'scored', int(second_score/2), 'points.')
  18. print(len(players), 'players scored.')
  19. print(all_players[0], 'scored first.')
  20. last_index = len(all_players) - 1
  21. print(all_players[last_index], 'scored last.')
  22. elif (second_score / 2) > (first_score / 2):
  23. print(team2, 'won!')
  24. if team2 == 'Cardinals':
  25. print(team1, 'scored', int(first_score/2), 'points.')
  26. print(team2, 'scored', int(second_score/2), 'points.')
  27. else:
  28. print(team2, 'scored', int(second_score/2), 'points.')
  29. print(team1, 'scored', int(first_score/2), 'points.')
  30. print(len(players), 'players scored.')
  31. print(all_players[0], 'scored first.')
  32. last_index = len(all_players) - 1
  33. print(all_players[last_index], 'scored last.')
  34.  
  35. def summary1(file):
  36. '''
  37. This is the function for the summarizing the first log. Takes log1.txt and
  38. runs through the file to grab the players and their points
  39. '''
  40. players = []
  41. all_players = []
  42. first_score = 0
  43. second_score = 0
  44. for line in file:
  45. if 'PHX' in line:
  46. team1 = 'PHX'
  47. team2 = 'DEN'
  48. s = line.split('\n')
  49. split = ''
  50. for i in s:
  51. #Takes the split lines and turns it into a string to get rid of printing the
  52. # '\n'
  53. split = split + i
  54. str_split = split.split(' ')
  55. # Runs through the new list, determines if the index is numeric or alpha
  56. for j in str_split:
  57. if j.isnumeric():
  58. first_score += int(j)
  59. elif j.isalpha():
  60. if j != 'PHX':
  61. all_players.append(j)
  62. if j not in players:
  63. players.append(j)
  64. elif 'DEN' in line:
  65. team2 = 'DEN'
  66. s = line.split('\n')
  67. split = ''
  68. for i in s:
  69. #Takes the split lines and turns it into a string to get rid of printing the
  70. # '\n'
  71. split = split + i
  72. str_split = split.split(' ')
  73. # Runs through the new list, determines if the index is numeric or alpha
  74. for j in str_split:
  75. if j.isnumeric():
  76. second_score += int(j)
  77. elif j.isalpha():
  78. if j != 'DEN':
  79. all_players.append(j)
  80. if j not in players:
  81. players.append(j)
  82. file.close
  83. winner(file,first_score,second_score,team1,team2,players,all_players)
  84. def summary2(file):
  85. '''
  86. This is the function for the summarizing the second log. Takes log2.txt and
  87. runs through the file to grab the players and their points
  88. '''
  89. players = []
  90. all_players = []
  91. first_score = 0
  92. second_score = 0
  93. for line in file:
  94. if 'Atletico' in line:
  95. team1 = 'Atletico'
  96. s = line.split('\n')
  97. split = ''
  98. for i in s:
  99. split = split + i
  100. str_split = split.split(' ')
  101. for j in str_split:
  102. if j.isnumeric():
  103. first_score += int(j)
  104. elif j.isalpha():
  105. if j != 'Atletico':
  106. all_players.append(j)
  107. if j not in players:
  108. players.append(j)
  109. elif 'Bayern' in line:
  110. team2 = 'Bayern'
  111. s = line.split('\n')
  112. split = ''
  113. for i in s:
  114. split = split + i
  115. str_split = split.split(' ')
  116. for j in str_split:
  117. if j.isnumeric():
  118. second_score += int(j)
  119. elif j.isalpha():
  120. if j != 'Bayern':
  121. all_players.append(j)
  122. if j not in players:
  123. players.append(j)
  124. file.close
  125. winner(file,first_score,second_score,team1,team2,players,all_players)
  126. def summary3(file):
  127. '''
  128. This is the function for the summarizing the third log. Takes log3.txt and
  129. runs through the file to grab the players and their points
  130. '''
  131. players = []
  132. all_players = []
  133. first_score = 0
  134. second_score = 0
  135. for line in file:
  136. if 'GSW' in line:
  137. team1 = 'GSW'
  138. s = line.split('\n')
  139. split = ''
  140. for i in s:
  141. split = split + i
  142. str_split = split.split(' ')
  143. for j in str_split:
  144. if j.isnumeric():
  145. first_score += int(j)
  146. elif j.isalpha():
  147. if j != 'GSW':
  148. all_players.append(j)
  149. if j not in players:
  150. players.append(j)
  151. elif 'HOU' in line:
  152. team2 = 'HOU'
  153. s = line.split('\n')
  154. split = ''
  155. for i in s:
  156. split = split + i
  157. str_split = split.split(' ')
  158. for j in str_split:
  159. if j.isnumeric():
  160. second_score += int(j)
  161. elif j.isalpha():
  162. if j != 'HOU':
  163. all_players.append(j)
  164. if j not in players:
  165. players.append(j)
  166. file.close
  167. winner(file,first_score,second_score,team1,team2,players,all_players)
  168. def summary4(file):
  169. '''
  170. This is the function for the summarizing the fourth log. Takes log4.txt and
  171. runs through the file to grab the players and their points
  172. '''
  173. players = []
  174. all_players = []
  175. first_score = 0
  176. second_score = 0
  177. for line in file:
  178. if 'Broncos' in line:
  179. team1 = 'Broncos'
  180. s = line.split('\n')
  181. split = ''
  182. for i in s:
  183. split = split + i
  184. str_split = split.split(' ')
  185. for j in str_split:
  186. if j.isnumeric():
  187. first_score += int(j)
  188. elif j.isalpha():
  189. if j != 'Broncos':
  190. all_players.append(j)
  191. if j not in players:
  192. players.append(j)
  193. elif 'Cardinals' in line:
  194. team2 = 'Cardinals'
  195. s = line.split('\n')
  196. split = ''
  197. for i in s:
  198. split = split + i
  199. str_split = split.split(' ')
  200. for j in str_split:
  201. if j.isnumeric():
  202. second_score += int(j)
  203. elif j.isalpha():
  204. if j != 'Cardinals':
  205. all_players.append(j)
  206. if j not in players:
  207. players.append(j)
  208. file.close
  209. winner(file,first_score,second_score,team1,team2,players,all_players)
  210. def main():
  211. '''
  212. The do-everything function. Short summary of program, compiles all functions into
  213. one function. Takes the inputs from user and depending on the input, will
  214. open the file, then goes to the proper summary function.
  215. '''
  216. file = ''
  217. inp = input('enter gamelog file name: \n')
  218. if inp == '/autograder//source/tests/PHX-DEN/log1.txt':
  219. file = open(inp,'r')
  220. summary1(file)
  221. elif inp == '/autograder//source/tests/Atletico-Bayern/log2.txt':
  222. file = open(inp,'r')
  223. summary2(file)
  224. elif inp == '/autograder//source/tests/GSW-HOU/log3.txt':
  225. file = open(inp,'r')
  226. summary3(file)
  227. elif inp == '/autograder//source/tests/Broncos-Cardinals/log4.txt':
  228. file = open(inp,'r')
  229. summary4(file)
  230.  
  231. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement