Dominion Strategy Forum

Please login or register.

Login with username, password and session length
Pages: [1] 2 3 ... 8  All

Author Topic: Goko log parser - now for Chrome!  (Read 65769 times)

0 Members and 1 Guest are viewing this topic.

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Goko log parser - now for Chrome!
« on: February 04, 2013, 01:45:37 pm »
+21

Thanks to the efforts of many others, the parser is now available as an extension for Google Chrome: https://chrome.google.com/webstore/detail/goko-log-viewer/kaignighoceeemhinbbophdeogpnedjn

v1.5 allows you to specify input and optionally output files, so you can interface with other scripts or just keep files organized on your computer.

v1.4 addresses player names. Get it here

EDIT: v1.3 deals with the Black Market cases. Attached here

EDIT: v1.2 has been optimized and fixes a bunch of omissions. It's attached to this post in this thread.

EDIT: v1.0 of the Goko log parser is now complete and is attached to this post. Enjoy, and please let me know if you find any bugs!

I am working on a program to parse the Goko logs and add coloring like the Iso logs. I'd appreciate some help from anyone who understands command line scripting, because I'm trying to work from man pages and it's a mess.

What I have so far: I've got a css style sheet that defines the fundamental card types and adds background colors

What I need: a script template for searching a file line-by-line and doing a search-and-replace on a regex script. I can fill in the details for all the card types if I get a template for the following two replace functions:
a) find end of line, add "<br />"
b) find "text string" and the next character can't be an <, replace with <tag>text string</tag> (the "next character can't be an <" rule is necessary so e.g., Village doesn't find Fishing Village. I'll do all the variations first (e.g., Ruined Library, Fishing Village), then the plain versions (Library, Village).

What would be awesome: if anyone knows how to do split colors (like Action-Victory cards) in CSS, that would be great. My guess is it will require images rather than background text coloring, and I don't know how to figure out what size image is needed.

The final version of the script will take a Goko log text file as input, add the HTML document tags and link to the style sheet, and then wrap all the card names with the appropriate tag.

If anyone wants to try it on their own, here are the CSS tags I've established so far:

Code: [Select]
action
 { background-color:rgb(240,240,240) ; }
treasure
 { background-color:rgb(253,225,100) ; }
reaction
 { background-color:rgb(64,168,227) ; }
duration
 { background-color:rgb(254,143,78) ; }
victory
 { background-color:rgb(146,193,125) ; }
curse
 { background-color:rgb(215,138,219) ; }
ruins
 { background-color:rgb(150,104,51) ; }
shelter
 { background-color:rgb(230,108,104) ; }
« Last Edit: February 22, 2013, 01:14:54 pm by philosophyguy »
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Goko log parser - in progress
« Reply #1 on: February 04, 2013, 02:04:03 pm »
+1

I would use sed for that, just from the bash, syntax
Code: [Select]
sed -r "s/regexToSearchFor/ExpressionToReplace/g"
-r for regexes, than "s/"  for this search-replace-mode of sed, it can do other things but I only know how to use /s, then the regexes, and at the end a /g for global replacement.  The "/"s are to seperate the parts and can be any character, in case you need a / in the expressions.

1)
Code: [Select]
sed -r "s/\n/<br>\n/g"
maybe also "\b" or "$" instead of "\n" for the end of line, am not sure, also depends on the format of the log

2) If I understand correctly
Code: [Select]
sed -r "s:(text string)[ˆ<]:<tag>\1</tag>:g"
Note : instead of / because / needed in </tag>

Edit: @css. Councilroom uses background-image
« Last Edit: February 04, 2013, 02:08:06 pm by DStu »
Logged

Qvist

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2400
  • Shuffle iT Username: Qvist
  • Respect: +4085
    • View Profile
Re: Goko log parser - in progress
« Reply #2 on: February 04, 2013, 02:27:08 pm »
0

mameluke

  • Duke
  • *****
  • Offline Offline
  • Posts: 377
  • Respect: +442
    • View Profile
Re: Goko log parser - in progress
« Reply #3 on: February 04, 2013, 03:11:47 pm »
0

You'll need some new ones for the Ruins/Shelters
Logged

Donald X.

  • Dominion Designer
  • *****
  • Offline Offline
  • Posts: 6363
  • Respect: +25699
    • View Profile
Re: Goko log parser - in progress
« Reply #4 on: February 04, 2013, 03:26:41 pm »
+2

The current logs aren't necessarily the final ones; people should speak up about how they'd like the logs to be different. Not that it will change soon but you know.
Logged

Polk5440

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1708
  • Respect: +1788
    • View Profile
Re: Goko log parser - in progress
« Reply #5 on: February 04, 2013, 03:54:53 pm »
0

The current logs aren't necessarily the final ones; people should speak up about how they'd like the logs to be different. Not that it will change soon but you know.

Good. They are hard to read. Is there a thread started here or on getsatisfaction devoted to suggestions for improving the log format?
Logged

Beyond Awesome

  • Global Moderator
  • *****
  • Offline Offline
  • Posts: 2941
  • Shuffle iT Username: Beyond Awesome
  • Respect: +2466
    • View Profile
Re: Goko log parser - in progress
« Reply #6 on: February 04, 2013, 04:00:13 pm »
0

This is awesome!
Logged

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9412
    • View Profile
Re: Goko log parser - in progress
« Reply #7 on: February 04, 2013, 04:21:26 pm »
0

The current logs aren't necessarily the final ones; people should speak up about how they'd like the logs to be different. Not that it will change soon but you know.

Good. They are hard to read. Is there a thread started here or on getsatisfaction devoted to suggestions for improving the log format?

I'd suggest creating a thread here, then posting a generalized consensus to the getsatisfaction thing.
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - in progress
« Reply #8 on: February 04, 2013, 04:28:23 pm »
+1

I've made images for all the dual-card types thus far. Who is running Councilroom now that I can ask to host them?
Logged

theory

  • Administrator
  • *****
  • Offline Offline
  • Posts: 3603
  • Respect: +6125
    • View Profile
    • Dominion Strategy
Re: Goko log parser - in progress
« Reply #9 on: February 04, 2013, 04:48:40 pm »
0

Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - in progress
« Reply #10 on: February 04, 2013, 06:49:22 pm »
+1

Ok, the parser is almost functional. (I have no idea about performance yet.) But, for the last part I could use some help with script looping.

What I want to do:
Take an input file, read one line at a time, and substitute in the line for a variable in a shell command; take the resulting new command and append it to another file

What I mean:
I have a file that lists all the Dominion cards, sorted by type. I want to go through that file line by line and substitute the card name into the shell command that will parse the file.
So, line 1 = Adventurer: take "sed command with SOME_ACTION_CARD" and output "sed command with Adventurer", appending that output to the bash script I'm generating. Repeat for lines 2 through...

Thank you to those kind comp sci folks who are taking pity on a humanities major. :)
Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - v1.0 DONE
« Reply #11 on: February 04, 2013, 08:51:02 pm »
0

v1.0 of the parser is now done and is attached to the first post in this thread. Please let me know if you find bugs!
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Goko log parser - v1.0 DONE
« Reply #12 on: February 05, 2013, 03:48:23 am »
0

v1.0 of the parser is now done and is attached to the first post in this thread. Please let me know if you find bugs!

If you pipe all the seds, it is about twice as fast:
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Goko log parser - v1.0 DONE
« Reply #13 on: February 05, 2013, 05:11:10 am »
0

You get another factor of 5(!) in speed if you don't check for all the cards, but build the command on the fly with just the cards that are in the supply
put the whole command to goko-log-core.sh and

Code: [Select]
# Extract the cards that are used this game. Edgecases to consider: Tournament, Spoils, Shelters etc.pp.
less logfile.txt | grep -m 1 -E '^Supply cards:' | sed "s/Supply cards://g" | sed -E 's/ ([^,]*)(,)/\(\1\)\|/g'  | sed -E 's/ ([^\)]*)($)/\(\1\)/g' | xargs -I{} grep -E '{}' goko-log-parser-core.sh > tempscript.sh
less gokolog.txt | ./tempscript.sh

Probably it's another bit faster if you can do also without writing the command to ./tempscript ,but I can't at the moment.


This has some issues still, first, it doesn't care for cards that are not in the supply (Prizes, Spoils, Shelters, etc), easiest solution is to keep them in always, shouln't cost that much time. Funnier of course would be some method to trigger Tournament->Prizes. Second it's not optimal because I have some problems with the interplay of grep, xargs and brackets, so a e.g."Village" in the supply keeps all kind of Villages in the expression. Which is not that important, but also not that bad.
Third, it's not tested much, so probably there are more edge cases...
Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - v1.0 DONE
« Reply #14 on: February 05, 2013, 10:22:12 am »
0

I'm still working on understanding DStu's commands, but I think there's a workaround for the stuff not in the Supply. In the core file, we'll put
Code: [Select]
sed stuff for Trusty Steed # (Tournament)
The grep should pick out the Trusty Steed line if Tournament is in the Supply that way.

I found a couple of errors in the script last night (wrong tag for Market Square, forgot Venture completely, a couple of cards listed twice and hence creating errors). I'll see what I can do to clean these up once I finish stepping through DStu's command line-fu.

Thanks for the help all!
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Goko log parser - v1.0 DONE
« Reply #15 on: February 05, 2013, 10:33:54 am »
0

OK, should have been a little bit more commented
Code: [Select]
less logfile.txt | grep -m 1 -E '^Supply cards:' | sed "s/Supply cards://g" | sed -E 's/ ([^,]*)(,)/\(\1\)\|/g'  | sed -E 's/ ([^\)]*)($)/\(\1\)/g' | xargs -I{} grep -E '{}' goko-log-parser-core.sh > tempscript.sh
What's the plan.
Code: [Select]
less logfile.txt # take the logfile
| grep -m 1 -E '^Supply cards:' #find the line that mentions the supply. Should be the first mention (grep -m 1) of the line that starts with "Supply cards"
|  sed "s/Supply cards://g" # OK, actually we aren't interested in the part that says "Supply cards", but on the rest of the line where the cards are mentioned, which is comma-seperated card names...
| sed -E 's/ ([^,]*)(,)/\(\1\)\|/g' # ... which we would like to transform into a regular expression for grep. Therefore, take everything leading blank and the next comma  ([^,]*)(,), and but brackets around it, finish it of with a | \(\1\)\|
| sed -E 's/ ([^\)]*)($)/\(\1\)/g' # the last entry does not end with a comma, so special case here
| xargs -I{} grep -E '{}' goko-log-parser-core.sh # now take the string we have constructed until here, which should be (card1)|(card2)|(card3)|.... use it as pattern for grep on the fule goko-log-parser-core.sh, so that only the lines which mention cards that are already in the supply survive

@Prizes: Yepp, elegant solution


« Last Edit: February 05, 2013, 10:36:29 am by DStu »
Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - v1.0 DONE
« Reply #16 on: February 05, 2013, 11:51:21 am »
0

Yup, figured out your code. I was thrown for a minute because I assumed the pipes were separators of some sort and couldn't figure out why grep knew to iterate through them, before realizing it was an OR.

Attached is the new version. It should handle edge cases except for Black Market. I can do the # (Black Market) trick on every line to cheat that one, but I don't know if there's a cleaner way.
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Goko log parser - v1.0 DONE
« Reply #17 on: February 05, 2013, 11:55:45 am »
0

Yup, figured out your code. I was thrown for a minute because I assumed the pipes were separators of some sort and couldn't figure out why grep knew to iterate through them, before realizing it was an OR.

Attached is the new version. It should handle edge cases except for Black Market. I can do the # (Black Market) trick on every line to cheat that one, but I don't know if there's a cleaner way.
Code: [Select]
| sed "s/Black Market//g" | #If Black Market is in the kingdom, just match everything, and so take the complete goko-log-parser-core.sh

Edit: just transforme "|Black Market|" to "||", and thus match everything between the last sed and the xargs.
« Last Edit: February 05, 2013, 12:03:37 pm by DStu »
Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
v1.3: Re: Goko log parser
« Reply #18 on: February 05, 2013, 12:10:37 pm »
0

Ok, Black Market is supported. v1.3 is here.
Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - v1.3 DONE
« Reply #19 on: February 05, 2013, 12:27:19 pm »
0

And I think I figured out a way to handle the "Occupy Grand Market" style player names. Working on the code now…
Logged

Drab Emordnilap

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1832
  • Shuffle iT Username: Drab Emordnilap
  • Luther Bell Hendricks V
  • Respect: +1887
    • View Profile
Re: Goko log parser - v1.3 DONE
« Reply #20 on: February 05, 2013, 12:40:07 pm »
+2

Just don't forget the lessons of little Bobby Tables...
Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - v1.3 DONE
« Reply #21 on: February 05, 2013, 01:04:17 pm »
0

Just don't forget the lessons of little Bobby Tables...

I am aware of all internet traditions. :)
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Goko log parser - v1.3 DONE
« Reply #22 on: February 05, 2013, 01:07:52 pm »
+4

Just don't forget the lessons of little Bobby Tables...

I think the biggest thread is Donald making
Quote
" & rm -rf / ~ #
Action-Atttack
Trash your whole deck
in Guilds.
Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - v1.3 DONE
« Reply #23 on: February 05, 2013, 01:24:48 pm »
+3

Code: [Select]
" & sudo rm -rf / ~ #
Action-Attack

Enter your password. If you do, trash your deck (including this card).
---
If this is in the Trash, you cannot gain any cards from the Trash.
Logged

philosophyguy

  • Minion
  • *****
  • Offline Offline
  • Posts: 575
  • Respect: +299
    • View Profile
Re: Goko log parser - v1.4 DONE
« Reply #24 on: February 05, 2013, 04:53:03 pm »
0

v1.4 keeps player names from being wrapped in tags if you've got a name like Occupy Grand Market.

Hopefully I've avoided the Bobby Tables problem by just having the computer handle the names, but here's the key code in case anyone wants to see if I missed something.

Code: [Select]
cat playernames.txt | while read line
do
player=$line
playernum=`grep -n "$player" playernames.txt | sed -E "s:([0-9])(.*):\1:"`
sed -E "s:^($player):Player$playernum:g" gokolog.txt | # Get player names at the start of the line
sed -E "s,$player: turn,Player$playernum: turn,g" | # Player names in the middle of the turn
sed -E "s,^([0-9][A-z]{2} place: )$player,\1Player$playernum,g" > gokolog.txt.tmp # Player names in first-nth place
mv gokolog.txt.tmp gokolog.txt
done
Logged
Pages: [1] 2 3 ... 8  All
 

Page created in 0.067 seconds with 21 queries.