Hand History Parser for obtaining Player Stats

Add your suggestions for improving Poker Mavens
cchervit
Posts: 35
Joined: Sat Mar 14, 2020 11:18 pm

Re: Hand History Parser for obtaining Player Stats

Post by cchervit »

naked_eskimo wrote:If I "stitched" two hand history files together, would this still work? Often games go from before midnight, until after midnight. This means the session history is spread over two files. If I just copied and pasted the contents of two files into one, would that work?
I had this issue, too. So I modded the loop just a bit so it would ignore the hands from the night before. Basically I ignore the hands until I hit the local table Hand Number to be 1. There are three critical restrictions on having this work, though.
  1. The first file argument you pass to the script MUST be the one with hands from the night before
  2. You have to run this before hands also get added to the 2nd file (in other words, before they play again the next night) cause if there's another 1st hand encountered, it will start adding those to the balances cause once I encounter the first hand of the table, everything after just gets counted
  3. You can't pass in hand result files from multiple tables into the script anymore
The better way would have been to pass in an argument for a given start/end datetime you want and have the script do datetime comparisons, but this was just quicker and dirtier to do for me. Or actually now that I'm typing this up, an even better way would be after reading in all the hands and sorting them in date order, just to add a new "Table output row" for each successive local hand of 1 encountered. In my old age, I just don't have patience to code anymore. Maybe the original script author can code up something better?!?! :D ;) Hint! Hint! Wink! Wink!

Anyway, here's the code loop that you need to replace with what's there:

Code: Select all

    # CC Added startHands variable
    # we need to find the first hand to process. sometimes log file has last night's hands first that we
    # want to skip over until we find the first local start hand. we'll use startHands to control when to
    # start adding the hands
    startHands = False
        
    for fh in args.file:
        f = open(fh.name, mode='r', encoding='utf-8')
        line = f.readline()
        while (len(line) != 0):
            matches = re.search("Hand #(\d*)-(\d*) - (.*)$",line)
            if (matches != None):
                handNumber = matches.group(1)
                # CC Added next 3 lines
                localHandNumber = matches.group(2)
                if localHandNumber == '1':
                    startHands = True
                # CC Added if/else condition and else block and indented if block 
                if startHands == True:
                    handTime = datetime.datetime.strptime(matches.group(3),"%Y-%m-%d %H:%M:%S")
                    hands[handNumber] = {LOCAL: matches.group(1),
                                       DATETIME: handTime,
                                       TEXT: ''}
                    line = f.readline()
                    while (not (line.strip() == '')):
                        table = re.search("Table: (.*)$",line)
                        if (table != None):
                            tableName = table.group(1)
                            if (not tableName in tables):
                                tables[tableName] = {COUNT: 0, LATEST: ""}
                            hands[handNumber][TABLE] = tableName
                        hands[handNumber][TEXT] = hands[handNumber][TEXT] + line
                        line = f.readline()
                else:
                    # just skip to next hand
                    while True:
                        line=f.readline()
                        if (line.strip() == ''):
                            break
            else:
                line = f.readline()
        f.close()
StevieG
Posts: 56
Joined: Mon May 04, 2020 12:27 pm

Re: Hand History Parser for obtaining Player Stats

Post by StevieG »

Hi, cchervit.

Thanks for the feedback.

There have been a number of changes and improvements to this since the last time posting the script here.

Most importantly, it is now available in a GitHub repository here: https://github.com/yellowtongue/process-log-mavens

Other improvements include:
  • The addition of the -g or --glob option for Windows users that will allow for wildcard specifications of file names, or whole directories
  • Better handling of fractional figures so that output is always rounded to hundredths
  • Support for player screen names with hyphens and non-ASCII characters
There actually should be no issue with processing multiple files, even with overlap. The same hand should get the same identifier, even in different files, and the script should organize by those identifiers.

Now I do understand that there might be an issue as an operator if you process logs this morning, then play again tonight, and the next day you want to examine only hands from the evening session but they were written to the same file you had already processed.

It could be possible to add an option for a start time and ignore hand before then. I might do that. In the meantime, you could just edit the text file and remove those hands.

Regardless, I recommend using the latest available from the GitHub repository.
cchervit
Posts: 35
Joined: Sat Mar 14, 2020 11:18 pm

Re: Hand History Parser for obtaining Player Stats

Post by cchervit »

StevieG wrote: Now I do understand that there might be an issue as an operator if you process logs this morning, then play again tonight, and the next day you want to examine only hands from the evening session but they were written to the same file you had already processed.

It could be possible to add an option for a start time and ignore hand before then. I might do that. In the meantime, you could just edit the text file and remove those hands.
StevieG,

Yes, this is exactly what's happening. A group of players play on Monday night from 8:30pm-1:30am Tuesday morning. I run a report later that morning to provide to them to settle up their accounts. Then the same group (or with a few changed players) play again on Tuesday night at 8:30pm-1:30am Wednesday morning. If I send in both the Wednedsay log with the Tuesday log, it also adds in the hands from Tuesday midnight-1:30am.

So basically the few lines I added to the script just skip over adding any hands from the first file until I get to the localHandNumber of 1 which is what PokerMavens starts at for the night games in the logs. I'm guessing Kent resets the hand number to 1 every time the table goes to zero players (and I'm glad he does!). So now I don't have to edit the hand result file at all.

And yes, one ideal solution would be to pass in a start time and not count hands until the start time. Or, I think even better would be to add an option to break out the balances by either Table+Persons or just total for each person (as it is now). If broken out by table, you'd add a TableName column/field to balances.csv and for every "table name + localHandNumber of 1", concat a "seating number" to the Table name field, and use that as a primary index (table name + seating number) for the table array. Make sense? So your output would either have totals by names only (like it is now) or "Table HoldEm - Seating 1" and the list of names/balances, "Table HoldEm - Seating 2" and its list of names/balances. That would be especially useful (for me) because I have players that cross over on tables but where each table has a different banker who needs separate results for their tables (we don't have a central banker -- but each home game deals with their own finances).

And thanks for the github link. I'll clone it now!

Chad
cchervit
Posts: 35
Joined: Sat Mar 14, 2020 11:18 pm

Re: Hand History Parser for obtaining Player Stats

Post by cchervit »

Also, StevieG, one more feature request would be to externalize some of the constant values in a JSON/XML file and read them in if there, otherwise use the defaults. That way, they wouldn't need to be typed up again each update (I'm thinking the email values and any note and titles used). Just put in my first new issue in the github with this feature suggestion!
StevieG
Posts: 56
Joined: Mon May 04, 2020 12:27 pm

Re: Hand History Parser for obtaining Player Stats

Post by StevieG »

I like the idea of an external file of constants.

Looks like Python supports .INI style configuration through a standard module

Code: Select all

configparser
so I am likely to use that rather than JSON or XML

The reason being the >INI file supports comments while the JSON format does not.

Look for that sometime soon.
StevieG
Posts: 56
Joined: Mon May 04, 2020 12:27 pm

Re: Hand History Parser for obtaining Player Stats

Post by StevieG »

Updated processLogMavens.py to use an INI file for commonly changed settings.

Good suggestion, cchervit
cchervit
Posts: 35
Joined: Sat Mar 14, 2020 11:18 pm

Re: Hand History Parser for obtaining Player Stats

Post by cchervit »

Awesome, Steve! Just saw the update to the Github project.

Thanks,
Chad
StevieG
Posts: 56
Joined: Mon May 04, 2020 12:27 pm

Re: Hand History Parser for obtaining Player Stats

Post by StevieG »

Chad,

I liked your suggestion of also using the native "Export > Email With Names" as the source file for emails.

The script is updated and the new option in the INI file is EmailExportFile

-Steve
cchervit
Posts: 35
Joined: Sat Mar 14, 2020 11:18 pm

Re: Hand History Parser for obtaining Player Stats

Post by cchervit »

Amazing! Thanks, Steve. BTW, it's such an awesome script to have! Thank you for writing it in the first place.

Chad
StevieG
Posts: 56
Joined: Mon May 04, 2020 12:27 pm

Re: Hand History Parser for obtaining Player Stats

Post by StevieG »

Thanks. It is great that people are getting use out of it.
Post Reply