Jump to content

Parsing Text Files?


Kaptin Gavrin

Recommended Posts

I'm trying to help someone with coding a PHP/MySQL-based site for a sports league using Madden NFL 2008.  The problem is that we haven't been able to figure out how to parse the game's log files, which are TXT files, in such a way that we can upload the data within them to the database.  Passing stats would go into a passing stats table, defensive stats into a defense table, etc.  If someone could help me understand how to do this, or even where to start with such a complex file, I'd be very grateful.  I'll give an example of a game log TXT file and a league.txt file.  Just use "gamelog.txt" and "league.txt" for refering to them.

 

gamelog.txt:

Madden NFL 08 PC v 3.0 Game Log - Lions at Bears
Game Time: Wed Oct 03 10:41:58 2007
Skill Level: All Pro
Quarter Length: 12 minute(s)

Slider                         Human   CPU
QB Accuracy                       56    56
Pass Blocking                     20    20
Receiver Catching                 70    70
Running Ability                   62    62
Offensive line Run Blocking       57    57
Defensive Awareness               50    50
Defensive line Knockdowns         20    20
Interceptions                      3     3
Defensive Break Blocks            15    15
Tackling                          50    50
Fieldgoal Length                  40    40
Fieldgoal Accuracy                99    99
Punt Length                       56    56
Punt Accuracy                     92    92
Kickoff Length                    57    57

Weather
Forecast: Fair
Wind: 4 mph
Temp: 74 degrees

Team               Q1   Q2   Q3   Q4   OT      FINAL
Lions               3    3    0    0    0          6
Bears               7    3    0    0    0         10

Game was not completed.

Game Statistics:                    Lions      Bears
First Downs                             8          6
Third Down Conversions                  1          3
Third Downs                             5          4
Third Down Percentage               20.0%      75.0%
Fourth Down Conversions                 0          0
Fourth Downs                            0          0
Fourth Down Percentage               0.0%       0.0%
Two Pt Conversions Made                 0          0
Two Pt Conversions Attempted            0          0
Two Pt Conversion Percentage         0.0%       0.0%
Offense Redzone Num                     1          1
Offense Redzone TDs                     0          1
Offense Redzone FGs                     1          0
Offense Redzone Percentage         100.0%     100.0%
Rushing Attempts                       15          9
Rushing Yards                          32         33
Rushing Average                       2.1        3.7
Rushing TDs                             0          0
Passing Yards                          63         90
Passing Completions                     6          5
Passing Attempts                       10          8
Completion Percentage               60.0%      62.5%
Passing Average                       6.3       11.3
Passing TDs                             0          1
Offensive Pass Interceptions            0          0
TOTAL OFFENSE                          95        123
Defensive Pass Interceptions            0          0
Punt Return Yards                       0          0
Kick Return Yards                      52         17
Punts                                   0          0
Punt Avg                              0.0        0.0
Fumbles                                 1          0
Fumbles Lost                            1          0
Penalties                               0          1
Penalty Yds                             0          5
Turnovers                               1          0
TIME OF POSSESSION                  11:04      07:38

Individual Stats: Bears
PASSING                        CMP  ATT  YDS  PCT   YPA SACK   TD  INT LONG RATING
Marc Bulger                      5    8   90   62  11.2    0    1    0   42  140.6

RUSHING                        ATT  YDS   AVG LONG   TD  FUM
Cedric Benson                    8   26   3.2    9    0    0
Vernand Morency                  1    7   7.0    7    0    0

RECEIVING                      REC  YDS   AVG LONG   TD DROP  YAC
Sidney Rice                      2   63  31.5   42    0    1   10
Mark Bradley                     1   19  19.0   19    0    0    6
Desmond Clark                    1    7   7.0    7    0    0    0
Bernard Berrian                  1    1   1.0    1    1    0    0

KICKING                        FGM  FGA  PCT FGSBLOCKED  XPA  XPM  PCT XPSBLOCKED KICKOFFS TOUCHBACKS
Robbie Gould                     1    1  100          0    1    1  100          0        3          1

PUNTING                        ATT  YDS   AVG LONG BLOCKS IN20 TOUCHBACKS
No stats.

KICK RETURNS                   ATT  YDS   AVG   TD LONG
Mark Bradley                     1   17  17.0    0   17

PUNT RETURNS                   ATT  YDS   AVG LONG   TD
Mark Bradley                     0    0   0.0    0    0

DEFENSE                        TOT LOSS SACK   FF FREC  YDS   TD  INT  RET   AVG DEFLECTIONS SAFETIES CTH ALLOW BIG HITS
Dedric Brown                     4    0    0    0    0    0    0    0    0   0.0           0        0         1        0
Adewale Ogunleye                 4    2    0    0    1    5    0    0    0   0.0           0        0         0        0
Brian Urlacher                   3    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Nathan Vasher                    2    0    0    0    0    0    0    0    0   0.0           0        0         2        0
Leon Hall                        2    0    0    0    0    0    0    0    0   0.0           0        0         1        0
Tommie Harris                    1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Dwight Freeney                   1    1    0    1    0    0    0    0    0   0.0           0        0         0        0
Dez Dorsey                       1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Takeo Spikes                     1    1    0    0    0    0    0    0    0   0.0           0        0         0        0
Josh Gattis                      1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Abdul Hodge                      1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Danieal Manning                  1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Cletidus Hunt                    0    0    0    0    0    0    0    0    0   0.0           1        0         0        0
Marlin Jackson                   0    0    0    0    0    0    0    0    0   0.0           0        0         0        0

BLOCKING                      PANCAKES SACKS ALLOWED
Desmond Clark                        3             0
John Tait                            3             0
Corey Hilliard                       2             0
Mark Bradley                         1             0
Jason Snelling                       1             0
Anthony Pudewell                     1             0
Deuce Lutui                          1             0


Individual Stats: Lions
PASSING                        CMP  ATT  YDS  PCT   YPA SACK   TD  INT LONG RATING
Drew Bledsoe                     6   10   63   60   6.2    0    0    0   22   78.3

RUSHING                        ATT  YDS   AVG LONG   TD  FUM
Brandon Jacobs                  12   35   2.9   11    0    0
Shawn Bryson                     1    3   3.0    3    0    0
Brian Westbrook                  1    0   0.0    0    0    0
Drew Bledsoe                     1   -6  -6.0    0    0    1

RECEIVING                      REC  YDS   AVG LONG   TD DROP  YAC
Vincent Jackson                  3   33  11.0   21    0    0    1
George Wrighster                 1   22  22.0   22    0    0    0
Reggie Williams                  2    8   4.0    7    0    0    3
Mike Furrey                      0    0   0.0    0    0    1    0

KICKING                        FGM  FGA  PCT FGSBLOCKED  XPA  XPM  PCT XPSBLOCKED KICKOFFS TOUCHBACKS
Mike Nugent                      2    2  100          0    0    0    0          0        2          1

PUNTING                        ATT  YDS   AVG LONG BLOCKS IN20 TOUCHBACKS
No stats.

KICK RETURNS                   ATT  YDS   AVG   TD LONG
Skyler Green                     2   52  26.0    0   30

PUNT RETURNS                   ATT  YDS   AVG LONG   TD
Skyler Green                     0    0   0.0    0    0

DEFENSE                        TOT LOSS SACK   FF FREC  YDS   TD  INT  RET   AVG DEFLECTIONS SAFETIES CTH ALLOW BIG HITS
Boss Bailey                      3    0    0    0    0    0    0    0    0   0.0           0        0         1        0
Ernie Sims                       3    1    0    0    0    0    0    0    0   0.0           0        0         1        0
Daniel Bullocks                  2    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Brandon Jacobs                   1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Brian Robison                    1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Sam Olajubutu                    1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Fernando Bryant                  1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Teddy Lehman                     1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
J.D Nelson                       1    0    0    0    0    0    0    0    0   0.0           0        0         0        0

BLOCKING                      PANCAKES SACKS ALLOWED
Rex Tucker                           4             0
Damien Woody                         2             0
Adam Bergen                          2             0
George Wrighster                     1             0
Brandon Jacobs                       1             0
Dan Santucci                         1             0
Winston Justice                      1             0
Shawn Bryson                         1             0
Dominic Raiola                       1             0


Game Log Ends
------------------------------------------------------------

 

 

 

league.txt:

LEAGUE STANDINGS
====================================================================

                                       AFC North                                       
TEAM                WINS LOSSES TIES PCT    PF  PA   HOME ROAD  AFC  NFC   DIV  STREAK 
Bengals             3    0      0    1.000  56  37   2-0  1-0   2-0  1-0   1-0  Won 3  
Ravens              3    0      0    1.000  115 66   0-0  3-0   1-0  2-0   1-0  Won 3  
Browns              2    1      0    0.666  113 74   0-1  2-0   1-1  1-0   0-1  Won 1  
Steelers            0    3      0    0.000  58  69   0-3  0-0   0-2  0-1   0-1  Lost 3 

                                       AFC South                                       
TEAM                WINS LOSSES TIES PCT    PF  PA   HOME ROAD  AFC  NFC   DIV  STREAK 
Jaguars             2    1      0    0.666  81  82   1-0  1-1   2-0  0-1   1-0  Won 2  
Texans              2    1      0    0.666  82  71   1-1  1-0   2-1  0-0   0-0  Won 2  
Titans              1    1      0    0.500  55  57   1-0  0-1   1-0  0-1   1-0  Won 1  
Colts               0    3      0    0.000  70  90   0-0  0-3   0-3  0-0   0-2  Lost 3 

                                       AFC East                                       
TEAM                WINS LOSSES TIES PCT    PF  PA   HOME ROAD  AFC  NFC   DIV  STREAK 
Patriots            3    0      0    1.000  128 70   0-0  3-0   3-0  0-0   2-0  Won 3  
Bills               2    1      0    0.666  90  61   1-1  1-0   2-1  0-0   2-1  Won 1  
Dolphins            0    3      0    0.000  19  54   0-1  0-2   0-3  0-0   0-1  Lost 3 
Jets                0    3      0    0.000  32  92   0-1  0-2   0-2  0-1   0-2  Lost 3 

                                       AFC West                                       
TEAM                WINS LOSSES TIES PCT    PF  PA   HOME ROAD  AFC  NFC   DIV  STREAK 
Chargers            3    0      0    1.000  49  31   1-0  2-0   3-0  0-0   2-0  Won 3  
Broncos             2    1      0    0.666  87  57   1-1  1-0   1-1  1-0   1-1  Won 1  
Chiefs              1    2      0    0.333  75  79   1-2  0-0   1-2  0-0   1-1  Lost 1 
Raiders             0    3      0    0.000  66  91   0-2  0-1   0-3  0-0   0-2  Lost 3 

                                       NFC North                                       
TEAM                WINS LOSSES TIES PCT    PF  PA   HOME ROAD  AFC  NFC   DIV  STREAK 
Bears               3    0      0    1.000  80  37   2-0  1-0   0-0  3-0   3-0  Won 3  
Vikings             2    0      0    1.000  55  44   2-0  0-0   1-0  1-0   0-0  Won 2  
Lions               1    1      0    0.500  49  56   1-0  0-1   1-0  0-1   0-1  Lost 1 
Packers             1    2      0    0.333  60  70   1-1  0-1   0-0  1-2   0-2  Lost 1 

                                       NFC South                                       
TEAM                WINS LOSSES TIES PCT    PF  PA   HOME ROAD  AFC  NFC   DIV  STREAK 
Falcons             3    0      0    1.000  111 58   0-0  3-0   0-0  3-0   2-0  Won 3  
Panthers            1    2      0    0.333  63  93   0-0  1-2   0-1  1-1   1-0  Lost 2 
Saints              1    2      0    0.333  61  79   1-2  0-0   0-0  1-2   1-2  Won 1  
Buccaneers          0    3      0    0.000  56  95   0-1  0-2   0-0  0-3   0-2  Lost 3 

                                       NFC East                                       
TEAM                WINS LOSSES TIES PCT    PF  PA   HOME ROAD  AFC  NFC   DIV  STREAK 
Giants              3    0      0    1.000  72  50   2-0  1-0   0-0  3-0   1-0  Won 3  
Cowboys             1    2      0    0.333  47  100  0-1  1-1   1-1  0-1   0-1  Lost 2 
Redskins            0    3      0    0.000  63  102  0-2  0-1   0-1  0-2   0-0  Lost 3 
Eagles              0    2      0    0.000  29  51   0-1  0-1   0-2  0-0   0-0  Lost 2 

                                       NFC West                                       
TEAM                WINS LOSSES TIES PCT    PF  PA   HOME ROAD  AFC  NFC   DIV  STREAK 
49ers               2    1      0    0.666  96  89   1-0  1-1   0-0  2-1   1-1  Won 2  
Cardinals           2    1      0    0.666  67  63   2-1  0-0   1-0  1-1   0-0  Lost 1 
Seahawks            1    2      0    0.333  84  80   1-1  0-1   0-0  1-2   1-0  Lost 2 
Rams                1    2      0    0.333  73  94   1-0  0-2   0-0  1-2   0-1  Lost 1 

    x=Clinched playoff birth
    y=Clinched divisional title
    z=Clinched home-field advantage

 

Link to comment
Share on other sites

Code is pretty easy, just going to take a while because the file is big. This should get you started, it reads in the gamelog data down to slider's stats, after that it's just more of the same.

 

<?php

$lines = file("gamelog.txt");

preg_match("/: (.*)/", $lines[1], $match);
$gameTime = $match[1];
preg_match("/: (.*)/", $lines[2], $match);
$skillLevel = $match[1];
preg_match("/: (.*)/", $lines[3], $match);
$quarterLength = $match[1];

$slider = array();

$t = 6;

do{
   preg_match_all("/[\w]+/", $lines[$t++], $matches);
   
   $matches = $matches[0];
   $stat = "";
   
   if(count($matches) < 2) break;

   while(count($matches) > 2)
   	 $stat .= array_shift($matches) . " ";
   	 
   $stat = trim($stat);
   
   $slider[] = array('stat' => $stat, 'human' => $matches[0], 'cpu' => $matches[1]);
}while(1);

print_r($slider);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.