AntoineH – I wonder if it is possible for me to use the same mechanism you created to fix the missing predictions to allow me to create the computer generated random scores for users. Can I Ask where about this code is?
Weird… where did my precious answer go? I thought I answered to this question 😀
The mechanism to change the scores is in the calc_score method of the Football_Pool_Pool class. This method also contains a hook that you can use to overwrite the function. I use this mechanism also in the Golden Games add-on.
AntoineH – Thank you. I have added this in but its hard for me to check if its working. It should be checking if a user has entered a home or away score and add a random number between 0-60 on any missing scores:
$user_home_is_valid = is_numeric($user_home); $user_away_is_valid = is_numeric($user_away); // Check if the user has provided predictions for both home and away teams if ($user_home_is_valid && $user_away_is_valid) { $user_home = (int) $user_home; $user_away = (int) $user_away; } else { // User prediction not complete for one or both teams // Set random scores between 0 and 60 for missing predictions if (!$user_home_is_valid) { $user_home = rand(0, 60); } if (!$user_away_is_valid) { $user_away = rand(0, 60); } }
If you want to check your code, you’ll need to create some test users and test matches. Write out some scenarios, add the test data and then check in the plugin and/or database if you get the expected values. Shouldn’t be too hard to test.
The current ‘fix incomplete’ method – does it update the users prediction in the DB from ‘NULL’ to ‘0’ or is it meant to leave it as ‘NULL’
It only ‘assumes’ a 0 when doing the calculation. If I also updated the database, you would never have the option to disable the option again and go back to the previous state.
Ah that makes sense – I was testing and it kept changing the users awarded points but it must be randomly predicting the missing score each time and thus changing the outcome every time the calc method runs. I think I need to add a method that predicts missing scores for a user and adds it to the DB to make it permanent. I was thinking I could create a method that does this when the match is locked for editing.
You can also do it when doing the calculation. Indeed, just update the DB for the ones containing a NULL value. Can be done in two queries (one for home and one for away). On a next calculation these values are permanent and won’t be updated again.
Something like this for the home score prediction:
UPDATE pool_wp_predictions
SET home_score = FLOOR(RAND()*(b-a+1))+a
WHERE home_score IS NULL
Where a and b are the min and max values for your predictions (e.g., a = 0 and b = 5).