meraki-analytics / cassiopeia

An all-inclusive Python framework for the Riot Games League of Legends API. Cass focuses on making the data easy and fun to work with, while providing all the tools necessary to create a website or do data analysis.
MIT License
553 stars 134 forks source link

Role types discrepancies #230

Closed xEcEz closed 6 years ago

xEcEz commented 6 years ago

Participants' role attribute can be of different types. Maybe having an enum that covers every case would be more consistent.

>>> print(match.participants[2].role)
None
>>> print(match.participants[4].role)
SOLO
>>> print(match.participants[6].role)
Role.adc
>>> print(type(match.participants[6].role))
<enum 'Role'>
>>> print(type(match.participants[4].role))
<class 'str'>
>>> print(type(match.participants[2].role))
<class 'NoneType'>
jjmaldonis commented 6 years ago

The reason for the role types being different is twofold:

1) In the general context of League, if you ask someone "What are the roles (or lanes) a champion can play in?" They will answer with "Top, mid, jungle, support, adc". The Riot API pollutes that answer with additional roles such as SOLO, DUO, and NONE, but those aren't roles, they are just placeholders for "ehhh we couldn't figure out what to do here".

2) More practically, a user can easily check if the roles Riot gives are valid by doing if isinstance(role, Enum). If that's false, Riot gave a weird result back that isn't especially useful. You can always recast the types using str(role) if you want a string or want them to always be the same type.

xEcEz commented 6 years ago

I see, thanks for the answer.

I ran into the same issue of getting weird results backs, so what I am doing is to combine both pieces of information to reconstruct something meaningful out of it. However, I understand the reason for exposing this information as is.

jjmaldonis commented 6 years ago

If you want better values for roles you can also check out our code here: https://github.com/meraki-analytics/role-identification

You need a champion.gg API key but after you have that you can use the role-id code like this:

roles = get_team_roles(match.blue_team, champion_roles)
print({role.name: champion.name for role, champion in roles.items()})

{'top': 'Pantheon', 'jungle': 'Nunu', 'mid': 'Akali', 'adc': 'Caitlyn', 'support': 'Morgana'}
xEcEz commented 6 years ago

Ok, thanks for sharing this.