After adding a player vs. player comparison, I finally set up the bot on a droplet last week. I posted about it on Reddit and as you can see it was very well received! It is being used a lot (nearly 100 comments a day), which is great to see. It also means I've received some feedback, and so I decided to quickly implement some of the suggestions I received!
Changing the player vs. player table
The player vs. player table wasn't very mobile friendly before, which someone pointed out immediately. They suggested to create a separate table for each player, and to simply stack them on top of each other, and so that's what I did. This will also allow for a comparison of more than 2 players in the future, which I might implement as well.
Improving the tables!
Improved tables for goalkeepers
I also made some other improvements to the tables in general. One problem was that comparing goalkeepers was pointless, because the tables only included stuff like expected goals and assists, which obviously isn't relevant to them. To solve this I decided to create a table that included their expected goals against, their saves and more.
Saving the results
Since a player's expected goals against isn't included in a player's information on Understat, I had to get this from their team itself. To do this, I created another function that saves all the team's results in the database, and then use that to get the data. Luckily this was pretty easy to do using my own Understat package!
Creating the goalkeeper table
Another thing I did was add the expected goals against to a defender's table, and also the points the player actually scored during the games (including bonus points). To accomplish this, the first thing I had to do was make sure the matches used when comparing players are only those played in the Premier League (since that's what FPL is about). Finally I needed to somehow get the points and then match this to the respective data from Understat. Luckily I could just use a player's history included in the FPL API to get the points, and all the fixtures on Understat have their own ID, so I could simply compare a player's fixtures with the Premier League fixtures.
You may have noticed that I also switched to use tabulate, which is a Python package for creating tables that I found. It works pretty well for my use case, and also cleaned up the code slightly.
I also made some other QoL changes to the bot, but this post is already getting pretty long. If you want to read more about it, you can check out the Reddit thread I created.
I might add the ability to compare more than 2 players to each other, but will have to see. Will hopefully receive some more suggestions as well!
Usage & installation
FPLbot uses MongoDB to store players in a database, and so it is required to have MongoDB installed. Other than that, it uses fpl to retrieve information from Fantasy Premier League's API, and thus requires Python 3.6+.
git clone firstname.lastname@example.org:amosbastian/FPLbot.git cd FPLbot pip install -r requirements.txt
Once installed you should create a
config.json file like the above example, but with the correct values. Once you have done this, then you can schedule a cron job to run the bot whenever you want!
I've created a Discord server for people interested in programming FPL related things, so if you are interested in helping out, or simply want to know more, then don't hesitate to join! Otherwise you can simply create an issue on GitHub.