-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventSystem.py
191 lines (166 loc) · 9.28 KB
/
EventSystem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import pandas as pd
import random
# Your File Paths
player_file_path = 'Files/Madden25/IE/Season8/Player.xlsx'
position_report_file_path = 'Files/Madden25/IE/Season8/Position_Report.xlsx'
output_file_path = 'Files/Madden25/IE/Season8/EventSystem_Results.xlsx'
# Set the season phase
season_phase = "Preseason" ### Change this to "Preseason", "TradeDeadline", or "Offseason" ###
# Read data from the specified Excel files
player_df = pd.read_excel(player_file_path)
position_report_df = pd.read_excel(position_report_file_path, sheet_name='Team Position Depth')
# Specify relevant columns from player_df
relevant_columns_player = ['FirstName', 'LastName', 'Position', 'YearsPro', 'Age', 'ConfidenceRating', 'InjuryRating', 'InjuryType', 'InjuryStatus', 'TotalInjuryDuration']
# Select only the relevant columns from player_df
player_subset_df = player_df[relevant_columns_player]
# Merge player_subset_df with position_report_df based on specified columns
merged_df = pd.merge(player_subset_df, position_report_df, on=['FirstName', 'LastName', 'Position', 'YearsPro'], how='inner')
# Function to determine WantsContractNow based on conditions
def young_newcontract(row):
multiplier = 1.0
if row['Position'] in ['WR', 'LT', 'RT', 'LE', 'RE', 'CB']:
multiplier = 1.25
elif row['Position'] == 'QB':
multiplier = 1.5
if season_phase == "Preseason" or season_phase == "Offseason":
if row['OverallRating'] >= 90 and row['YearsPro'] == 3 and row['ContractYearsLeft'] <= 2:
return 'Yes' if random.random() <= 0.25 * multiplier else 'No'
elif 85 <= row['OverallRating'] <= 89 and row['YearsPro'] == 3 and row['ContractYearsLeft'] <= 2:
return 'Yes' if random.random() <= 0.05 * multiplier else 'No'
elif 80 <= row['OverallRating'] <= 84 and row['YearsPro'] == 4 and row['ContractYearsLeft'] == 1:
return 'Yes' if random.random() <= 0.05 * multiplier else 'No'
elif 85 <= row['OverallRating'] <= 89 and row['YearsPro'] == 4 and row['ContractYearsLeft'] == 1:
return 'Yes' if random.random() <= 0.15 * multiplier else 'No'
elif row['OverallRating'] >= 90 and row['YearsPro'] == 4 and row['ContractYearsLeft'] == 1:
return 'Yes' if random.random() <= 0.30 * multiplier else 'No'
else:
return 'No'
else:
return 'No'
# Apply the function to create the WantsContractNow column
merged_df['WantsContractNow'] = merged_df.apply(young_newcontract, axis=1)
# Function to determine Holdout based on conditions
def vet_wantscontract(row):
multiplier = 1.0
if row['Position'] in ['WR', 'LT', 'RT', 'LE', 'RE', 'CB']:
multiplier = 1.5
elif row['Position'] == 'QB':
multiplier = 2.0
if season_phase == "Preseason" or season_phase == "Offseason":
if row['OverallRating'] >= 90 and row['Position'] in ['HB', 'RB'] and row['YearsPro'] >= 4 and row['ContractYearsLeft'] <= 2:
return 'Yes' if random.random() <= 0.25 * multiplier else 'No'
elif 85 <= row['OverallRating'] <= 89 and row['Position'] not in ['HB', 'RB'] and row['YearsPro'] >= 4 and row['ContractYearsLeft'] == 1:
return 'Yes' if random.random() <= 0.05 * multiplier else 'No'
elif 90 <= row['OverallRating'] <= 94 and row['Position'] not in ['HB', 'RB'] and row['YearsPro'] >= 4 and row['ContractYearsLeft'] == 1:
return 'Yes' if random.random() <= 0.15 * multiplier else 'No'
elif row['OverallRating'] >= 95 and row['Position'] not in ['HB', 'RB'] and row['YearsPro'] >= 4 and row['ContractYearsLeft'] == 1:
return 'Yes' if random.random() <= 0.25 * multiplier else 'No'
else:
return 'No'
else:
return 'No'
# Apply the function to create the HoldoutForContract column
merged_df['HoldoutForContract'] = merged_df.apply(vet_wantscontract, axis=1)
# Function to determine trade request based on conditions
def traderequest_lowmorale(row):
multiplier = 1.0
if row['ConfidenceRating'] < 20:
multiplier = 10.0
elif 20 <= row['ConfidenceRating'] < 30:
multiplier = 5.0
elif 30 <= row['ConfidenceRating'] < 40:
multiplier = 1.5
elif 40 <= row['ConfidenceRating'] < 50:
multiplier = 0.75
elif 50 <= row['ConfidenceRating'] < 60:
multiplier = 0.25
elif 60 <= row['ConfidenceRating'] < 70:
multiplier = 0.1
elif row['ConfidenceRating'] >= 70:
multiplier = 0.05
if season_phase == "Preseason" or season_phase == "TradeDeadline" or season_phase == "Offseason":
if row['OverallRating'] >= 80 and row['YearsPro'] >= 2 and row['Age'] <= 26 and row['ContractYearsLeft'] <= 3:
return 'Yes' if random.random() <= 0.025 * multiplier else 'No'
elif row['OverallRating'] >= 80 and row['YearsPro'] >= 2 and 27 <= row['Age'] >= 29 and row['ContractYearsLeft'] <= 3:
return 'Yes' if random.random() <= 0.05 * multiplier else 'No'
elif row['OverallRating'] >= 80 and row['YearsPro'] >= 2 and row['Age'] >= 30 and row['ContractYearsLeft'] <= 3:
return 'Yes' if random.random() <= 0.10 * multiplier else 'No'
else:
return 'No'
else:
return 'No'
# Apply the function to create the TradeUnhappy column
merged_df['TradeUnhappy'] = merged_df.apply(traderequest_lowmorale, axis=1)
# Function to determine trade request based on conditions
def traderequest_playingtime(row):
multiplier = 0.0
if row['Position'] in ['TE', 'LT', 'LG', 'C', 'RG', 'RT', 'LOLB', 'MLB', 'ROLB', 'FS', 'SS'] and row['Rank'] >= 2:
multiplier = 1.0
elif row['Position'] in ['RB', 'HB', 'DT', 'LE', 'RE'] and row['Rank'] >= 3:
multiplier = 1.0
elif row['Position'] in ['WR', 'CB'] and row['Rank'] >= 4:
multiplier = 1.0
if season_phase == "Preseason" or season_phase == "TradeDeadline" or season_phase == "Offseason":
if row['OverallRating'] >= 90 and row['YearsPro'] >= 2:
return 'Yes' if random.random() <= 1.0 * multiplier else 'No'
elif 80 <= row['OverallRating'] < 90 and row['YearsPro'] >= 2 and row['ContractYearsLeft'] <= 3 and row['ConfidenceRating'] <= 55:
return 'Yes' if random.random() <= 0.75 * multiplier else 'No'
elif 75 <= row['OverallRating'] < 80 and row['YearsPro'] >= 2 and row['ContractYearsLeft'] <= 3 and row['ConfidenceRating'] <= 55:
return 'Yes' if random.random() <= 0.50 * multiplier else 'No'
elif 70 <= row['OverallRating'] < 75 and row['YearsPro'] >= 2 and row['ContractYearsLeft'] <= 3 and row['ConfidenceRating'] <= 55:
return 'Yes' if random.random() <= 0.025 * multiplier else 'No'
else:
return 'No'
else:
return 'No'
# Apply the function to create the TradePlayingTime column
merged_df['TradePlayingTime'] = merged_df.apply(traderequest_playingtime, axis=1)
# Function to determine offseason injury based on conditions
def injury_offseason(row):
multiplier = 1.0
if 73 <= row['InjuryRating'] <= 74 and row['Position'] not in ['HB', 'RB']:
multiplier = 1.5
if 75 <= row['InjuryRating'] <= 77 and row['Position'] not in ['HB', 'RB']:
multiplier = 1.25
if 78 <= row['InjuryRating'] <= 80 and row['Position'] not in ['HB', 'RB']:
multiplier = 1.0
if 81 <= row['InjuryRating'] <= 83 and row['Position'] not in ['HB', 'RB']:
multiplier = 0.75
if 84 <= row['InjuryRating'] <= 85 and row['Position'] not in ['HB', 'RB']:
multiplier = 0.5
if 78 <= row['InjuryRating'] <= 79 and row['Position'] in ['HB', 'RB']:
multiplier = 1.5
if 80 <= row['InjuryRating'] <= 82 and row['Position'] in ['HB', 'RB']:
multiplier = 1.25
if 83 <= row['InjuryRating'] <= 85 and row['Position'] in ['HB', 'RB']:
multiplier = 1.0
if 86 <= row['InjuryRating'] <= 88 and row['Position'] in ['HB', 'RB']:
multiplier = 0.75
if 89 <= row['InjuryRating'] <= 90 and row['Position'] in ['HB', 'RB']:
multiplier = 0.5
if season_phase == "Preseason":
if row['InjuryStatus'] == 'Uninjured':
return 'ACL' if random.random() <= 0.001 * multiplier else 'Achilles' if random.random() <= 0.002 * multiplier else 'PartialSeasonInjury' if random.random() <= 0.002 * multiplier else 'No'
else:
return 'No'
else:
return 'No'
# Apply the function to create the OffseasonInjury column
merged_df['OffseasonInjury'] = merged_df.apply(injury_offseason, axis=1)
# Function to determine Retirement based on conditions
def vet_earlyretirement(row):
if season_phase == "Offseason":
if row['Position'] in ['QB', 'K', 'P'] and row['Age'] >= 35 and row['OverallRating'] >= 70:
return 'Yes' if random.random() <= 0.01 else 'No'
if row['Position'] in ['RB', 'HB'] and row['Age'] >= 27 and row['OverallRating'] >= 70:
return 'Yes' if random.random() <= 0.01 else 'No'
if row['Position'] not in ['QB', 'RB', 'HB', 'K', 'P'] and row['Age'] >= 30 and row['OverallRating'] >= 70:
return 'Yes' if random.random() <= 0.01 else 'No'
else:
return 'No'
else:
return 'No'
# Apply the function to create the Retire column
merged_df['Retire'] = merged_df.apply(vet_earlyretirement, axis=1)
# Save the merged dataframe to a new Excel file
merged_df.to_excel(output_file_path, index=False)