SHARE
TWEET

Fifa Program

a guest Feb 16th, 2020 260 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def Calculate(year1, year2, allData, response):
  2.     # Main logic
  3.     Increased = 0
  4.     Decreased = 0
  5.     KeptSame  = 0
  6.     TotalPlayers  = 0
  7.     for data in allData.iterrows():
  8.         TotalPlayers = TotalPlayers + 1
  9.         # Read columns per player
  10.         playerId = data[1][0]
  11.  
  12.         if(year1 == 2015):
  13.             playerYear1Overall = data[1][1]
  14.         if(year1 == 2016):
  15.             playerYear1Overall = data[1][2]
  16.         if(year1 == 2017):
  17.             playerYear1Overall = data[1][3]
  18.         if(year1 == 2018):
  19.             playerYear1Overall = data[1][4]
  20.         if(year1 == 2019):
  21.             playerYear1Overall = data[1][5]
  22.  
  23.         if(year2 == 2016):
  24.             playerYear2Overall = data[1][2]
  25.         if(year2 == 2017):
  26.             playerYear2Overall = data[1][3]
  27.         if(year2 == 2018):
  28.             playerYear2Overall = data[1][4]
  29.         if(year2 == 2019):
  30.             playerYear2Overall = data[1][5]
  31.         if(year2 == 2020):
  32.             playerYear2Overall = data[1][6]
  33.  
  34.         if math.isnan(playerYear1Overall):
  35.             playerYear1Overall = 0
  36.  
  37.         if math.isnan(playerYear2Overall):
  38.             playerYear2Overall = 0
  39.            
  40.         # Calculate counts
  41.         diff = playerYear2Overall - playerYear1Overall
  42.  
  43.        
  44.         if int(diff) > 0:
  45.             Increased = Increased + 1
  46.         if diff < 0:
  47.             Decreased = Decreased + 1
  48.         if diff == 0:
  49.             KeptSame = KeptSame + 1
  50.  
  51.  
  52.     # Calculate percentages
  53.     PercentageIncreased = Increased / float(TotalPlayers) * 100
  54.     PercentageDecreased = Decreased / float(TotalPlayers) * 100
  55.     PercentageKeptSame  = KeptSame / float(TotalPlayers) * 100
  56.  
  57.     # Create dictionary for year data
  58.     yearData = {}
  59.     yearData['Increased'] = PercentageIncreased
  60.     yearData['Decreased'] = PercentageDecreased
  61.     yearData['KeptSame']  = PercentageKeptSame
  62.  
  63.     # Prepare response of the function
  64.     response[year2] = yearData
  65.  
  66. responseData = {}
  67.  
  68. # Call each year combination
  69. Calculate(2015, 2016, merge5, responseData)
  70.  
  71. Calculate(2016, 2017, merge5, responseData)
  72.  
  73. Calculate(2017, 2018, merge5, responseData)
  74.  
  75. Calculate(2018, 2019, merge5, responseData)
  76.  
  77. Calculate(2019, 2020, merge5, responseData)
  78.  
  79. # Initialize variables
  80. totalIncreased = 0
  81. totalDecreased = 0
  82. totalKeptSame  = 0
  83.  
  84. # Extract data from response dictionary
  85. for year in responseData.keys():
  86.     totalIncreased = totalIncreased + responseData[year]['Increased']
  87.     totalDecreased = totalDecreased + responseData[year]['Decreased']
  88.     totalKeptSame = totalKeptSame + responseData[year]['KeptSame']
  89.  
  90. # Initialize variables
  91. averageIncreased = 0
  92. averageDecreased = 0
  93. averageKeptSame  = 0
  94.  
  95. # Calculate averages
  96. averageIncreased = totalIncreased / float(5)
  97. averageDecreased = totalDecreased / float(5)
  98. averageKeptSame  = totalKeptSame / float(5)
  99.  
  100. print "Increased: " + str(averageIncreased)
  101. print "Decreased: " + str(averageDecreased)
  102. print "Kept Same: " + str(averageKeptSame)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top