pyAFL icon indicating copy to clipboard operation
pyAFL copied to clipboard

Player Bio

Open audas opened this issue 4 years ago • 12 comments

Not really sure how to go about making changes - but it would be great if we could get player stats to include player bio so we can have their date of birth etc. If we get it as a timestamp then we can also use it as useable data, same for height and weight. Something like this? Sorry if this is not the way of going about things.

`

  player_bio={}
    for i in soup.find_all('b'):
        if(re.sub(r"[\n\t\s]*", "", i.get_text())=="Born:"):
            player_bio["dob"]=re.sub(r"[\n\t\s]*", "", i.next_sibling.replace(" (",""))    
            timestamp = (datetime.strptime(player_bio["dob"], '%d-%b-%Y') - datetime(1970, 1, 1)).total_seconds()
            player_bio["timestamp"]=timestamp
        if(re.sub(r"[\n\t\s]*", "", i.get_text())=="Height:"):
            player_bio["height"]=re.sub("[^0-9]", "",i.next_sibling)
        if(re.sub(r"[\n\t\s]*", "", i.get_text())=="Weight:"):
            player_bio["weight"]=re.sub("[^0-9]", "",i.next_sibling) `

audas avatar May 28 '21 01:05 audas

Thanks @audas. Great idea! And this is definitely how to go about making changes! Much appreciated :smile:

Perhaps we can add a 'metadata' attribute to the Player object which contains these data fields. For example, see Stuart Magee:

player.metadata = {"height": 174, 
                   "weight": 74, 
                   "born": <timestamp_object: "13-Oct-1943">,
                   "debut": <timestamp_object: "01-Oct-1958">, 
                   "last": <timestamp_object: "01-Oct-1968">, 
                   }

@audas would you like to implement this patch? You've already written most of the HTML parsing, now just need to plug it into the Player.get_player_stats() function. I'd be happy to help out if you're unsure about how to contribute!

RamParameswaran avatar May 28 '21 14:05 RamParameswaran

On immediate second thought - perhaps it's better to make that data available as a Pandas dataframe, like all the other data... @audas what do you think?

RamParameswaran avatar May 28 '21 14:05 RamParameswaran

I added what you have done yes. It comes back in the form of player_bio as part of the object. I also added a new function called get_player_bio() which returns ONLY this so it can be used as a faster function.

I have placed all of Carlton so far into a local database for faster cross reference..

audas avatar May 28 '21 21:05 audas

Sounds great @audas. Would you be able to push your update to Github?

RamParameswaran avatar May 29 '21 12:05 RamParameswaran

I am not confident on doing this sort of thing RamParameswaran - I can post my code, but I feel very uncertain on doing things like this. I would like to learn and try.

I download things as a zip file and work on them in Eclipse or InteliJ etc.

audas avatar May 29 '21 12:05 audas

That's 100% okay @audas! pyAFL is a fun hobby project, and a really good way learn about Open Source :wink:

Here's a great video that explains the basics of using Github and contributing to open source projects.

RamParameswaran avatar May 29 '21 12:05 RamParameswaran

@RamParameswaran Hey, is this still up for grabs? I'd like to try working on it.

AntonySJohn avatar Oct 15 '21 08:10 AntonySJohn

Hi @AntonySJohn yep this is still up for grabs. I'd be happy to help or advise if you need, just ping me.

RamParameswaran avatar Oct 16 '21 00:10 RamParameswaran

Hi @RamParameswaran, is this still up for grabs? I would like to give it a try.

adrperez5 avatar Apr 22 '24 19:04 adrperez5

Hi @adrperez5. Yep no-one else has picked this up, so it is definitely up for grabs! I'm happy for you to implement this as you think best. And I'll of course review and merge your PR promptly. Thanks!

RamParameswaran avatar Apr 22 '24 20:04 RamParameswaran

Hi @audas I have placed the bio information in the Player object as an attribute so it may be called using player.metadata after calling get_player_stats. player.metadata is currently a dictionary. This is my first time contributing, so I would like some guidance on how to have my code reviewed.

adrperez5 avatar Apr 25 '24 14:04 adrperez5

Hi @audas ,

A couple of quick thoughts:

  1. Might be good to add some checks just in case next_sibling is missing or the format is weird — just to avoid any crashes. 2 .Converting DOB to a timestamp is a nice touch! You could even keep both the readable date and the timestamp if that’s useful.
  2. If you’re up for it, maybe wrap this into a little helper like extract_player_bio(soup) and plug it into the part that handles player stats.

kxc663 avatar Apr 17 '25 04:04 kxc663