# The Poker Sleuth Statistics Language

Links to many examples of using the Poker Sleuth Statistics Language may be found on the Statistics Reference page, where you can see the source code for all of the statistics built-in to Poker Sleuth.

Poker Sleuth's flexible Statistics Language can define almost any statistic that captures how frequently a player takes some action in a some situation. These statistics can always be expressed as a percentage, computed as follows:

When defining a state, there are three key elements that must be defined for every action a player takes.

• The action is an opportunity if it qualifies as a situation for measuring the statistic.
• An opportunity is an instance if the player took the action being measured.
• Some statistics are per_hand; they measure the percentage of hands where some event takes place, such as VPIP. Other statistics measure the percentage of actions where some event takes place, such as AFq.

A stat definition must define each of those three elements. Here is a minimal example that simply measures what percentage of a player's actions are folds:

Percentage of actions that are bets or raises
per_hand: false opportunity: true instance: action == Fold

Each time a player takes an action during a hand, the stat definition rule is considered. If opportunity evaluates to true, then the action will be included when calculating the statistic. In the simple example above, opportunity is always true, all actions will be included. If instance evaluates to true, then the frequency will increase; otherwise, it will decrease. If per_hand is true, then the whole hand will be considered one opportunity as long as opportunity was true at least once during the hand. The frequency will increase as long as instance was true at least once when opportunity was true.

In addition to action, the Poker Sleuth Statistics Language defines a wide array of useful properties that you can use. For a complete list of properties and operations, see Statistics Language Properties and Operations.

You may also define additional properties to be used as part of a rule. Let's examine the definition for Raised First In (RFI):

RFI
per_hand: true entered: action != Fold and round == P opportunity: not other(entered) and round == P instance: action == Raise split position

We entered to be a player who had a pre-flop action and didn't fold. An opportunity occurs when no one else as entered the pot yet pre-flop.

There's one other feature of the Poker Sleuth Statistics Language that we need to mention: the ability to subdivide stats. As the last line of a stat definition, place the keyword split followed by one or more properties that you want to subdivide on. Those properties will then be available as Filters and Breakdowns when configuring the Stat Controls. In the Raised First In definition above, it's split based on position. That instructs Poker Sleuth to track the RFI separately for players in the Small Blind, Big Blind, Early Position, Hijack, Cutoff, or Button.