Jump to content

Recommended Posts

I play an online car sim, GTR, and after a race it creates a log file that I want to parse and write to a database. I've not any experience with parsing logs - I'm not asking how to write the actual script but I need suggestions on how to approach this problem. Here is a portion of the log:

//[[gMa1.000f©2004 SBDT]] [[]]

[Header]
Game=GTR
Version=1.400
TimeString=2006/03/16 21:52:24
Aids=0,0,0,0,0,1,0,0,0

[Race]
RaceMode=5
Scene=GAMEDATA\LOCATIONS\Barcelona\Barcelona.TRK
AIDB=GAMEDATA\LOCATIONS\Barcelona\Barcelona.AIW
Race Length=0.200
Track Length=4718.9307

[Slot007]
Driver=C_Bex
Vehicle=Saleen Teams - S7-R
Team=Konrad Motorsport
Penalty=0
QualTime=1:50.335
Laps=6
Lap=(0, -1.000, 3:03.475)
Lap=(1, 223.820, 2:08.530)
Lap=(2, 352.349, 2:00.438)
Lap=(3, 472.787, 1:50.591)
Lap=(4, 583.378, 2:08.462)
Lap=(5, 711.840, 2:23.195)
LapDistanceTravelled=1667.881348
BestLap=1:50.591
RaceTime=DNF
Reason=0

[Slot000]
Driver=BH
Vehicle=Ferrari Teams - 360 Modena
Team=Menx
Penalty=0
QualTime=1:48.111
Laps=19
Lap=(0, -1.000, 3:01.972)
Lap=(1, 222.317, 1:55.995)
Lap=(2, 338.312, 1:50.358)
Lap=(3, 448.671, 1:53.831)
Lap=(4, 562.502, 1:50.526)
Lap=(5, 673.028, 1:51.130)
Lap=(6, 784.158, 1:49.784)
Lap=(7, 893.941, 1:53.135)
Lap=(8, 1007.077, 1:51.039)
Lap=(9, 1118.116, 1:50.883)
Lap=(10, 1228.999, 1:50.778)
Lap=(11, 1339.777, 1:50.370)
Lap=(12, 1450.147, 1:51.789)
Lap=(13, 1561.937, 2:06.571)
Lap=(14, 1688.507, 2:09.218)
Lap=(15, 1817.725, 2:09.650)
Lap=(16, 1947.375, 3:25.906)
Lap=(17, 2153.281, 2:15.009)
Lap=(18, 2288.290, 2:04.894)
LapDistanceTravelled=4599.286621
BestLap=1:49.784
RaceTime=0:39:32.839

[Slot001]
Driver=whitham69
Vehicle=Chrysler Teams - Viper GTS-R
Team=Zwaan's Racing
Penalty=0
QualTime=1:41.356
Laps=12
Lap=(0, -1.000, 3:00.675)
Lap=(1, 221.020, 1:49.506)
Lap=(2, 330.526, 1:43.544)
Lap=(3, 434.070, 1:42.503)
Lap=(4, 536.573, 1:42.339)
Lap=(5, 638.912, 1:43.145)
Lap=(6, 742.056, 1:43.078)
Lap=(7, 845.134, 1:43.336)
Lap=(8, 948.470, 1:42.415)
Lap=(9, 1050.885, 1:42.994)
Lap=(10, 1153.879, 1:42.991)
Lap=(11, 1256.870, 1:42.179)
LapDistanceTravelled=3412.975586
BestLap=1:42.179
RaceTime=DNF
Reason=4

[Slot002]
Driver=TPG`Haiku
Vehicle=Porsche Teams - 911 GT3-RS
Team=Freisinger Motorsport
Penalty=0
QualTime=1:51.295
Laps=19
Lap=(0, -1.000, 3:04.045)
Lap=(1, 224.390, 1:58.526)
Lap=(2, 342.915, 1:51.348)
Lap=(3, 454.263, 1:51.826)
Lap=(4, 566.089, 1:52.024)
Lap=(5, 678.113, 1:54.562)
Lap=(6, 792.675, 2:05.667)
Lap=(7, 918.342, 1:52.338)
Lap=(8, 1030.681, 1:54.997)
Lap=(9, 1145.678, 1:55.559)
Lap=(10, 1261.237, 1:54.174)
Lap=(11, 1375.411, 1:58.668)
Lap=(12, 1494.079, 1:54.652)
Lap=(13, 1608.731, 2:05.343)
Lap=(14, 1734.074, 1:54.827)
Lap=(15, 1848.902, 1:55.140)
Lap=(16, 1964.042, 2:11.171)
Lap=(17, 2095.212, 1:53.895)
Lap=(18, 2209.107, 1:54.338)
LapDistanceTravelled=4631.258301
BestLap=1:51.348
RaceTime=0:38:03.101


[END]

I want to write information on each driver (name, car, total laps, best time, race time) each to a row in the database. I don't need to write the information on the specific laps. What is a good way to approach this problem?
Link to comment
https://forums.phpfreaks.com/topic/5232-suggestions-for-parsing-a-race-log/
Share on other sites

I just put your sample data into 'haiku.txt' and ran this

[code]$data = parse_ini_file('haiku.txt', true);

echo $data['Slot002']['Driver']; // --> TPG`Haiku

// view daya array
echo '<pre>', print_r ($data, true), '</pre>';[/code]

Output was-->

[code]
TPG`Haiku
Array
(
    [Header] => Array
        (
            [Game] => GTR
            [Version] => 1.400
            [TimeString] => 2006/03/16 21:52:24
            [Aids] => 0,0,0,0,0,1,0,0,0
        )

    [Race] => Array
        (
            [RaceMode] => 5
            [Scene] => GAMEDATA\LOCATIONS\Barcelona\Barcelona.TRK
            [AIDB] => GAMEDATA\LOCATIONS\Barcelona\Barcelona.AIW
            [Race Length] => 0.200
            [Track Length] => 4718.9307
        )

    [Slot007] => Array
        (
            [Driver] => C_Bex
            [Vehicle] => Saleen Teams - S7-R
            [Team] => Konrad Motorsport
            [Penalty] => 0
            [QualTime] => 1:50.335
            [Laps] => 6
            [Lap] => 5, 711.840, 2:23.195
            [LapDistanceTravelled] => 1667.881348
            [BestLap] => 1:50.591
            [RaceTime] => DNF
            [Reason] => 0
        )

    [Slot000] => Array
        (
            [Driver] => BH
            [Vehicle] => Ferrari Teams - 360 Modena
            [Team] => Menx
            [Penalty] => 0
            [QualTime] => 1:48.111
            [Laps] => 19
            [Lap] => 18, 2288.290, 2:04.894
            [LapDistanceTravelled] => 4599.286621
            [BestLap] => 1:49.784
            [RaceTime] => 0:39:32.839
        )

    [Slot001] => Array
        (
            [Driver] => whitham69
            [Vehicle] => Chrysler Teams - Viper GTS-R
            [Team] => Zwaan's Racing
            [Penalty] => 0
            [QualTime] => 1:41.356
            [Laps] => 12
            [Lap] => 11, 1256.870, 1:42.179
            [LapDistanceTravelled] => 3412.975586
            [BestLap] => 1:42.179
            [RaceTime] => DNF
            [Reason] => 4
        )

    [Slot002] => Array
        (
            [Driver] => TPG`Haiku
            [Vehicle] => Porsche Teams - 911 GT3-RS
            [Team] => Freisinger Motorsport
            [Penalty] => 0
            [QualTime] => 1:51.295
            [Laps] => 19
            [Lap] => 18, 2209.107, 1:54.338
            [LapDistanceTravelled] => 4631.258301
            [BestLap] => 1:51.348
            [RaceTime] => 0:38:03.101
        )

    [END] => Array
        (
        )

)

[/code]

As suspected, only last lap in each slot is recorded because of duplicate keys.
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.