-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
230 lines (198 loc) · 9.1 KB
/
app.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import pickle as pkl
from flask import Flask, render_template, request, url_for, redirect
import numpy as np
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict_score', methods=['GET', 'POST'])
def predict_score():
return render_template('predict_score.html')
@app.route('/score', methods=['GET', 'POST'])
def score():
temp_array = list()
if request.method == 'POST':
batting_team = request.form['batting-team']
if batting_team == 'Chennai Super Kings':
temp_array = temp_array + [1, 0, 0, 0, 0, 0, 0, 0]
elif batting_team == 'Delhi Capitals':
temp_array = temp_array + [0, 1, 0, 0, 0, 0, 0, 0]
elif batting_team == 'Kings XI Punjab':
temp_array = temp_array + [0, 0, 1, 0, 0, 0, 0, 0]
elif batting_team == 'Kolkata Knight Riders':
temp_array = temp_array + [0, 0, 0, 1, 0, 0, 0, 0]
elif batting_team == 'Mumbai Indians':
temp_array = temp_array + [0, 0, 0, 0, 1, 0, 0, 0]
elif batting_team == 'Rajasthan Royals':
temp_array = temp_array + [0, 0, 0, 0, 0, 1, 0, 0]
elif batting_team == 'Royal Challengers Bangalore':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 1, 0]
elif batting_team == 'Sunrisers Hyderabad':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 1]
bowling_team = request.form['bowling-team']
if bowling_team == 'Chennai Super Kings':
temp_array = temp_array + [1, 0, 0, 0, 0, 0, 0, 0]
elif bowling_team == 'Delhi Capitals':
temp_array = temp_array + [0, 1, 0, 0, 0, 0, 0, 0]
elif bowling_team == 'Kings XI Punjab':
temp_array = temp_array + [0, 0, 1, 0, 0, 0, 0, 0]
elif bowling_team == 'Kolkata Knight Riders':
temp_array = temp_array + [0, 0, 0, 1, 0, 0, 0, 0]
elif bowling_team == 'Mumbai Indians':
temp_array = temp_array + [0, 0, 0, 0, 1, 0, 0, 0]
elif bowling_team == 'Rajasthan Royals':
temp_array = temp_array + [0, 0, 0, 0, 0, 1, 0, 0]
elif bowling_team == 'Royal Challengers Bangalore':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 1, 0]
elif bowling_team == 'Sunrisers Hyderabad':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 1]
x = request.form['venue']
if x == 'M Chinnaswamy Stadium':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Punjab Cricket Association Stadium, Mohali':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
elif x == 'Feroz Shah Kotla':
temp_array = temp_array + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Wankhede Stadium':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
elif x == 'Sawai Mansingh Stadium':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
elif x == 'MA Chidambaram Stadium, Chepauk':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Eden Gardens':
temp_array = temp_array + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Dr DY Patil Sports Academy':
temp_array = temp_array + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Brabourne Stadium':
temp_array = temp_array + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Sardar Patel Stadium, Motera':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
elif x == 'Himachal Pradesh Cricket Association Stadium':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Subrata Roy Sahara Stadium':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
elif x == 'Rajiv Gandhi International Stadium, Uppal':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
elif x == 'Shaheed Veer Narayan Singh International Stadium':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
elif x == 'JSCA International Stadium Complex':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Maharashtra Cricket Association Stadium':
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Dr. Y.S. Rajasekhara Reddy ACA-VDCA Cricket Stadium':
temp_array = temp_array + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif x == 'Barabati Stadium':
temp_array = temp_array + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
else:
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
runs = int(request.form['runs'])
wickets = int(request.form['wickets'])
overs = float(request.form['overs'])
runs_last_5 = int(request.form['runs_last_5'])
wickets_last_5 = int(request.form['wickets_last_5'])
temp_array = temp_array + [runs, wickets, overs, runs_last_5, wickets_last_5]
data = np.array([temp_array]).reshape(1, -1)
with open('score.pkl', 'rb') as f:
regressor = pkl.load(f)
if batting_team == bowling_team or runs < runs_last_5 or wickets < wickets_last_5 or wickets > 10 or overs < 5.0:
return redirect(url_for('predict_score'))
else:
my_prediction = int(regressor.predict(data)[0])
return render_template('score.html', lower_limit=my_prediction - 10, upper_limit=my_prediction + 5)
@app.route('/predict_winner', methods=['GET', 'POST'])
def predict_winner():
return render_template('predict_winner.html')
@app.route('/winner', methods=['GET', 'POST'])
def winner():
temp = [0, 0, 0, 0, 0]
team1 = str(request.args.get('list1'))
if team1 == 'Royal Challengers Bangalore':
temp[0] = 0
elif team1 == 'Kings XI Punjab':
temp[0] = 1
elif team1 == 'Delhi Capitals':
temp[0] = 2
elif team1 == 'Mumbai Indians':
temp[0] = 3
elif team1 == 'Rajasthan Royals':
temp[0] = 4
elif team1 == 'Chennai Super Kings':
temp[0] = 5
elif team1 == 'Kolkata Knight Riders':
temp[0] = 6
else:
temp[0] = 7
team2 = str(request.args.get('list2'))
if team2 == 'Royal Challengers Bangalore':
temp[1] = 0
elif team2 == 'Kings XI Punjab':
temp[1] = 1
elif team2 == 'Delhi Capitals':
temp[1] = 2
elif team2 == 'Mumbai Indians':
temp[1] = 3
elif team2 == 'Rajasthan Royals':
temp[1] = 4
elif team2 == 'Chennai Super Kings':
temp[1] = 5
elif team2 == 'Kolkata Knight Riders':
temp[1] = 6
else:
temp[1] = 7
x = str(request.args.get('list3'))
if x == 'M Chinnaswamy Stadium':
temp[2] = 1
elif x == 'Punjab Cricket Association Stadium, Mohali':
temp[2] = 2
elif x == 'Feroz Shah Kotla':
temp[2] = 3
elif x == 'Wankhede Stadium':
temp[2] = 4
elif x == 'Sawai Mansingh Stadium':
temp[2] = 5
elif x == 'MA Chidambaram Stadium, Chepauk':
temp[2] = 6
elif x == 'Eden Gardens':
temp[2] = 7
elif x == 'Dr DY Patil Sports Academy':
temp[2] = 8
elif x == 'Brabourne Stadium':
temp[2] = 9
elif x == 'Sardar Patel Stadium, Motera':
temp[2] = 10
elif x == 'Himachal Pradesh Cricket Association Stadium':
temp[2] = 11
elif x == 'Subrata Roy Sahara Stadium':
temp[2] = 12
elif x == 'Rajiv Gandhi International Stadium, Uppal':
temp[2] = 13
elif x == 'Shaheed Veer Narayan Singh International Stadium':
temp[2] = 14
elif x == 'JSCA International Stadium Complex':
temp[2] = 15
elif x == 'Maharashtra Cricket Association Stadium':
temp[2] = 16
elif x == 'Dr. Y.S. Rajasekhara Reddy ACA-VDCA Cricket Stadium':
temp[2] = 17
elif x == 'Barabati Stadium':
temp[2] = 18
else:
temp[2] = 19
toss_win = int(request.args.get('toss_winner'))
temp[3] = toss_win
choose = int(request.args.get('fb'))
temp[4] = choose
with open('winner.pkl', 'rb') as f:
model = pkl.load(f)
lst = np.array(temp).reshape(1, -1)
prediction = model.predict(lst)
if prediction == 0:
team_win = team1
else:
team_win = team2
if team1 == team2:
return redirect(url_for('predict_winner'))
else:
return render_template('winner.html', data=team_win)
if __name__ == "__main__":
app.run(debug=True,use_reloader=False)