forum.webdiplomacy.net

webDip dev coordination forum / public access todo list
It is currently Fri Nov 17, 2017 9:06 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Parsing order logs
PostPosted: Sat Feb 25, 2012 4:19 am 
Offline
Site Admin

Joined: Sat Jun 28, 2008 6:24 am
Posts: 892
Since order logs are in JSON format and contain only territory IDs they can be hard to make sense of. This is a bit of shell script which replaces territory IDs in an order log directory with the territory names.

It converts
Code:
Time: Feb 18 2012 22:54:37 (UTC+0)
[{"id": "25587979", "unitID": null, "type": "Build Army", "toTerrID": "31", "fromTerrID": "", "viaConvoy": ""}]

Time: Feb 20 2012 18:54:48 (UTC+0)
[{"id": "25639343", "unitID": "1726033", "type": "Move", "toTerrID": "25", "fromTerrID": "", "viaConvoy": "No", "convoyPath": ["27", "69"]}, {"id": "25639344", "unitID": "1726034", "type": "Hold", "toTerrID": "", "fromTerrID": "", "viaConvoy": ""}, {"id": "25639345", "unitID": "1726035", "type": "Move", "toTerrID": "21", "fromTerrID": "", "viaConvoy": "No"}, {"id": "25639346", "unitID": "1726036", "type": "Move", "toTerrID": "27", "fromTerrID": "", "viaConvoy": "No"}, {"id": "25639347", "unitID": "1735143", "type": "Move", "toTerrID": "32", "fromTerrID": "", "viaConvoy": "No"}]

Time: Feb 20 2012 23:14:00 (UTC+0)
[{"id": "25639343", "unitID": "1726033", "type": "Support move", "toTerrID": "21", "fromTerrID": "28", "viaConvoy": ""}, {"id": "25639344", "unitID": "1726034", "type": "Hold", "toTerrID": "", "fromTerrID": "", "viaConvoy": ""}, {"id": "25639345", "unitID": "1726035", "type": "Move", "toTerrID": "21", "fromTerrID": "", "viaConvoy": "No"}, {"id": "25639346", "unitID": "1726036", "type": "Move", "toTerrID": "80", "fromTerrID": "", "viaConvoy": "No"}, {"id": "25639347", "unitID": "1735143", "type": "Move", "toTerrID": "32", "fromTerrID": "", "viaConvoy": "No"}]

Time: Feb 22 2012 01:11:12 (UTC+0)
[{"id": "25686677", "unitID": "1726034", "type": "Retreat", "toTerrID": "33", "fromTerrID": "", "viaConvoy": ""}]

into
Code:
Time: Feb 18 2012 22:54:37 (UTC+0)
[{id: 25587979, unitID: null, type: Build Army, toTerrID: Moscow

Time: Feb 20 2012 18:54:48 (UTC+0)
type: Move, toTerrID: Armenia, viaConvoy: No, convoyPath: [Sevastopol, Black Sea]
type: Hold
type: Move, toTerrID: Rumania, viaConvoy: No
type: Move, toTerrID: Sevastopol, viaConvoy: No
type: Move, toTerrID: St. Petersburg, viaConvoy: No

Time: Feb 20 2012 23:14:00 (UTC+0)
type: Support move, toTerrID: Rumania, fromTerrID: Ukraine
type: Hold
type: Move, toTerrID: Rumania, viaConvoy: No
type: Move, toTerrID: Bulgaria (North Coast), viaConvoy: No
type: Move, toTerrID: St. Petersburg, viaConvoy: No

Time: Feb 22 2012 01:11:12 (UTC+0)
type: Retreat, toTerrID: Finland


Code:
rm parsed.txt;

# Prepare the order logs, putting them all into one file
cat *.txt | \
   perl -pe 's/\}, \{/\n/g' | \
   perl -pe 's/"id": "[0-9]+", "unitID": "[0-9]+"//g;s/^(\[{)?, //g;s/, "[^"]+": ""//g; s/}\]$//g' > parsed.txt;

# Get the list of cached territory names, so that territory IDs can be replaced
cat ~www/wwwroot/webdiplomacy/variants/Classic/cache/territories.js | \
   perl -ne 's#"id"#\n#g; print' | \
   grep name | \
   perl -ne 'm#"([^"]+)","name":"([^"]+)"# and print "s/\"$1\"/\"$2\"/\n";' | (
   while read a; do
      # For each territory a substitution rule has been generated; run each rule on the order logs
      cat parsed.txt | sed -e "$a" > parsed.txt.tmp;
      
      mv parsed.txt.tmp parsed.txt;
   done
);

# Get rid of the double quotes in the order logs for readability
cat parsed.txt | sed -e 's/"//g' > parsed.txt.tmp;

# Ready to be read
mv parsed.txt.tmp parsed.txt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group