Functions

This chapter documents the Functions used in this package.

Analysis

One off functions for various analysis. Almost all Analysis functions take either a Game or Player Class Object.

face_card_in_winning_cards(data):

Find what percent of the time a face card is used to win.

Parameters:

data (DocumentFilter) – Input data.

Returns:

A dict of file_id and face card in winning hand percent.

Return type:

dict

Example:
# This function requires Player Stacks and Wins to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import face_card_in_winning_cards
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
face_card_in_winning_cards(data=DocumentFilter(data=poker, class_lst=['Player Stacks', 'Wins']))
Note:

Percent of all Winning Cards = Total all cards and get percent that include a face card. Percent one face in Winning Cards = Percent of all wins hand at least a single face card.

longest_streak(data):

Find the longest winning streak.

Parameters:

data (DocumentFilter) – Input data.

Returns:

Longest streak.

Return type:

pd.DataFrame

Example:
# This function requires Wins to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import longest_streak
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
longest_streak(data=DocumentFilter(data=poker, class_lst=['Wins']))
Note:

DocumentFilter requires class_lst=[‘Wins’]

raise_signal_winning(data):

When a player raises, does that mean they are going to win(?).

Parameters:

data (DocumentFilter) – Input data.

Returns:

A pd.DataFrame with the percent related to each position.

Return type:

pd.DataFrame

Example:
# This function requires Raises to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import raise_signal_winning
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
raise_signal_winning(data=DocumentFilter(data=poker, class_lst=['Raises']))
Note:

DocumentFilter requires class_lst=[‘Raises’]

small_or_big_blind_win(data):

When a player is small or big blind, does that mean they are going to win(?).

Parameters:

data (DocumentFilter) – Input data.

Returns:

A pd.DataFrame with the percent related to each blind.

Return type:

pd.DataFrame

Example:
# This function requires Small Blind and Big Blind to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import small_or_big_blind_win
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
small_or_big_blind_win(data=DocumentFilter(data=poker, class_lst=['Small Blind', 'Big Blind']))
Note:

DocumentFilter requires class_lst=[‘Small Blind’, ‘Big Blind’]

player_verse_player(data):

Find how many times and what value a player called or folded related all other players.

Parameters:

data (DocumentFilter) – Input data.

Returns:

A dict of counts and values for each ‘Calls’, ‘Raises’, ‘Checks’, and ‘Folds’.

Return type:

dict

Example:
# This function requires 'Calls', 'Raises', 'Checks', and 'Folds' to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import player_verse_player
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
player_verse_player(data=DocumentFilter(data=poker, class_lst=['Calls', 'Raises', 'Checks', 'Folds']))
Note:

DocumentFilter requires class_lst=[‘Calls’, ‘Raises’, ‘Checks’, ‘Folds’]

bluff_study(data, position_lst):

Compare betting habits when a player is bluffing.

Parameters:
  • data (DocumentFilter) – Input data.

  • position_lst (Union[List[str], str]) –

Returns:

A pd.DataFrame of counts and values for each position.

Return type:

pd.DataFrame

Example:
# This function requires a single player_index to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import bluff_study
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
bluff_study(data=DocumentFilter(data=poker, player_index_lst=['DZy-22KNBS']))
Note:

This function requires a single player_index to be included in the DocumentFilter.

static_analysis(data):

Build a static analysis DataFrame.

Parameters:

data (DocumentFilter) – Input data.

Returns:

A dict of stats.

Return type:

dict

Example:
# This function requires a single player_index to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import static_analysis
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
static_analysis(data=DocumentFilter(data=poker, player_index_lst=['DZy-22KNBS']))
Note:

This function requires a single player_index to be included in the DocumentFilter.

pressure_or_hold(data, bet, position):

Check how a player has responded to a bet in the past.

Parameters:
  • data (DocumentFilter) – Input data.

  • position (str) – Location in the hand, default is None. Optional

Paran bet:

Proposed bet amount.

Returns:

A dict of Call Counts, Fold Counts, Total Count, and Call Percent.

Return type:

dict

Example:
# This function requires a single player_index to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import pressure_or_hold
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
pressure_or_hold(data=DocumentFilter(data=poker, player_index_lst=['DZy-22KNBS']), bet=500, position='Pre Flop')
Note:

None

ts_analysis(data, window):

Build a Time Series DataFrame.

Parameters:
  • data (DocumentFilter) – A Player class object.

  • window (int) – Rolling window value, default is 5. Optional

Returns:

A DataFrame of various moves over time.

Return type:

pd.DataFrame

Example:
# This function requires a single player_index to be included in the DocumentFilter.
from poker.poker_class import Poker
from poker.analysis import ts_analysis
from poker.document_filter_class import DocumentFilter
repo = 'location of your previous game'
grouped = [['YEtsj6CMK4', 'M_ODMJ-3Je', 'DZy-22KNBS'],
            ['48QVRRsiae', 'u8_FUbXpAz']]
poker = Poker(repo_location=repo, grouped=grouped)
ts_analysis(data=DocumentFilter(data=poker, player_index_lst=['DZy-22KNBS']))
Note:

This is a function version of the TSanalysis class.

Base

One off functions for helping analysis. These are helper functions that were constructed to limit the reliance on other packages. Most take a list, np.ndarray, or pd.Series and return a list of floats or ints.

normalize(data, keep_nan):

Normalize a list between 0 and 1.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data to normalize.

  • keep_nan (bool) – If True, will maintain nan values, default is False. Optional

Returns:

Normalized list.

Return type:

list

Example:
from poker.base import normalize
data = [1, 2, 3, None, np.nan, 4]
# keep_nan set to False (default)
test = normalize(data, keep_nan=False) # [0.0, 0.3333333333333333, 0.6666666666666666, 1.0]
# keep_nan set to True
test = normalize(data, keep_nan=False) # [0.0, 0.3333333333333333, 0.6666666666666666, nan, nan, 1.0]
Note:

If an int or float is passed for keep_nan, that value will be placed where nan’s are present.

standardize(data, keep_nan):

Standardize a list with a mean of zero and std of 1.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data to standardize.

  • keep_nan (bool) – If True, will maintain nan values, default is False. Optional

Returns:

Standardized list.

Return type:

list

Example:

None

Note:

If an int or float is passed for keep_nan, that value will be placed where nan’s are present.

running_mean(data, num):

Calculate the Running Std on num interval.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data.

  • num (int) – Input val used for Running Std window.

Returns:

Running mean for a given np.ndarray, pd.Series, or list.

Return type:

List[float]

Example:
from poker.base import running_mean
data = [1, 2, 3, None, np.nan, 4]
test = running_mean(data=data, num=2) # [1.5, 1.5, 1.5, 2.5, 2.75, 2.5]
Note:

None and np.nan values are replaced with the mean value.

running_std(data, num):

Calculate the Running Std on num interval.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data.

  • num (int) – Input val used for Running Std window.

Returns:

Running mean for a given np.ndarray, pd.Series, or list.

Return type:

List[float]

Example:
from poker.base import running_std
data = [1, 2, 3, None, np.nan, 4]
test = running_std(data=data, num=2) # [0.7071067811865476, 0.7071067811865476, 0.7071067811865476,
                                     #  0.7071067811865476, 0.3535533905932738, 0.0]
Note:

None and np.nan values are replaced with the mean value.

running_median(data, num):

Calculate the Running Median on num interval.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data.

  • num (int) – Input val used for Running median window.

Returns:

list.

Return type:

List[float]

Example:

None

Note:

None and np.nan values are replaced with the mean value.

running_percentile(data, num):

Calculate the Running Percentile on num interval.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data.

  • num (int) – Input val used for Running Percentile window.

  • q (float) – Percent of data.

Returns:

Running percentile for a given np.ndarray, pd.Series, or list.

Return type:

List[float]

Example:

None

Note:

None and np.nan values are replaced with the mean value.

cumulative_mean(data):

Calculate the Cumulative Mean.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Cumulative mean for a given np.ndarray, pd.Series, or list.

Return type:

List[float]

Example:
from poker.base import cumulative_mean
data = [1, 2, 3, None, np.nan, 4]
test = cumulative_mean(data=data) # [0.0, 1.0, 1.5, 2.0, 2.125, 2.2]
Note:

None and np.nan values are replaced with the mean value.

round_to(data, val, remainder):

Rounds an np.array, pd.Series, or list of values to the nearest value.

Parameters:
  • data (list, np.ndarray, pd.Series, int, float, or any of the numpy int/float variations) – Input data.

  • val (int) – Value to round to. If decimal, will be that number divided by.

  • remainder (bool) – If True, will round the decimal, default is False. Optional

Returns:

Rounded number.

Return type:

List[float] or float

Example:
# With remainder set to True.
lst = [4.3, 5.6]
round_to(data=lst, val=4, remainder=True) # [4.25, 5.5]

# With remainder set to False.
lst = [4.3, 5.6]
round_to(data=lst, val=4, remainder=False) # [4, 4]
Note:

Single int or float values can be passed.

calc_gini(data):

Calculate the Gini Coef for a list.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Gini value.

Return type:

float

Example:
>>> lst = [4.3, 5.6]
>>> calc_gini(data=lst, val=4, remainder=True) # 0.05445544554455435
Note:

The larger the gini coef, the more consolidated the chips on the table are to one person.

search_dic_values(dic, item):

Searches a dict using the values.

Parameters:
  • dic (dict) – Input data.

  • item (str, float or int) – Search item.

Returns:

Key value connected to the value.

Return type:

str, float or int

Example:

None

Note:

None

flatten(data, type_used):

Flattens a list of lists and checks the list.

Parameters:
  • data (list) – Input data.

  • type_used (str) – Type to search for, default is “str”. Optional

  • type_used – Either {str, int, or float}

Returns:

Returns a flattened list.

Return type:

list

Example:

None

Note:

Will work when lists are mixed with non-list items.

native_mode(data):

Calculate Mode of a list.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Returns the Mode.

Return type:

float

Example:

None

Note:

None

native_median(data):

Calculate Median of a list.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Returns the Median.

Return type:

float

Example:

None

Note:

If multiple values have the same count, will return the mean. Median is used if there is an odd number of same count values.

native_mean(data):

Calculate Mean of a list.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Returns the mean.

Return type:

float

Example:

None

Note:

None

native_variance(data, ddof):

Calculate Variance of a list.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data.

  • ddof (int) – Set the degrees of freedom, default is 1. Optional

Returns:

Returns the Variance.

Return type:

float

Example:

None

Note:

None

native_std(data, ddof):

Calculate Standard Deviation of a list.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data.

  • ddof (int) – Set the degrees of freedom, default is 1. Optional

Returns:

Returns the Standard Deviation.

Return type:

float

Example:

None

Note:

None

native_sum(data):

Calculate Sum of a list.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Returns the Sum.

Return type:

float

Example:

None

Note:

None

native_max(data):

Calculate Max of a list.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Returns the max value.

Return type:

float

Example:

None

Note:

None

unique_values(data, count, order, indexes, keep_nan):

Get Unique values from a list.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data.

  • count (bool) – Return a dictionary with item and count, default is None. Optional

  • order (bool) – If True will maintain the order, default is None. Optional

  • indexes (bool) – If True will return index of all similar values, default is None. Optional

  • keep_nan (bool) – If True will keep np.nan and None values, converting them to None, default is False. Optional

Returns:

Returns either a list of unique values or a dict of unique values with counts.

Return type:

Union[list, dict]

Example:
from poker.base import unique_values
data = [1, 2, 3, None, np.nan, 4]
# count set to False (default)
test = normalize(data, keep_nan=False) # [1, 2, 3, 4]
# count set to True
test = normalize(data, keep_nan=False) # {1: 1, 2: 1, 3: 1, 4: 1}
Note:

Ordered may not appear accurate if viewing in IDE.

native_skew(data):

Calculate Skew of a list.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Returns the skew value.

Return type:

float

Example:

None

Note:

None

native_kurtosis(data):

Calculate Kurtosis of a list.

Parameters:

data (list, np.ndarray, or pd.Series) – Input data.

Returns:

Returns the kurtosis value.

Return type:

float

Example:

None

Note:

None

native_percentile(data, q):

Calculate Percentile of a list.

Parameters:
  • data (list, np.ndarray, or pd.Series) – Input data.

  • q (float) – Percentile percent.

Returns:

Returns the percentile value.

Return type:

float

Example:

None

Note:

If input values are floats, will return float values.