Getting Data From a .txt File

Hello,

I am having some trouble with the logic for a project. I am trying to extract data from a .txt file. The data comes in chunks within a single text file. As an example, a text document might look like this:

This is the start of a chunk
This line has data
This line has data
This line has data
This is the end of a chunk

This is the start of a chunk
This line has data
This line has data
This line has data
This line has data
This line has data
This is the end of a chunk

What I am trying to do is write code that will take all the lines from the start of a chunk to the end of a chunk, store it somewhere in the program where I can do more detailed analysis on that chunk, then repeat the process for the next chunk. A typical .txt file can have anywhere from 20 to 400 different chunks of data. What is the best way to break this text file apart into it’s relevant chunks of data?

I have tried “copying” each chunk into an Array but I am having trouble understanding exactly how to accomplish it.

Thank you for the help.

Can you post a few lines of your data?

Kf

Hey there, I would suggest taking a look at the loadStrings() function? You can see its documentation here:

https://processing.org/reference/loadStrings_.html

And also, the splitTokens() function, which uses a delim parameter of a character:

https://processing.org/reference/splitTokens_.html

With a little bit of modification to where you want your data to start and end? I think these will be able to help you out!

P.S.: A little bit of a different approach, if you want to change your data file from being a .txt, you can also learn about JSON’s, which are great for holding data for your projects, and aren’t too hard to use! If you’d like to, you can see about about them on the Processing website here:

https://processing.org/reference/JSONObject.html

Hope this helps!

EnhancedLoop7

Hey everyone,

Thanks for the help so far. I am actually looking at loadstrings() as well as the main functions to manipulate the data like join() and split() for example. My question is more about the logic of pulling the data.

To be a little more specific, the project I am working on is dealing with hand history data from hands I have played on an online poker site. The hand histories show all the hands that all players at the table had. What I would like to do as a starting point is find out what types of hands players are opening with from each position at the table.

This data comes to me in a standard .txt format. Each hand is listed one after the other from a particular table. I have at this point close to 100 hand history files, each of which contains anywhere from 20-400 individual hand histories.

I am having trouble grasping what the best way to store this data in the Processing sketch would be. Should I be creating objects for each hand that will have analysis done on them individually? Is it more useful to store these String[] hand histories into a 2d array?

Thanks again for any help. Just talking about the project has been very helpful and is getting me to think more about how to structure the project long term.

Below is a sample of what two hands would look like in a text file.

Bovada Hand #3630881295 Zone Poker ID#1257 HOLDEMZonePoker No Limit - 2018-07-16 22:23:43
Seat 1: UTG+2 ($10.30 in chips)
Seat 2: Dealer ($66.94 in chips)
Seat 3: Small Blind ($64.82 in chips)
Seat 4: Big Blind [ME] ($12.50 in chips)
Seat 5: UTG ($16.68 in chips)
Seat 6: UTG+1 ($9.47 in chips)
Dealer : Set dealer [2]
Small Blind : Small Blind $0.10
Big Blind [ME] : Big blind $0.25
*** HOLE CARDS ***
UTG+2 : Card dealt to a spot [2c 5s]
Dealer : Card dealt to a spot [8h 5h]
Small Blind : Card dealt to a spot [9s Jd]
Big Blind [ME] : Card dealt to a spot [3s 8c]
UTG : Card dealt to a spot [Jc 4d]
UTG+1 : Card dealt to a spot [Qs 6c]
Small Blind : Leave(Auto)
UTG : Folds
UTG : Leave(Auto)
Dealer : Leave(Auto)
UTG+1 : Folds
UTG+1 : Leave(Auto)
UTG+2 : Folds
UTG+2 : Leave(Auto)
Dealer : Folds
Small Blind : Folds
Big Blind [ME] : Does not show [3s 8c] (High Card)
Big Blind [ME] : Hand result $0.35
Big Blind [ME] : Leave(Auto)
Enter(Auto)
Small Blind : Enter(Auto)
Enter(Auto)
Enter(Auto)
Enter(Auto)
Enter(Auto)
*** SUMMARY ***

Bovada Hand #3630881440 Zone Poker ID#1257 HOLDEMZonePoker No Limit - 2018-07-16 22:24:00
Seat 1: Big Blind ($25 in chips)
Seat 2: UTG ($37.32 in chips)
Seat 3: UTG+1 ($23.29 in chips)
Seat 4: UTG+2 ($31.78 in chips)
Seat 5: Dealer [ME] ($12.60 in chips)
Seat 6: Small Blind ($36.92 in chips)
Dealer [ME] : Set dealer [5]
Small Blind : Small Blind $0.10
Big Blind : Big blind $0.25
*** HOLE CARDS ***
Big Blind : Card dealt to a spot [Ac 4s]
UTG : Card dealt to a spot [5h 7h]
UTG+1 : Card dealt to a spot [8h Kh]
UTG+2 : Card dealt to a spot [Kd Ah]
Dealer [ME] : Card dealt to a spot [8c 3c]
Small Blind : Card dealt to a spot [Ad Ts]
UTG : Folds
UTG : Leave(Auto)
UTG+1 : Folds
UTG+1 : Leave(Auto)
UTG+2 : Raises $1.25 to $1.25
Dealer [ME] : Folds
Dealer [ME] : Leave(Auto)
Big Blind : Leave(Auto)
Small Blind : Folds
Small Blind : Leave(Auto)
Big Blind : Folds
UTG+2 : Return uncalled portion of bet $1
UTG+2 : Does not show [Kd Ah] (High Card)
UTG+2 : Hand result $0.60
UTG+2 : Leave(Auto)
Enter(Auto)
Big Blind : Enter(Auto)
Enter(Auto)
Enter(Auto)
Enter(Auto)
Enter(Auto)
*** SUMMARY ***
Total Pot($0.60)
Seat+1: Big Blind lost with High Card [Ac 4s]
Seat+2: UTG Folded before the RIVER
Seat+3: UTG+1 Folded before the RIVER
Seat+4: UTG+2 $0.60 [Does not show]
Seat+5: Dealer Folded before the RIVER
Seat+6: Small Blind Folded before the RIVER

Hi :slight_smile:

It really all depends of what you want to do with those data afterwards. You spoke about doing detailed analysis in you first post so you need to figure out what kind of analysis you want to perform with which data and what would be the storage format that would allow you do to it the more easily.

If you just need to have access to the cards played in the right order then a 1d array would be sufficient and a special character in your array could represent the end of a game so you have a additional information for free.

Now if you also need some additional information like the player name you can either use a 2d array or create a new class (let’s call it Turn) to store all the data of a turn and then store those Turn object in a 1d array.

You can even be more fancy and create several class: one for a game and one for a turn played for exemple. Whit that, you can store all the game in 1 array and that will be the game object that will have to store all the turns played.

If you still can’t figure out how to store your data, explain what you want to do in more detail so wa can elp you figure it out :wink:

jb4x:
It really all depends of what you want to do with those data afterwards

I have a list of things I would like to do initially, but I have used Poker Tracker software in the past and the options they provide can be very expansive. Part of the reason I am doing this project is that I felt like buying their software for $200 when I only use about 10% of it seemed silly. Most of what I want to do now is some data visualization regarding:

What types of hands are players opening for a bet in each position at the table?
What types of hands are players calling a bet with in each position at the table?
What types of haves are players raising with?
Answer the above questions for preflop, on the flop, on the turn, and on the river.

So for example, let’s look at the below hand.

Bovada Hand #3630881440 Zone Poker ID#1257 HOLDEMZonePoker No Limit - 2018-07-16 22:24:00
Seat 1: Big Blind ($25 in chips)
Seat 2: UTG ($37.32 in chips)
Seat 3: UTG+1 ($23.29 in chips)
Seat 4: UTG+2 ($31.78 in chips)
Seat 5: Dealer [ME] ($12.60 in chips)
Seat 6: Small Blind ($36.92 in chips)
Dealer [ME] : Set dealer [5]
Small Blind : Small Blind $0.10
Big Blind : Big blind $0.25
*** HOLE CARDS ***
Big Blind : Card dealt to a spot [Ac 4s]
UTG : Card dealt to a spot [5h 7h]
UTG+1 : Card dealt to a spot [8h Kh]
UTG+2 : Card dealt to a spot [Kd Ah]
Dealer [ME] : Card dealt to a spot [8c 3c]
Small Blind : Card dealt to a spot [Ad Ts]
UTG : Folds
UTG : Leave(Auto)
UTG+1 : Folds
UTG+1 : Leave(Auto)
UTG+2 : Raises $1.25 to $1.25
Dealer [ME] : Folds
Dealer [ME] : Leave(Auto)
Big Blind : Leave(Auto)
Small Blind : Folds
Small Blind : Leave(Auto)
Big Blind : Folds
UTG+2 : Return uncalled portion of bet $1
UTG+2 : Does not show [Kd Ah] (High Card)
UTG+2 : Hand result $0.60
UTG+2 : Leave(Auto)
Enter(Auto)
Big Blind : Enter(Auto)
Enter(Auto)
Enter(Auto)
Enter(Auto)
Enter(Auto)
*** SUMMARY ***
Total Pot($0.60)
Seat+1: Big Blind lost with High Card [Ac 4s]
Seat+2: UTG Folded before the RIVER
Seat+3: UTG+1 Folded before the RIVER
Seat+4: UTG+2 $0.60 [Does not show]
Seat+5: Dealer Folded before the RIVER
Seat+6: Small Blind Folded before the RIVER

I would like to keep a log in the database of all the hands that a player from UTG+2 opens for a bet with. In this case, I would like this hand to be scanned and have the hand [Kd Ah] added into the log of UTG+2 hands. Since there is no practical difference between any two card combination of the same card ranks that is unsuited (KdAh, AsKc, KdAc, etc) I just need to log this hand as AKo (o = offsuit).

I have been tinkering with using the 2d array for the hand histories. So far I have code that stores all the information from a .txt file. Now I’m trying to figure out the logic for how to start manipulating the data.