RubenvanGemeren commited on
Commit
d7d6a80
·
1 Parent(s): 47db1be

added test endpoint

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -149,8 +149,41 @@ for player in sample_players:
149
 
150
  @app.route("/test")
151
  def test():
 
 
152
 
153
- return "test"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
 
156
  @app.route("/")
 
149
 
150
  @app.route("/test")
151
  def test():
152
+ # Create new list
153
+ display_players = []
154
 
155
+ for player in players:
156
+ if not any(p['first_name'] == player['first_name'] and p['second_name'] == player['second_name'] for p in display_players):
157
+ # Get all players with the same first and last name
158
+ all_predictions = [
159
+ p for p in players if p["first_name"] == player["first_name"] and p["second_name"] == player["second_name"]
160
+ ]
161
+ # Select the one with the highest gameweek
162
+ latest_prediction_entry = max(all_predictions, key=lambda x: x["gameweek"])
163
+
164
+ # Remove the selected player from the list
165
+ # all_predictions.remove(latest_prediction_entry)
166
+
167
+ # Ensure 'latest_predictions' is initialized as an empty list
168
+ # Create a new dictionary to hold the predictions for this player
169
+ latest_predictions = []
170
+
171
+ # Add the field gameweek, points, predicted_score to the selected player as a dictionary
172
+ for p in all_predictions:
173
+ latest_predictions.append({
174
+ "gameweek": p["gameweek"],
175
+ "points": p["points"],
176
+ "predicted_score": p["predicted_score"]
177
+ })
178
+
179
+ # Add the latest_predictions to the selected player
180
+ latest_prediction_entry["latest_predictions"] = latest_predictions
181
+
182
+ # Add to new list
183
+ display_players.append(latest_prediction_entry)
184
+
185
+
186
+ return display_players
187
 
188
 
189
  @app.route("/")