Register FAQ Search Today's Posts Mark Forums Read
Go Back   JazzJackrabbit Community Forums » Open Forums » General Jazz Jackrabbit Talk

Parse the playlog

DanZeal

JCF Member

Joined: Jan 2008

Posts: 302

DanZeal is an asset to this forum

Apr 17, 2009, 03:25 PM
DanZeal is offline
Reply With Quote
Parse the playlog

Need help to parse the playlog file so it can be submited to a mysql database.
If anyone got some knowledge in this please tell me.
Some progress has already been made with the php code.
__________________

ZStats
"The myth that women should not lift heavy is advanced only by women who fear effort and men who fear women." Eric Midkiff
djazz djazz's Avatar

JCF Member

Joined: Feb 2009

Posts: 257

djazz is OFF DA CHARTdjazz is OFF DA CHARTdjazz is OFF DA CHART

Oct 22, 2009, 06:16 AM
djazz is offline
Reply With Quote
PHP Code:
<?php

// Parse each log from playlog001.txt
$file='./playlog001.txt';
$playLog=array_slice(explode("
[["
,file_get_contents($file)),1);



$playArray=array();
$playLength=count($playArray);
foreach(
$playLog as $key => $value) {
    
    
$playLog[$key]=explode('
'
,$playLog[$key]);
    
array_pop($playLog[$key]);
    
    
$playLog[$key][0]=preg_replace("/(\w+), (\w+) (\d)(\d), (\d)(\d)(\d)(\d) at (\d)(\d):(\d)(\d):(\d)(\d)\]\]/","$1 $2 $3$4, $5$6$7$8 - $9$10:$11$12:$13$14",$playLog[$key][0]);
    
    
$playLog[$key][1]=preg_replace("/\*\*Current level: \"(.*?)\" - (.*?)/","$1 | $2",$playLog[$key][1]);
    
    
$playLog[$key][2]=preg_replace("/\*\*Next level: (.*?)/","$1",$playLog[$key][2]);
    
    
$playLog[$key][3]=preg_replace("/\*\*Game Mode: /","",$playLog[$key][3]);
    
    
$customMode=preg_replace("/\*\*Custom Mode: /","",$playLog[$key][4]);
    if(
$customMode!='OFF'){
        
$playLog[$key][3]=$customMode;
        
//echo $playLog[$key][3];
    
}
    
    
//$playLog[$key][4]=preg_replace("/\[(\d)(\d):(\d)(\d):(\d)(\d)\] >>> Game Start/","$1$2:$3$4:$5$6",$playLog[$key][5]);
    
    
$line=0;
    
$endLine=0;
    for(
$i=5;$i count($playLog[$key]);$i++) {
        if(
strchr($playLog[$key][$i],"*** Game End Stats")){
            
$playLog[$key][4]=preg_replace("/\*\*\* Game End Stats \[\[(\w+), (\w+) (\d)(\d), (\d)(\d)(\d)(\d) at (\d)(\d):(\d)(\d):(\d)(\d)\]\] \*\*\*/","$1 $2 $3$4, $5$6$7$8 - $9$10:$11$12:$13$14",$playLog[$key][$i]);
            
$line=$i+1;
        }
        if(
$line && ($i >= $line) && ($i count($playLog[$key]))) {
            
$tmp=preg_replace("/( +)  /"," | ",$playLog[$key][$i]);
            
$playLog[$key][$i]="";
            
$playLog[$key][$i-$line+5]=trim($tmp,' | 
'
);
            
$endLine=$i-6;
        }
        else {}
    }
    if(
$endLine 0) {
        
//$playLog[$key][count($playLog[$key])]="lol";
        
$playLog[$key]=array_slice($playLog[$key],0,$endLine);
    }
}

print_r($playLog);
?>
Made this some time ago, not working fully yet.
Do whatever you want with it
__________________
WebJCS 2 (new and in progress)
WebJCS 1 (old but complete)
SGIP Simple Games in Progress list
Level Packer v2 - With a GUI!
PHP Tileset Compiler
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT -8. The time now is 02:50 PM.