Advertisement
clesiomatias

Untitled

Sep 14th, 2022
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.14 KB | None | 0 0
  1. import random
  2.  
  3. import pandas as pd
  4.  
  5. '''1. Estrutura com os Grupos e Seleções, além de seus respectivos scores (Ranking FIFA)'''
  6.  
  7. df = pd.read_csv('https://raw.githubusercontent.com/digitalinnovationone/live-coding-evitando-o-7x1-com-python-e-sql/main/data.csv')
  8. df.head()
  9.  
  10.  
  11.  
  12. '''2. Classe que representa um time, com suas características e comportamentos:'''
  13. class Team:
  14.     BEST_SCORE=1837.6 #éééééé do Brasil sil sil
  15.     def __init__(self, content) :
  16.         teamData = content.split('|')
  17.         self.name = teamData[0]
  18.         self.score=float(teamData[1])    
  19.    
  20.     def motivate(self):
  21.         self.last_motivation = random.uniform (70, (self.score*100)/Team.BEST_SCORE )
  22.         return self.last_motivation
  23.  
  24.  
  25. ''' Fase 3 - Simulando a fase Grupos'''
  26. bestTeamByGroup={}
  27. for label, content in df.items():
  28.     team1 = Team(content[0])
  29.     team2 = Team(content[1])
  30.     team3 = Team(content[2])
  31.     team4 = Team(content[3])
  32.  
  33.     bestTeamByGroup[label] = sorted([team1,team2,team3,team4], key=Team.motivate, reverse=True)
  34.  
  35. for grupo, motivatedTeams in bestTeamByGroup.items():
  36.     print(f'Grupo {grupo}: ')    
  37.     for team in motivatedTeams:
  38.         print(f'Time: {team.name}, Motivação: {team.last_motivation:.2f}')
  39.     print()
  40.  
  41.  
  42. '''4. Simulando as Oitavas de Final (16 melhores seleções)'''
  43. team1A = bestTeamByGroup['A'][0]
  44. team2A = bestTeamByGroup['A'][1]
  45. team1B = bestTeamByGroup['B'][0]
  46. team2B = bestTeamByGroup['B'][1]
  47. team1C = bestTeamByGroup['C'][0]
  48. team2C = bestTeamByGroup['C'][1]
  49. team1D = bestTeamByGroup['D'][0]
  50. team2D = bestTeamByGroup['D'][1]
  51. team1E = bestTeamByGroup['E'][0]
  52. team2E = bestTeamByGroup['E'][1]
  53. team1F = bestTeamByGroup['F'][0]
  54. team2F = bestTeamByGroup['F'][1]
  55. team1G = bestTeamByGroup['G'][0]
  56. team2G = bestTeamByGroup['G'][1]
  57. team1H = bestTeamByGroup['H'][0]
  58. team2H = bestTeamByGroup['H'][1]
  59.  
  60.  
  61.  
  62. quarter1 = team1A if team1A.motivate() > team2B.motivate() else team2B
  63. quarter2 = team1C if team1C.motivate() > team2D.motivate() else team2D
  64. quarter3 = team1E if team1E.motivate() > team2F.motivate() else team2F
  65. quarter4 = team1G if team1G.motivate() > team2H.motivate() else team2H
  66. quarter5 = team1B if team1B.motivate() > team2A.motivate() else team2A
  67. quarter6 = team1D if team1D.motivate() > team2C.motivate() else team2C
  68. quarter7 = team1F if team1F.motivate() > team2E.motivate() else team2E
  69. quarter8 = team1H if team1H.motivate() > team2G.motivate() else team2G
  70. print('oitavas de final')
  71. print(f'{team1A.name} ({team1A.last_motivation:.2f}) x {team2B.name} ({team2B.last_motivation:.2f})')
  72. print(f'{team1C.name} ({team1C.last_motivation:.2f}) x {team2D.name} ({team2D.last_motivation:.2f})')
  73. print(f'{team1E.name} ({team1E.last_motivation:.2f}) x {team2F.name} ({team2F.last_motivation:.2f})')
  74. print(f'{team1G.name} ({team1G.last_motivation:.2f}) x {team2H.name} ({team2H.last_motivation:.2f})')
  75. print(f'{team1B.name} ({team1B.last_motivation:.2f}) x {team2A.name} ({team2A.last_motivation:.2f})')
  76. print(f'{team1D.name} ({team1D.last_motivation:.2f}) x {team2C.name} ({team2C.last_motivation:.2f})')
  77. print(f'{team1F.name} ({team1F.last_motivation:.2f}) x {team2E.name} ({team2E.last_motivation:.2f})')
  78. print(f'{team1H.name} ({team1H.last_motivation:.2f}) x {team2G.name} ({team2G.last_motivation:.2f})')
  79.  
  80. '''5. Simulando as Quartas de Final (8 melhores seleções)'''
  81. semi1 = quarter1 if quarter1.motivate() > quarter2.motivate() else quarter2
  82. semi2 = quarter3 if quarter3.motivate() > quarter4.motivate() else quarter4
  83. semi3 = quarter5 if quarter5.motivate() > quarter6.motivate() else quarter6
  84. semi4 = quarter7 if quarter7.motivate() > quarter8.motivate() else quarter8
  85. print()
  86. print("quartas finais")
  87. print(f'{quarter1.name} ({quarter1.last_motivation:.2f}) x {quarter2.name} ({quarter2.last_motivation:.2f})')
  88. print(f'{quarter3.name} ({quarter3.last_motivation:.2f}) x {quarter4.name} ({quarter4.last_motivation:.2f})')
  89. print(f'{quarter5.name} ({quarter5.last_motivation:.2f}) x {quarter6.name} ({quarter6.last_motivation:.2f})')
  90. print(f'{quarter7.name} ({quarter7.last_motivation:.2f}) x {quarter8.name} ({quarter8.last_motivation:.2f})')
  91.  
  92. '''6. Simulando as Semifinais (4 melhores seleções)'''
  93. final1 = semi1 if semi1.motivate() > semi2.motivate() else semi2
  94. terceiro1 = semi2 if semi1.last_motivation > semi2.last_motivation else semi1
  95. final2 = semi3 if semi3.motivate() > semi4.motivate() else semi4
  96. terceiro2 = semi4 if semi3.last_motivation > semi4.last_motivation else semi3
  97.  
  98. print()
  99. print('semi-fimais')
  100. print(f'{semi1.name} ({semi1.last_motivation:.2f}) x {semi2.name} ({semi2.last_motivation:.2f})')
  101. print(f'{semi3.name} ({semi3.last_motivation:.2f}) x {semi4.name} ({semi4.last_motivation:.2f})')
  102.  
  103. '''7. Simulando a Final (2 melhores seleções)'''
  104. winner = final1 if final1.motivate() > final2.motivate() else final2
  105. second = final1 if final1.last_motivation < final2.last_motivation else final2
  106. third = terceiro1 if terceiro1.motivate() > final2.motivate() else final2
  107. fourth = terceiro1 if terceiro1.last_motivation < final2.last_motivation else final2
  108. print()
  109. print(f'1º: {winner.name} ({winner.last_motivation:.2f})')
  110. print(f'2: {second.name} ({second.last_motivation:.2f})')
  111. print(f'3º: {third.name} ({third.last_motivation:.2f})')
  112. print(f'4º: {fourth.name} ({fourth.last_motivation:.2f})')
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement