Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matheus joining City #630

Open
alexanderfolstad opened this issue Sep 7, 2023 · 12 comments
Open

Matheus joining City #630

alexanderfolstad opened this issue Sep 7, 2023 · 12 comments

Comments

@alexanderfolstad
Copy link

So Matheus joined City, and has changed teams in FPL. However, AIrsenal does not account for this -- he is still registered as a WOL-player, and as such, does not get traded away - even though I now have 4 City-players.

Any tips on how to resolve?

@nbarlowATI
Copy link
Member

Hi @alexanderfolstad , thanks for reporting this - very interesting! (Out of curiosity, how does the FPL webpage deal with this? Do you have something on your team page telling you that you need to transfer out one of your City players?)

I can reproduce this, and it looks like the update of the PlayerAttributes isn't being saved correctly to the database when we do airsenal_update_db. From a bit of debug output in fill_player_attributes_table.py it does look like there is a PlayerAttributes being created for Nunes with "MCI" as the team, but after running that function, I can't find it in the database. I will investigate further and update.

@alexanderfolstad
Copy link
Author

I'm not sure if I can trade different player and keep 4 city-players, actually.

Looks like this:
city

@nbarlowATI
Copy link
Member

Interesting!
OK, so I made (hopefully) a fix in the develop branch that should double check that the updated PlayerAttributes are being committed to the database.
If you do

git checkout develop
pip install .
airsenal_setup_initial_db --clean
airsenal_update_db

then run prediction and optimization as usual, hopefully it will work... I at least verified that doing

python
>>> from airsenal.framework.utils import *
>>> p = get_player("Matheus Luiz Nunes")
>>> p.team("2324", 5)

returns 'MCI'.

Let us know if this helps!

@alexanderfolstad
Copy link
Author

alexanderfolstad commented Sep 8, 2023

Thanks! Giving this a crack.

from airsenal.framework.utils import *
p = get_player("Matheus Luiz Nunes")
p.team("2324", 5)
'MCI'

However, this is the team output after running optimisation:
=== starting 11 ===

== GK ==

Aaron Ramsdale (ARS)

== DEF ==

Kyle Walker (MCI)
Pedro Porro (TOT)
Aaron Wan-Bissaka (MUN)

== MID ==

Eberechi Eze (CRY)
Mohamed Salah (LIV)
Bruno Borges Fernandes (MUN)
James Maddison (TOT)(VC)

== FWD ==

Julián Álvarez (MCI)
Erling Haaland (MCI)(C)
Lyle Foster (BUR)

=== subs ===

Sam Johnstone (CRY)
Michael Keane (EVE)
Matheus Luiz Nunes (WOL)
Tyrone Mings (AVL)

@nbarlowATI
Copy link
Member

Ah, OK, this might involve a more complicated fix then - perhaps we look for "compulsory transfers" at the start of the optimization process. I can work on this later on today...
Would you be OK with sharing your FPL_TEAM_ID with us so we can use your situation to debug? (we won't have the login details so won't be able to make any changes to your team! :) )

@alexanderfolstad
Copy link
Author

No worries at all! My team ID is 1024117.

@jack89roberts
Copy link
Contributor

jack89roberts commented Sep 11, 2023

Assuming the issue with the attributes table is now fixed, this is something that the logic in Squad.add_player should cope with.

It looks like we disable the number of players per team check when getting the starting squad (I think that's the correct thing to do to get around this), but proposed transfers during the optimisation should be seen as invalid unless they fix the problem with having too many City players. Not sure why that isn't happening.

@jack89roberts
Copy link
Contributor

I think the problem is that we create the initial squad setting each player's team to be the team they played for at the time the transfer was made. Maybe we should change that to be the player's team for the first gameweek of the optimisation window instead.

@nbarlowATI
Copy link
Member

The thing is that when we add players to the squad via the past transactions, we assign a "team" to the CandidatePlayer which is correct when that player was added. One could argue that it would be better for the CandidatePlayer to just have a "player" attribute, that points to a Player instance (and would therefore have all the PlayerAttributes), but I could imagine that being slower and more memory-hungry in the optimization.
One fix may be for the squad to have an "update" method, that is called at the end of "get_starting_squad", that refreshes all the information according to the PlayerAttributes for the appropriate gameweek...? I'm looking into doing this now.

@nbarlowATI
Copy link
Member

Hi @alexanderfolstad we think we have a candidate fix for this problem in the branch bugfix-630/invalid-team - do you think you could git checkout this branch, re-run pip install . and do all the usual steps, and see if it works? (I reckon/hope it should tell you to remove either Kyle Walker or Nunes...)
We are still thinking about whether there may be a more elegant way of fixing this problem, but hopefully this branch should at least work...

@fol-debug
Copy link

fol-debug commented Sep 14, 2023 via email

@alexanderfolstad
Copy link
Author

Players in: Players out:


Josh Cullen Matheus Luiz Nunes

Perfect. Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants