jarajpu commited on
Commit
18f3eba
·
1 Parent(s): 9599300

Added user guide

Browse files
Files changed (6) hide show
  1. app.py +103 -20
  2. ipl_image.png +0 -0
  3. match_outcomes.json +3 -0
  4. matches.json +1 -1
  5. players.json +273 -0
  6. predictions.csv +5 -1
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import json
2
  from datetime import datetime, timedelta
3
 
@@ -10,6 +11,7 @@ predictions_csv = 'predictions.csv'
10
  users_json = 'users.json'
11
  matches_json = 'matches.json'
12
  outcomes_json = 'match_outcomes.json'
 
13
 
14
 
15
  # Initialize CSV and JSON files if they don't exist
@@ -49,6 +51,17 @@ def load_match_outcomes():
49
  return []
50
 
51
 
 
 
 
 
 
 
 
 
 
 
 
52
  # Get today's date in IST to load today's match
53
  def get_current_date_ist():
54
  tz_IST = pytz.timezone('Asia/Kolkata')
@@ -156,11 +169,56 @@ def calculate_max_bid_points(user_name):
156
 
157
 
158
  # Streamlit UI
159
- st.title("DIS IPL Match Predictions")
160
- st.write("Predict, Compete, and Win 🏏 - Where Every Guess Counts! 🏆")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  # Prediction form
163
- with st.expander("Submit Prediction"):
164
 
165
  # User selection
166
  user_name = st.selectbox("Select User", ["Select a user..."] + get_users())
@@ -185,7 +243,15 @@ with st.expander("Submit Prediction"):
185
 
186
  # Predictions
187
  predicted_winner = st.selectbox("Predicted Winner", teams)
188
- predicted_motm = st.text_input("Predicted Man of the Match")
 
 
 
 
 
 
 
 
189
  bid_points = st.number_input("Bid Points", min_value=1, value=100, format="%d")
190
 
191
  # Submit button
@@ -195,7 +261,7 @@ with st.expander("Submit Prediction"):
195
 
196
 
197
  # Show predictions
198
- with st.expander("Predictions"):
199
 
200
  # Display predictions
201
  if st.button("Show Predictions"):
@@ -207,7 +273,7 @@ with st.expander("Predictions"):
207
 
208
 
209
  # Show leaderboard
210
- with st.expander("Leaderboard"):
211
 
212
  # Display leaderboard
213
  if st.button("Show Leaderboard"):
@@ -231,8 +297,7 @@ with st.expander("Leaderboard"):
231
  st.write("Leaderboard data not available.")
232
 
233
 
234
-
235
-
236
  ADMIN_PASSPHRASE = "admin123"
237
 
238
 
@@ -304,19 +369,37 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match):
304
  save_users(users)
305
 
306
 
307
- with st.sidebar.expander("Admin Panel", expanded=False):
308
- admin_pass = st.text_input("Enter admin passphrase:", type="password")
 
309
 
310
  if admin_pass == ADMIN_PASSPHRASE:
311
- st.success("Authenticated")
312
- matches = get_today_matches() # this function gets matches for today
313
-
314
- match_id_selection = st.selectbox("Select Match ID", [match['match_id'] for match in matches])
315
- winning_team = st.text_input("Winning Team")
316
- man_of_the_match = st.text_input("Man of the Match")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
 
318
- if st.button("Submit Match Outcome"):
319
- update_leaderboard_and_outcomes(match_id_selection, winning_team, man_of_the_match)
320
- st.success("Match outcome submitted and leaderboard updated!")
 
 
321
  else:
322
- st.error("Not authenticated")
 
 
1
+ import base64
2
  import json
3
  from datetime import datetime, timedelta
4
 
 
11
  users_json = 'users.json'
12
  matches_json = 'matches.json'
13
  outcomes_json = 'match_outcomes.json'
14
+ image_path = 'ipl_image.png'
15
 
16
 
17
  # Initialize CSV and JSON files if they don't exist
 
51
  return []
52
 
53
 
54
+ # Load the player list from the JSON file
55
+ def load_player_list():
56
+ with open('players.json', 'r') as file:
57
+ return json.load(file)
58
+
59
+
60
+ def get_base64_of_image(path):
61
+ with open(path, "rb") as image_file:
62
+ return base64.b64encode(image_file.read()).decode()
63
+
64
+
65
  # Get today's date in IST to load today's match
66
  def get_current_date_ist():
67
  tz_IST = pytz.timezone('Asia/Kolkata')
 
169
 
170
 
171
  # Streamlit UI
172
+ encoded_image = get_base64_of_image(image_path)
173
+ custom_css = f"""
174
+ <style>
175
+ .header {{
176
+ font-size: 50px;
177
+ color: #FFD700; /* Gold */
178
+ text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; /* Black text shadow */
179
+ text-align: center;
180
+ padding: 10px;
181
+ background-image: url('data:image/png;base64,{encoded_image}');
182
+ background-size: cover;
183
+ }}
184
+ </style>
185
+ """
186
+ # Apply custom CSS
187
+ st.markdown(custom_css, unsafe_allow_html=True)
188
+ # Use the custom class in a div with your title
189
+ st.markdown('<div class="header">DIS IPL Match Predictions</div>', unsafe_allow_html=True)
190
+
191
+ st.write("🏆 Predict, Compete, and Win 🏏 - Where Every Guess Counts! 🏆")
192
+
193
+ user_guide_content = """
194
+ ### 📘 User Guide
195
+
196
+ #### Submitting Predictions
197
+ - **Match Selection**: Choose the match you want to predict from today's available matches.
198
+ - **Team and Player Prediction**: Select the team you predict will win and the "Man of the Match".
199
+ - **Bid Points**: Enter the number of points you wish to bid on your prediction. Remember, the maximum you can bid is capped at 20% of your total points.
200
+
201
+ #### Scoring System
202
+ - **Winning Team Prediction**: Correct predictions earn you 1000 points, while incorrect predictions deduct 200 points.
203
+ - **Man of the Match Prediction**: Correctly predicting the "Man of the Match" awards you 200 points. No penalty for incorrect guesses.
204
+ - **Bonus Points**: An additional 200 points bonus is awarded for getting both the team and "Man of the Match" predictions right.
205
+
206
+ #### Bid Point Constraints
207
+ - You cannot bid more than 20% of your current total points.
208
+ - Bid points will be doubled if your prediction is correct, and deducted if incorrect.
209
+
210
+ #### Rules for Submission
211
+ - Predictions must be submitted before the match starts.
212
+ - Only one prediction per match is allowed.
213
+ - Review your prediction carefully before submission, as it cannot be changed once submitted.
214
+ """
215
+
216
+ # User Guide as an expander
217
+ with st.expander("User Guide 📘"):
218
+ st.markdown(user_guide_content)
219
 
220
  # Prediction form
221
+ with st.expander("Submit Prediction 📝"):
222
 
223
  # User selection
224
  user_name = st.selectbox("Select User", ["Select a user..."] + get_users())
 
243
 
244
  # Predictions
245
  predicted_winner = st.selectbox("Predicted Winner", teams)
246
+
247
+ # Load the player list and populate the dropdown based on the selected team
248
+ predicted_motm = ""
249
+ player_list = load_player_list()
250
+ if predicted_winner in player_list:
251
+ players = player_list[predicted_winner]
252
+ predicted_motm = st.selectbox("Predicted Man of the Match", players)
253
+ # predicted_motm = st.text_input("Predicted Man of the Match")
254
+
255
  bid_points = st.number_input("Bid Points", min_value=1, value=100, format="%d")
256
 
257
  # Submit button
 
261
 
262
 
263
  # Show predictions
264
+ with st.expander("Predictions 🔍"):
265
 
266
  # Display predictions
267
  if st.button("Show Predictions"):
 
273
 
274
 
275
  # Show leaderboard
276
+ with st.expander("Leaderboard 🏆"):
277
 
278
  # Display leaderboard
279
  if st.button("Show Leaderboard"):
 
297
  st.write("Leaderboard data not available.")
298
 
299
 
300
+ ############################# Admin Panel ##################################
 
301
  ADMIN_PASSPHRASE = "admin123"
302
 
303
 
 
369
  save_users(users)
370
 
371
 
372
+ with st.sidebar:
373
+ expander = st.expander("Admin Panel", expanded=False)
374
+ admin_pass = expander.text_input("Enter admin passphrase:", type="password", key="admin_pass")
375
 
376
  if admin_pass == ADMIN_PASSPHRASE:
377
+ expander.success("Authenticated")
378
+ matches = get_today_matches() # This function fetches today's matches
379
+
380
+ # If matches are available, let the admin select one
381
+ if matches:
382
+ match_selection = expander.selectbox("Select Match", matches, format_func=lambda match: f"{match['teams'][0]} vs {match['teams'][1]}", key="match_selection")
383
+ selected_match_id = match_selection['match_id']
384
+ teams = match_selection['teams']
385
+
386
+ # Let admin select the winning team
387
+ winning_team = expander.selectbox("Winning Team", teams, key="winning_team")
388
+
389
+ # Fetch and display players for the selected winning team
390
+ player_list = load_player_list()
391
+ if winning_team in player_list:
392
+ players = player_list[winning_team]
393
+ man_of_the_match = expander.selectbox("Man of the Match", players, key="man_of_the_match")
394
+ else:
395
+ players = []
396
+ man_of_the_match = expander.text_input("Man of the Match (Type if not listed)", key="man_of_the_match_fallback")
397
 
398
+ if expander.button("Submit Match Outcome", key="submit_outcome"):
399
+ update_leaderboard_and_outcomes(selected_match_id, winning_team, man_of_the_match)
400
+ expander.success("Match outcome submitted and leaderboard updated!")
401
+ else:
402
+ expander.write("No matches are available for today.")
403
  else:
404
+ if admin_pass: # Show error only if something was typed
405
+ expander.error("Not authenticated")
ipl_image.png ADDED
match_outcomes.json CHANGED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [
2
+
3
+ ]
matches.json CHANGED
@@ -2,7 +2,7 @@
2
  {
3
  "match_id": "20240322_2",
4
  "date": "2024-03-22",
5
- "time": "7:30 PM",
6
  "teams": ["CSK", "RCB"],
7
  "venue": "Chennai"
8
  },
 
2
  {
3
  "match_id": "20240322_2",
4
  "date": "2024-03-22",
5
+ "time": "10:30 PM",
6
  "teams": ["CSK", "RCB"],
7
  "venue": "Chennai"
8
  },
players.json ADDED
@@ -0,0 +1,273 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "CSK": [
3
+ "MS Dhoni",
4
+ "Devon Conway",
5
+ "Ruturaj Gaikwad",
6
+ "Ajinkya Rahane",
7
+ "Shaik Rasheed",
8
+ "Ravindra Jadeja",
9
+ "Mitchell Santner",
10
+ "Moeen Ali",
11
+ "Shivam Dube",
12
+ "Nishant Sindhu",
13
+ "Ajay Mandal",
14
+ "Rajvardhan Hangargekar",
15
+ "Deepak Chahar",
16
+ "Maheesh Theekshana",
17
+ "Mukesh Chowdhary",
18
+ "Prashant Solanki",
19
+ "Simarjeet Singh",
20
+ "Tushar Deshpande",
21
+ "Matheesha Pathirana",
22
+ "Rachin Ravindra",
23
+ "Shardul Thakur",
24
+ "Daryl Mitchell",
25
+ "Sameer Rizvi",
26
+ "Mustafizur Rahman",
27
+ "Avanish Rao Aravelly"
28
+ ],
29
+ "DC": [
30
+ "Rishabh Pant",
31
+ "David Warner",
32
+ "Prithvi Shaw",
33
+ "Yash Dhull",
34
+ "Abishek Porel",
35
+ "Axar Patel",
36
+ "Lalit Yadav",
37
+ "Mitchell Marsh",
38
+ "Pravin Dubey",
39
+ "Vicky Ostwal",
40
+ "Anrich Nortje",
41
+ "Kuldeep Yadav",
42
+ "Lungi Ngidi",
43
+ "Khaleel Ahmed",
44
+ "Ishant Sharma",
45
+ "Mukesh Kumar",
46
+ "Harry Brook",
47
+ "Tristan Stubbs",
48
+ "Ricky Bhui",
49
+ "Kumar Kushagra",
50
+ "Rasikh Dar",
51
+ "Jhye Richardson",
52
+ "Sumit Kumar",
53
+ "Shai Hope",
54
+ "Swastik Chhikara",
55
+ "Jake Fraser-McGurk"
56
+ ],
57
+ "GT": [
58
+ "David Miller",
59
+ "Shubman Gill",
60
+ "Matthew Wade",
61
+ "Wriddhiman Saha",
62
+ "Kane Williamson",
63
+ "Abhinav Manohar",
64
+ "B Sai Sudharsan",
65
+ "Darshan Nalkande",
66
+ "Vijay Shankar",
67
+ "Jayant Yadav",
68
+ "Rahul Tewatia",
69
+ "Mohammed Shami",
70
+ "Noor Ahmad",
71
+ "R Sai Kishore",
72
+ "Rashid Khan",
73
+ "Josh Little",
74
+ "Mohit Sharma",
75
+ "Azmatullah Omarzai",
76
+ "Umesh Yadav",
77
+ "Shahrukh Khan",
78
+ "Sushant Mishra",
79
+ "Kartik Tyagi",
80
+ "Manav Suthar",
81
+ "Spencer Johnson",
82
+ "Robin Minz"
83
+ ],
84
+ "KKR": [
85
+ "Nitish Rana",
86
+ "Rinku Singh",
87
+ "Rahmanullah Gurbaz",
88
+ "Shreyas Iyer",
89
+ "Jason Roy",
90
+ "Anukul Roy",
91
+ "Andre Russell",
92
+ "Venkatesh Iyer",
93
+ "Suyash Sharma",
94
+ "Harshit Rana",
95
+ "Sunil Narine",
96
+ "Vaibhav Arora",
97
+ "Varun Chakravarthy",
98
+ "KS Bharat",
99
+ "Chetan Sakariya",
100
+ "Mitchell Starc",
101
+ "Angkrish Raghuvanshi",
102
+ "Ramandeep Singh",
103
+ "Sherfane Rutherford",
104
+ "Manish Pandey",
105
+ "Mujeeb Ur Rahman",
106
+ "Gus Atkinson",
107
+ "Sakib Hussain",
108
+ "Dushmantha Chameera",
109
+ "Phil Salt"
110
+ ],
111
+ "LSG": [
112
+ "KL Rahul",
113
+ "Quinton de Kock",
114
+ "Nicholas Pooran",
115
+ "Ayush Badoni",
116
+ "Deepak Hooda",
117
+ "K Gowtham",
118
+ "Krunal Pandya",
119
+ "Kyle Mayers",
120
+ "Marcus Stoinis",
121
+ "Prerak Mankad",
122
+ "Yudhvir Singh",
123
+ "Mark Wood",
124
+ "Mayank Yadav",
125
+ "Mohsin Khan",
126
+ "Ravi Bishnoi",
127
+ "Yash Thakur",
128
+ "Amit Mishra",
129
+ "Naveen-ul-Haq",
130
+ "Devdutt Padikkal",
131
+ "Shivam Mavi",
132
+ "Arshin Kulkarni",
133
+ "M. Siddharth",
134
+ "Ashton Turner",
135
+ "David Willey",
136
+ "Arshad Khan"
137
+ ],
138
+ "MI": [
139
+ "Rohit Sharma",
140
+ "Dewald Brevis",
141
+ "Suryakumar Yadav",
142
+ "Ishan Kishan",
143
+ "Tilak Varma",
144
+ "Tim David",
145
+ "Vishnu Vinod",
146
+ "Arjun Tendulkar",
147
+ "Shams Mulani",
148
+ "Nehal Wadhera",
149
+ "Jasprit Bumrah",
150
+ "Kumar Kartikeya",
151
+ "Piyush Chawla",
152
+ "Akash Madhwal",
153
+ "Jason Behrendorff",
154
+ "Romario Shepherd",
155
+ "Hardik Pandya",
156
+ "Gerald Coetzee",
157
+ "Dilshan Madushanka",
158
+ "Shreyas Gopal",
159
+ "Nuwan Thushara",
160
+ "Naman Dhir",
161
+ "Anshul Kamboj",
162
+ "Mohammad Nabi",
163
+ "Shivalik Sharma",
164
+ "Luke Wood"
165
+ ],
166
+ "PBKS": [
167
+ "Shikhar Dhawan",
168
+ "Jitesh Sharma",
169
+ "Jonny Bairstow",
170
+ "Prabhsimran Singh",
171
+ "Liam Livingstone",
172
+ "Matthew Short",
173
+ "Harpreet Bhatia",
174
+ "Atharva Taide",
175
+ "Rishi Dhawan",
176
+ "Sam Curran",
177
+ "Sikandar Raza",
178
+ "Shivam Singh",
179
+ "Harpreet Brar",
180
+ "Arshdeep Singh",
181
+ "Kagiso Rabada",
182
+ "Nathan Ellis",
183
+ "Rahul Chahar",
184
+ "Gurnoor Brar",
185
+ "Vidwath Kaverappa",
186
+ "Harshal Patel",
187
+ "Chris Woakes",
188
+ "Ashutosh Sharma",
189
+ "Vishwanath Pratap Singh",
190
+ "Shashank Singh",
191
+ "Tanay Thyagarajan",
192
+ "Prince Choudhary",
193
+ "Rilee Rossouw"
194
+ ],
195
+ "RR": [
196
+ "Sanju Samson",
197
+ "Jos Buttler",
198
+ "Shimron Hetmyer",
199
+ "Yashasvi Jaiswal",
200
+ "Dhruv Jurel",
201
+ "Riyan Parag",
202
+ "Donovan Ferreira",
203
+ "Kunal Rathore",
204
+ "R Ashwin",
205
+ "Kuldeep Sen",
206
+ "Navdeep Saini",
207
+ "Sandeep Sharma",
208
+ "Trent Boult",
209
+ "Yuzvendra Chahal",
210
+ "Adam Zampa",
211
+ "Prasidh Krishna",
212
+ "Avesh Khan",
213
+ "Rovman Powell",
214
+ "Shubham Dubey",
215
+ "Tom Kohler-Cadmore",
216
+ "Abid Mushtaq",
217
+ "Nandre Burger"
218
+ ],
219
+ "RCB": [
220
+ "Faf du Plessis",
221
+ "Glenn Maxwell",
222
+ "Virat Kohli",
223
+ "Rajat Patidar",
224
+ "Anuj Rawat",
225
+ "Dinesh Karthik",
226
+ "Suyash Prabhudessai",
227
+ "Will Jacks",
228
+ "Mahipal Lomror",
229
+ "Karn Sharma",
230
+ "Manoj Bhandage",
231
+ "Mayank Dagar",
232
+ "Vyshak Vijaykumar",
233
+ "Akash Deep",
234
+ "Mohammed Siraj",
235
+ "Reece Topley",
236
+ "Himanshu Sharma",
237
+ "Rajan Kumar",
238
+ "Cameron Green",
239
+ "Alzarri Joseph",
240
+ "Yash Dayal",
241
+ "Lockie Ferguson",
242
+ "Tom Curran",
243
+ "Swapnil Singh",
244
+ "Saurav Chauhan"
245
+ ],
246
+ "SRH": [
247
+ "Abdul Samad",
248
+ "Aiden Markram",
249
+ "Rahul Tripathi",
250
+ "Glenn Phillips",
251
+ "Mayank Agarwal",
252
+ "Heinrich Klaasen",
253
+ "Anmolpreet Singh",
254
+ "Upendra Yadav",
255
+ "Nitish Kumar Reddy",
256
+ "Abhishek Sharma",
257
+ "Marco Jansen",
258
+ "Washington Sundar",
259
+ "Sanvir Singh",
260
+ "Bhuvneshwar Kumar",
261
+ "Fazalhaq Farooqi",
262
+ "T Natarajan",
263
+ "Umran Malik",
264
+ "Mayank Markande",
265
+ "Shahbaz Ahmed",
266
+ "Travis Head",
267
+ "Wanindu Hasaranga",
268
+ "Pat Cummins",
269
+ "Jaydev Unadkat",
270
+ "Akash Singh",
271
+ "Jhathavedh Subramanyan"
272
+ ]
273
+ }
predictions.csv CHANGED
@@ -1 +1,5 @@
1
- user_name,match_id,predicted_winner,predicted_motm,bid_points
 
 
 
 
 
1
+ user_name,match_id,predicted_winner,predicted_motm,bid_points
2
+ Sahil,20240322_2,CSK,Ruturaj Gaikwad,250
3
+ Naveein,20240322_2,CSK,Rachin Ravindra,1000
4
+ Ganesh,20240322_2,CSK,Ruturaj Gaikwad,300
5
+ Jay,20240322_2,CSK,Ruturaj Gaikwad,500