I have a piece of code which parses a large JSON containing ~30000 shot events (a list of dicts) occurring in a Battle Royale match and returns the shots with intent to hit an opponent. It estimates this using heuristics.
I'm working with two separate event logs for the same match:
match_shot_events.json: all the shot events throughout the match (sparse data)- Relevant fields:
timestamp,(x, y, z)of the impact
- Relevant fields:
match_movement_events.json: the movement events (positions) of every player recorded at ~400 ms intervals throughout the match (dense data)- Relevant fields:
timestamp,(x, y, z)of the player
- Relevant fields:
Current algorithm:
- Go through the movement events (positions) once, mapping each player ID to a list of their movements events sorted by timestamp
- For each shot event
- Get position of shooter at time of shot (binary search)
- For each opponent player:
- Get position at the time of the shot (binary search)
- Compute direction vector and bullet ray
- Surround position in sphere
- Check if ray intersects sphere (constant time) and if it does, add it to the return list
The current implementation uses plain python and takes 15 minutes to run. I'd like to speed that up if possible, but I'm not sure how to. Any help would be appreciated.