0

My django app stores the actions that players do during a game. One of the models is called Event, and it contains a list of all actions by players. It has the following 4 columns: game_id, player_name, action, turn. Turn is the number of the turn in which the action takes place.

Now I want to count how often players behave in certain patterns. For example, I want to know how often a player takes decision A in turn 2 and that same player takes decision B in turn 3. I'm breaking my head over how I can do this. Can someone help?

Note: Ideally the queries should be efficient, bearing in mind that some related queries are following. For example, after the above query I would want to know how often a player takes decision C in turn 4, after doing A and B in turns 2 and 3. (The goal is to predict the likelihood of each action, given the actions in the past.)

Uberfatty
  • 107
  • 1
  • 1
  • 4
  • Any efforts? You may try [GROUP BY on multiple fields](https://stackoverflow.com/questions/37483884/django-orm-group-by-multiple-columns) – sudden_appearance Feb 25 '22 at 21:35
  • With a GROUP BY I could do things like count the number of actions each player performed in each turn, but I don't see how I can use it to do what I described. – Uberfatty Feb 26 '22 at 09:55

0 Answers0