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 135 forks source link

IndexError: list index out of range when requesting the position too early in the game #425

Closed JasonMendoza2008 closed 2 years ago

JasonMendoza2008 commented 2 years ago

To reproduce the bug, make a virtual environment under Python 3.10.2. Install cassiopeiawith pip install cassiopeia. And run the following script https://github.com/meraki-analytics/cassiopeia/blob/master/examples/timeline.py but at time 00:10.

Traceback:

Traceback (most recent call last):
  File "C:\Users\---\Documents\Projets_Persos\League of Legends\main.py", line 43, in <module>
    print_newest_match(name="RatIRL ILY", region="EUW")
  File "C:\Users\---\Documents\Projets_Persos\League of Legends\main.py", line 33, in print_newest_match
    print("Position:", p_state.position)
  File "C:\Users\---\virtualenv\LoL\lib\site-packages\cassiopeia\core\match.py", line 871, in position
    latest_event_ts = sorted(latest_event_with_ts)[-1]
IndexError: list index out of range
JasonMendoza2008 commented 2 years ago

Catching the exception IndexError or checking the length of the list beforehand is probably the way to go (and returning the coordinates of the spawn because we don't have any more information yet) but as pointed out in the other issue (https://github.com/meraki-analytics/cassiopeia/issues/424) I would prefer interacting with someone that knows a bit about the source code of cassiopeia before making a pull request to fix those problems.

jjmaldonis commented 2 years ago

I'm going to say this is intentional. There isn't a valid Position that can be returned this early in the game since there is no data for it, so throwing an IndexError seems reasonable. Like you said, you can catch the exception if you want.

JasonMendoza2008 commented 2 years ago

Fair enough!

Quick question @jjmaldonis, what triggers data to be filled in with Position? I'm not sure I fully understand that.

jjmaldonis commented 2 years ago

@JasonMendoza2008 I dug into this more. The position data is filled by the position.x and position.y values in the timeline's participant frames, or by the latest event in the cumulative timeline that has both a position and a timestamp. It looks like a frame always exists, regardless of the time when the cumulative timeline is queried. I fixed the bug where an IndexError is thrown, so now this method should never throw an error. See https://github.com/meraki-analytics/cassiopeia/pull/430/files#diff-ab73563069f209cd2b1cf65668f8e114081b54556c707a69b71790b8731da890R1039 for details.