Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update parser dep, expose bountiesWon on player stats #2

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@babel/plugin-transform-runtime": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/preset-typescript": "^7.22.11",
"@poker-apprentice/hand-history-parser": "^6.0.0",
"@poker-apprentice/hand-history-parser": "^6.2.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-node-resolve": "^15.2.1",
Expand Down
6 changes: 6 additions & 0 deletions src/__fixtures__/handHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { HandStrength } from '@poker-apprentice/types';

export const bovadaHandHistory: HandHistory = {
info: {
type: 'cash',
blinds: ['0.5', '1'],
currency: 'USD',
variant: 'holdem',
handNumber: '12345',
tableNumber: '1',
isFastFold: false,
bettingStructure: 'no limit',
site: 'bovada',
Expand All @@ -17,6 +19,7 @@ export const bovadaHandHistory: HandHistory = {
{
name: 'John',
seatNumber: 1,
positionIndex: 0,
position: 'BTN',
chipStack: '49.50',
isHero: false,
Expand All @@ -25,6 +28,7 @@ export const bovadaHandHistory: HandHistory = {
{
name: 'Carl',
seatNumber: 2,
positionIndex: 1,
position: 'SB',
chipStack: '27.45',
isHero: false,
Expand All @@ -33,6 +37,7 @@ export const bovadaHandHistory: HandHistory = {
{
name: 'Mike',
seatNumber: 3,
positionIndex: 2,
position: 'BB',
chipStack: '87.25',
isHero: true,
Expand Down Expand Up @@ -64,5 +69,6 @@ export const bovadaHandHistory: HandHistory = {
{ type: 'showdown', playerName: 'Mike', handStrength: HandStrength.OnePair, mucked: true },
{ type: 'showdown', playerName: 'Carl', handStrength: HandStrength.OnePair, mucked: false },
{ type: 'award-pot', playerName: 'Carl', amount: '56.9', isSidePot: false },
{ type: 'award-bounty', playerName: 'Carl', amount: '250' },
],
};
3 changes: 3 additions & 0 deletions src/analyzeHand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('analyzeHand', () => {
"players": {
"Mike": {
"aggressiveActionCount": 3,
"bountiesWon": "0",
"streets": {
"flop": {
"betCount": 1,
Expand Down Expand Up @@ -72,6 +73,7 @@ describe('analyzeHand', () => {
"players": {
"John": {
"aggressiveActionCount": 1,
"bountiesWon": "0",
"streets": {
"preflop": {
"betCount": 0,
Expand Down Expand Up @@ -105,6 +107,7 @@ describe('analyzeHand', () => {
"players": {
"Carl": {
"aggressiveActionCount": 0,
"bountiesWon": "250",
"streets": {
"flop": {
"betCount": 0,
Expand Down
1 change: 1 addition & 0 deletions src/analyzeHand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const analyzeHand = ({ actions, players }: HandHistory): HandHistoryStats
totalContributed: playerStat.totalContributed.toString(),
totalRakeContributed: playerStat.totalRakeContributed.toString(),
totalWon: playerStat.totalWon.toString(),
bountiesWon: playerStat.bountiesWon.toString(),
}));

const knownPlayers = new Set(
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export interface PlayerStats {
* The amount of chips won or lost by the player.
*/
totalWon: string;
/**
* The value of any bounties won during the hand, where the denomination matches the currency
* represented by the associated game.
*/
bountiesWon: string;
/**
* Whether the player voluntarily put chips into the pot.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/types/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export interface HandStatsState extends Omit<HandStats, 'totalPot' | 'totalRake'
export interface PlayerStatsState
extends OmitStrict<
PlayerStats,
'totalAwarded' | 'totalContributed' | 'totalRakeContributed' | 'totalWon'
'totalAwarded' | 'totalContributed' | 'totalRakeContributed' | 'totalWon' | 'bountiesWon'
> {
totalAwarded: BigNumber;
totalContributed: BigNumber;
totalRakeContributed: BigNumber;
totalWon: BigNumber;
bountiesWon: BigNumber;
}

export type AllPlayerStatsState = Record<string, PlayerStatsState>;
Expand Down
13 changes: 13 additions & 0 deletions src/utils/applyAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
Action,
AwardBountyAction,
AwardPotAction,
BetAction,
CallAction,
Expand Down Expand Up @@ -36,6 +37,7 @@ export const getInitialState = (players: Player[] = []): State => ({
totalContributed: new BigNumber(0),
totalRakeContributed: new BigNumber(0),
totalWon: new BigNumber(0),
bountiesWon: new BigNumber(0),
vpip: false,
wentToShowdown: false,
} satisfies PlayerStatsState,
Expand Down Expand Up @@ -227,9 +229,18 @@ const applyAwardPot = ({ state, action }: ApplyOptions<AwardPotAction>): State =
})),
});

const applyAwardBounty = ({ state, action }: ApplyOptions<AwardBountyAction>): State => ({
...state,
playerStats: updatePlayerStats(state, action.playerName, ({ bountiesWon }) => ({
bountiesWon: bountiesWon.plus(action.amount),
})),
});

export const applyAction = ({ state, action }: ApplyOptions<Action>): State => {
const { type } = action;
switch (type) {
case 'award-bounty':
return applyAwardBounty({ state, action });
case 'award-pot':
return applyAwardPot({ state, action });
case 'bet':
Expand All @@ -252,6 +263,8 @@ export const applyAction = ({ state, action }: ApplyOptions<Action>): State => {
return applyShowdown({ state, action });
case 'deal-hand':
return state;
case 'tournament-placement':
return state;
default:
return assertNever(type);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1350,10 +1350,10 @@
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==

"@poker-apprentice/hand-history-parser@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@poker-apprentice/hand-history-parser/-/hand-history-parser-6.0.0.tgz#5768eec4f4229c7bce2f979c730d321d806a7541"
integrity sha512-NeHJ0SBZZYyJLUT+v5HZ2FnkYXiS9CRDXitHA5QCBSQDYr7ND+aQlZaB/2wIpzFi5N2iIjtP5enRdSZnQqjNGg==
"@poker-apprentice/hand-history-parser@^6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@poker-apprentice/hand-history-parser/-/hand-history-parser-6.2.0.tgz#4b465e5202a621769c4b49b486b5d91defddc3b7"
integrity sha512-UvsZt+FDxMLxr0gzIrWSApz5nXd8VMxDACuIGyw+t1EOB0WYTR4rIDuUhDdOqA/l4gkPXJ3MV9g5tQDo+n5RwQ==
dependencies:
"@babel/runtime" "^7.22.11"
"@poker-apprentice/types" "^1.4.0"
Expand Down