Coders Corner

Discussion in 'Off Topic' started by SteveDrivingSlowly, Aug 12, 2019.

  1. SteveDrivingSlowly

    SteveDrivingSlowly ACC Results Ste(ve)ward

    Posts:
    327
    Likes:
    377
    Hello all, my name is Steve and I am a huge nerd.

    I thought I'd make a thread for people who would like to talk about web development, arduino, processing and computer programming stuff as there seem to be quite a few crossovers between Sim racing and this stuff. I hope I am not duplicating something that already exists - admission of guilt for not searching the forum at all before posting this.

    There are lots of projects I've come across where people are making their own button boxes or handbrakes or other sim related hardware with DIY elecontronics inside - I'd love to give this a go at some point! Also, I've recently been (very slowly, as the name suggests that is how I do everything) building a web app to firstly parse race results for Assetto Corsa Competizione from .json files generated by the race server, and later perhaps record these in a database - similar to those you would have seen for other games out there already (I'm not doing this for money or fame - just because I need a project to work on as I learn stuff).

    I thought to myself "hey I wonder if anyone else is thinking about/wondering about/embarking on a similar project?" So here is a thread to talk about it. I am no expert - just a guy with a computer and google trying to work stuff out - but I am very interested in talking to people about their ideas, trying to solve problems, or answer questions (no matter how basic, I don't care!), learn from other peoples experiences etc. More than happy to share all my code and work on the race results project and discuss how awful and inefficient my solutions are!
    Last edited: Aug 12, 2019
    Peter Wise, beakeroo, nanlatt and 2 others like this.
  2. SteveDrivingSlowly

    SteveDrivingSlowly ACC Results Ste(ve)ward

    Posts:
    327
    Likes:
    377
    So to get us started, here is some javascript I made to solve a problem I came across when analysing the race data for assetto corsa competizione. How do you calculate a drivers finishing position in a race? The combination of number of laps competed and total time to complete them makes for an interesting logic puzzle - here is how I solved it:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
    
    </body>
    
    
    <script type="text/javascript">
    
    var laps = [38, 38, 37, 20];
    var times = [1000, 1010, 1090, 800];
    var drivers = ["steve", "marty", "andy", "wally"];
    
    var driverPosition = 1000;
    var driverLapCount = 0;
    var positionToAssign = 1;
    var driver = "";
    
    //loop through and test
    for (var j = 0; j < drivers.length; j++) {
    
        driver = drivers[j];
        driverLapCount = laps[j];
        driverTotalTime = times[j];
    
    //show the driver, his lap count and total race time
        alert(driver + " " + driverLapCount + " " + driverTotalTime);
    
        for (var i = 0; i <= laps.length; i++) {
       
            if (laps[i] > driverLapCount) {
               
                    positionToAssign ++;
    
            }
    
        }
    
    //show rank by laps completed
        alert("lap Pos " + positionToAssign);
               
        for (var k = 0; k <= times.length; k++) {
       
            if (laps[k] == driverLapCount && times[k] < driverTotalTime) {
    
            positionToAssign ++;
    
            }
       
        }
    
    //show position based on time, taking into account laps
        alert("time pos " + positionToAssign);
    
        driverPosition = positionToAssign;
    
    //show final position
        alert("final pos " + driverPosition);
    
        //reset the position to assign for the next driver test
    
        positionToAssign = 1;
    
    }
    
    </script>
    
    </html>
    
    If you copy this code into notepad, save it as index.html and then run it in your web browser, it should do stuff. It runs through loops testing each drivers lap count and ranks it, then takes into account their total race time to assign their final position.

    If you change the values in the brackets in these arrays (and then save the file, refresh your browser):

    var laps = [38, 38, 37, 20];
    var times = [1000, 1010, 1090, 800];
    var drivers = ["steve", "marty", "andy", "wally"];

    it should change the output of the code.

    I made this to test the logic - soon I'll implement it in the project I am working on.
    Last edited: Aug 12, 2019
  3. SteveDrivingSlowly

    SteveDrivingSlowly ACC Results Ste(ve)ward

    Posts:
    327
    Likes:
    377
    OK so another little thing related to racing - if you get a result in milliseconds (as is the case in the ACC results .json), how do you convert it into HH:MM:SS.mmm format? Here is a function (again in javascript) that will do this little job:

    Code:
    
    function msToTime(duration) {
    
      var milliseconds = duration % 1000,
      seconds = Math.floor((duration / 1000) % 60),
      minutes = Math.floor((duration / (1000 * 60)) % 60),
      hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
    
      hours = (hours < 10) ? "0" + hours : hours;
      minutes = (minutes < 10) ? "0" + minutes : minutes;
      seconds = (seconds < 10) ? "0" + seconds : seconds;
      milliseconds = (milliseconds < 100) ? "0" + milliseconds : milliseconds;
    
      return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
    
    }
    
    
    You call this function and pass to it duration, which is the result you have in milliseconds. It them does some math and re formats the result.

    For those not familiar, the % symbol is Modulus, meaning give me the remainder after performing a division (9 divided by 2 is 4 with 1 as the remainder).

    Math.floor rounds down to the nearest integer - meaning 1.6 will be rounded down to 1, even though normal rounding would make 1.6 become 2.

    The use of the ? (ternary operator) in this function is something I just learned - it is kind of like shorthand for an if statement. Usually it would look something like this:

    Code:
    
    if (hours < 10) {
    
    hours = "0" + hours;
    
    } else {
    
    hours = hours;
    
    }
    
    
    In human this would be like saying "if the amount of hours is less than ten, add a 0 before the number (e.g. 09 instead of 9), otherwise just leave it as it is (e.g. 10 would stay 10)".

    The ternary version goes like this:

    result = condition ? value1 : value2;

    result is tested against the condition, and if true value1 is returned, if false value 2 is returned.

    Honestly I find it harder to read than the if version, but wanted to try and use it after I read about it...

    There are a lot of versions of this code out there on the web if you search for it (stackoverflow etc) - but they didn't work properly (@marty spotted a bug in one version I found) so it needed a few small tweaks to get to this state.
    Last edited: Aug 13, 2019
  4. SteveDrivingSlowly

    SteveDrivingSlowly ACC Results Ste(ve)ward

    Posts:
    327
    Likes:
    377
    OK so today lets talk about the files that are generated by the server each time a session in ACC ends.

    These files contain a lot of information about what happened in the session, such as the track, session type, driver names, lap times, amount of laps completed, the cars that were used an so on. If you open one of the files in a text editor such as notepad, you will see something like this:

    Code:
    {
        "sessionType": "R2",
        "trackName": "spa",
        "sessionIndex": 4,
        "sessionResult": {
            "bestlap": 137895,
            "bestSplits": [
                40896,
                60030,
                36702
            ],
            "isWetSession": 0,
            "type": 1,
            "leaderBoardLines": [
                {
                    "car": {
                        "carId": 1014,
                        "raceNumber": 25,
                        "carModel": 3,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Andrew",
                                "lastName": "O'Hara",
                                "shortName": "O'H",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Andrew",
                        "lastName": "O'Hara",
                        "shortName": "O'H",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 143283,
                        "lastSplits": [
                            42336,
                            63216,
                            37731
                        ],
                        "bestLap": 137895,
                        "bestSplits": [
                            40896,
                            60030,
                            36969
                        ],
                        "totalTime": 1843590,
                        "lapCount": 13,
                        "lastSplitId": 0
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1006,
                        "raceNumber": 23,
                        "carModel": 6,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Mat",
                                "lastName": "Nipperess",
                                "shortName": "Nip",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Mat",
                        "lastName": "Nipperess",
                        "shortName": "Nip",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 144381,
                        "lastSplits": [
                            42273,
                            64104,
                            38004
                        ],
                        "bestLap": 139776,
                        "bestSplits": [
                            41118,
                            61386,
                            36831
                        ],
                        "totalTime": 1846795,
                        "lapCount": 13,
                        "lastSplitId": 0
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1003,
                        "raceNumber": 63,
                        "carModel": 4,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Sergey",
                                "lastName": "Mironenko",
                                "shortName": "Mir",
                                "playerId": "S76561198000612750"
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Sergey",
                        "lastName": "Mironenko",
                        "shortName": "Mir",
                        "playerId": "S76561198000612750"
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 144126,
                        "lastSplits": [
                            41853,
                            63828,
                            38445
                        ],
                        "bestLap": 140472,
                        "bestSplits": [
                            41022,
                            61800,
                            37035
                        ],
                        "totalTime": 1847950,
                        "lapCount": 13,
                        "lastSplitId": 0
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1015,
                        "raceNumber": 9,
                        "carModel": 8,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Neil",
                                "lastName": "Faichney",
                                "shortName": "Fai",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Neil",
                        "lastName": "Faichney",
                        "shortName": "Fai",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 146859,
                        "lastSplits": [
                            42687,
                            64989,
                            39183
                        ],
                        "bestLap": 140577,
                        "bestSplits": [
                            41439,
                            61068,
                            37035
                        ],
                        "totalTime": 1865088,
                        "lapCount": 13,
                        "lastSplitId": 0
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1013,
                        "raceNumber": 777,
                        "carModel": 7,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Steve",
                                "lastName": "Driving Slowly",
                                "shortName": "Dri",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Steve",
                        "lastName": "Driving Slowly",
                        "shortName": "Dri",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 148284,
                        "lastSplits": [
                            42612,
                            66612,
                            39060
                        ],
                        "bestLap": 140775,
                        "bestSplits": [
                            41364,
                            62394,
                            37017
                        ],
                        "totalTime": 1871668,
                        "lapCount": 13,
                        "lastSplitId": 0
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1011,
                        "raceNumber": 76,
                        "carModel": 12,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Art",
                                "lastName": "Vandelay",
                                "shortName": "Van",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Art",
                        "lastName": "Vandelay",
                        "shortName": "Van",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 149019,
                        "lastSplits": [
                            43494,
                            65961,
                            39564
                        ],
                        "bestLap": 141492,
                        "bestSplits": [
                            41673,
                            62229,
                            37122
                        ],
                        "totalTime": 1889217,
                        "lapCount": 13,
                        "lastSplitId": 0
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1004,
                        "raceNumber": 11,
                        "carModel": 2,
                        "cupCategory": 2,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Terry",
                                "lastName": "Rayton",
                                "shortName": "Ray",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Terry",
                        "lastName": "Rayton",
                        "shortName": "Ray",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 149352,
                        "lastSplits": [
                            42966,
                            66924,
                            39462
                        ],
                        "bestLap": 139185,
                        "bestSplits": [
                            41079,
                            61005,
                            36969
                        ],
                        "totalTime": 1900117,
                        "lapCount": 13,
                        "lastSplitId": 0
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1012,
                        "raceNumber": 13,
                        "carModel": 8,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Matt",
                                "lastName": "Jorgensen",
                                "shortName": "Jor",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Matt",
                        "lastName": "Jorgensen",
                        "shortName": "Jor",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 138597,
                        "lastSplits": [
                            41031,
                            60699,
                            36867
                        ],
                        "bestLap": 138597,
                        "bestSplits": [
                            41031,
                            60699,
                            36702
                        ],
                        "totalTime": 524939,
                        "lapCount": 3,
                        "lastSplitId": 2
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1002,
                        "raceNumber": 58,
                        "carModel": 5,
                        "cupCategory": 2,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Imad",
                                "lastName": "Farhat",
                                "shortName": "Far",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Imad",
                        "lastName": "Farhat",
                        "shortName": "Far",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 27579,
                        "lapCount": 0,
                        "lastSplitId": 1
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1001,
                        "raceNumber": 991,
                        "carModel": 1,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Marty",
                                "lastName": "Cerven",
                                "shortName": "Cer",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Marty",
                        "lastName": "Cerven",
                        "shortName": "Cer",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1005,
                        "raceNumber": 7,
                        "carModel": 8,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Emanuele",
                                "lastName": "Franca",
                                "shortName": "Fra",
                                "playerId": "S76561198050820277"
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Emanuele",
                        "lastName": "Franca",
                        "shortName": "Fra",
                        "playerId": "S76561198050820277"
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1007,
                        "raceNumber": 24,
                        "carModel": 4,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Andrew",
                                "lastName": "O'Hara",
                                "shortName": "O'H",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Andrew",
                        "lastName": "O'Hara",
                        "shortName": "O'H",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1008,
                        "raceNumber": 57,
                        "carModel": 8,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Roland",
                                "lastName": "Schmid",
                                "shortName": "Sch",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Roland",
                        "lastName": "Schmid",
                        "shortName": "Sch",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1009,
                        "raceNumber": 8,
                        "carModel": 8,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Nando",
                                "lastName": "Lattanzio",
                                "shortName": "Lat",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Nando",
                        "lastName": "Lattanzio",
                        "shortName": "Lat",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1010,
                        "raceNumber": 1,
                        "carModel": 3,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Sergey",
                                "lastName": "Mironenko",
                                "shortName": "Mir",
                                "playerId": "S76561198000612750"
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Sergey",
                        "lastName": "Mironenko",
                        "shortName": "Mir",
                        "playerId": "S76561198000612750"
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1016,
                        "raceNumber": 540,
                        "carModel": 0,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Aleksei",
                                "lastName": "Fedorov",
                                "shortName": "Fed",
                                "playerId": "S76561198850565263"
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Aleksei",
                        "lastName": "Fedorov",
                        "shortName": "Fed",
                        "playerId": "S76561198850565263"
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1017,
                        "raceNumber": 114,
                        "carModel": 15,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Brad",
                                "lastName": "Cook",
                                "shortName": "Coo",
                                "playerId": "S76561198042644871"
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Brad",
                        "lastName": "Cook",
                        "shortName": "Coo",
                        "playerId": "S76561198042644871"
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1018,
                        "raceNumber": 19,
                        "carModel": 4,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Stefano",
                                "lastName": "Ricchiuti",
                                "shortName": "Ric",
                                "playerId": "S76561198019313236"
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Stefano",
                        "lastName": "Ricchiuti",
                        "shortName": "Ric",
                        "playerId": "S76561198019313236"
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1019,
                        "raceNumber": 10,
                        "carModel": 8,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": "Default",
                                "lastName": "Default",
                                "shortName": "Def",
                                "playerId": "S76561197989619464"
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": "Default",
                        "lastName": "Default",
                        "shortName": "Def",
                        "playerId": "S76561197989619464"
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                },
                {
                    "car": {
                        "carId": 1020,
                        "raceNumber": 14,
                        "carModel": 15,
                        "cupCategory": 0,
                        "teamName": "",
                        "drivers": [
                            {
                                "firstName": " ",
                                "lastName": "Slasher",
                                "shortName": "Sla",
                                "playerId": ""
                            }
                        ]
                    },
                    "currentDriver": {
                        "firstName": " ",
                        "lastName": "Slasher",
                        "shortName": "Sla",
                        "playerId": ""
                    },
                    "currentDriverIndex": 0,
                    "timing": {
                        "lastLap": 2147483647,
                        "lastSplits": [],
                        "bestLap": 2147483647,
                        "bestSplits": [
                            2147483647,
                            2147483647,
                            2147483647
                        ],
                        "totalTime": 2147483647,
                        "lapCount": 0,
                        "lastSplitId": 4294967295
                    },
                    "missingMandatoryPitstop": 0,
                    "driverTotalTimes": [
                        0.0
                    ]
                }
            ]
        },
        "laps": [
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 825597,
                "isValidForBest": true,
                "splits": [
                    725511,
                    62343,
                    37743
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 414357,
                "isValidForBest": true,
                "splits": [
                    314253,
                    62061,
                    38043
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 452217,
                "isValidForBest": true,
                "splits": [
                    352104,
                    62052,
                    38061
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 424902,
                "isValidForBest": true,
                "splits": [
                    322599,
                    62115,
                    40188
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 414018,
                "isValidForBest": true,
                "splits": [
                    312900,
                    63261,
                    37857
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 394824,
                "isValidForBest": true,
                "splits": [
                    294159,
                    62901,
                    37764
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 1304085,
                "isValidForBest": true,
                "splits": [
                    1204206,
                    61962,
                    37917
                ]
            },
            {
                "carId": 1012,
                "driverIndex": 0,
                "laptime": 479253,
                "isValidForBest": true,
                "splits": [
                    359175,
                    62121,
                    57957
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 142077,
                "isValidForBest": true,
                "splits": [
                    41724,
                    62010,
                    38343
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 142095,
                "isValidForBest": true,
                "splits": [
                    41829,
                    61503,
                    38763
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 140889,
                "isValidForBest": true,
                "splits": [
                    41421,
                    61386,
                    38082
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 141669,
                "isValidForBest": true,
                "splits": [
                    41748,
                    62658,
                    37263
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 143358,
                "isValidForBest": true,
                "splits": [
                    43446,
                    62142,
                    37770
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 142131,
                "isValidForBest": true,
                "splits": [
                    42036,
                    62223,
                    37872
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 147879,
                "isValidForBest": true,
                "splits": [
                    42537,
                    62229,
                    43113
                ]
            },
            {
                "carId": 1012,
                "driverIndex": 0,
                "laptime": 140010,
                "isValidForBest": true,
                "splits": [
                    42516,
                    60792,
                    36702
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 139731,
                "isValidForBest": true,
                "splits": [
                    41385,
                    61377,
                    36969
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 139776,
                "isValidForBest": true,
                "splits": [
                    41118,
                    61548,
                    37110
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 141825,
                "isValidForBest": true,
                "splits": [
                    41310,
                    63318,
                    37197
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 140775,
                "isValidForBest": true,
                "splits": [
                    41364,
                    62394,
                    37017
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 139242,
                "isValidForBest": true,
                "splits": [
                    41286,
                    60759,
                    37197
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 140577,
                "isValidForBest": true,
                "splits": [
                    42474,
                    61068,
                    37035
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 142536,
                "isValidForBest": true,
                "splits": [
                    41673,
                    63306,
                    37557
                ]
            },
            {
                "carId": 1012,
                "driverIndex": 0,
                "laptime": 138597,
                "isValidForBest": true,
                "splits": [
                    41031,
                    60699,
                    36867
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 140463,
                "isValidForBest": true,
                "splits": [
                    41274,
                    62109,
                    37080
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 140253,
                "isValidForBest": true,
                "splits": [
                    41373,
                    62049,
                    36831
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 140472,
                "isValidForBest": true,
                "splits": [
                    41637,
                    61800,
                    37035
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 137895,
                "isValidForBest": true,
                "splits": [
                    40896,
                    60030,
                    36969
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 141984,
                "isValidForBest": true,
                "splits": [
                    41886,
                    63036,
                    37062
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 141534,
                "isValidForBest": true,
                "splits": [
                    41439,
                    62487,
                    37608
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 141978,
                "isValidForBest": true,
                "splits": [
                    41895,
                    62694,
                    37389
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 139185,
                "isValidForBest": true,
                "splits": [
                    41079,
                    61005,
                    37101
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 140787,
                "isValidForBest": true,
                "splits": [
                    41412,
                    62352,
                    37023
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 140118,
                "isValidForBest": true,
                "splits": [
                    41160,
                    61914,
                    37044
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 141093,
                "isValidForBest": true,
                "splits": [
                    41229,
                    61944,
                    37920
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 142452,
                "isValidForBest": true,
                "splits": [
                    41895,
                    63093,
                    37464
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 142041,
                "isValidForBest": true,
                "splits": [
                    41589,
                    62712,
                    37740
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 141492,
                "isValidForBest": true,
                "splits": [
                    41835,
                    62535,
                    37122
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 140091,
                "isValidForBest": true,
                "splits": [
                    41208,
                    61869,
                    37014
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 142131,
                "isValidForBest": true,
                "splits": [
                    41415,
                    63102,
                    37614
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 141489,
                "isValidForBest": true,
                "splits": [
                    41022,
                    62877,
                    37590
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 142998,
                "isValidForBest": true,
                "splits": [
                    42303,
                    62685,
                    38010
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 145962,
                "isValidForBest": true,
                "splits": [
                    42321,
                    64290,
                    39351
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 143199,
                "isValidForBest": true,
                "splits": [
                    41733,
                    63567,
                    37899
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 175455,
                "isValidForBest": true,
                "splits": [
                    74172,
                    63354,
                    37929
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 142152,
                "isValidForBest": true,
                "splits": [
                    41376,
                    62754,
                    38022
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 142959,
                "isValidForBest": true,
                "splits": [
                    41553,
                    63438,
                    37968
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 143133,
                "isValidForBest": true,
                "splits": [
                    41628,
                    63117,
                    38388
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 144396,
                "isValidForBest": true,
                "splits": [
                    43197,
                    62757,
                    38442
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 144801,
                "isValidForBest": true,
                "splits": [
                    42174,
                    64287,
                    38340
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 144177,
                "isValidForBest": true,
                "splits": [
                    42063,
                    64020,
                    38094
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 144930,
                "isValidForBest": true,
                "splits": [
                    41943,
                    64161,
                    38826
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 144108,
                "isValidForBest": true,
                "splits": [
                    41997,
                    63654,
                    38457
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 143829,
                "isValidForBest": true,
                "splits": [
                    41772,
                    63951,
                    38106
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 144870,
                "isValidForBest": true,
                "splits": [
                    42057,
                    64362,
                    38451
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 146574,
                "isValidForBest": true,
                "splits": [
                    43035,
                    64215,
                    39324
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 146646,
                "isValidForBest": true,
                "splits": [
                    42729,
                    64944,
                    38973
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 146481,
                "isValidForBest": true,
                "splits": [
                    42321,
                    65718,
                    38442
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 146880,
                "isValidForBest": true,
                "splits": [
                    42801,
                    65172,
                    38907
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 146319,
                "isValidForBest": true,
                "splits": [
                    42675,
                    64662,
                    38982
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 146817,
                "isValidForBest": true,
                "splits": [
                    42795,
                    65442,
                    38580
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 145953,
                "isValidForBest": true,
                "splits": [
                    41784,
                    65664,
                    38505
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 147819,
                "isValidForBest": true,
                "splits": [
                    43290,
                    65247,
                    39282
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 149175,
                "isValidForBest": true,
                "splits": [
                    43128,
                    66462,
                    39585
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 153054,
                "isValidForBest": true,
                "splits": [
                    42657,
                    70266,
                    40131
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 149937,
                "isValidForBest": true,
                "splits": [
                    43239,
                    66762,
                    39936
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 146340,
                "isValidForBest": true,
                "splits": [
                    43188,
                    64329,
                    38823
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 147684,
                "isValidForBest": true,
                "splits": [
                    43104,
                    65781,
                    38799
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 148413,
                "isValidForBest": true,
                "splits": [
                    42603,
                    67305,
                    38505
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 147789,
                "isValidForBest": true,
                "splits": [
                    43647,
                    65169,
                    38973
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 148332,
                "isValidForBest": true,
                "splits": [
                    42714,
                    66039,
                    39579
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 152496,
                "isValidForBest": true,
                "splits": [
                    44214,
                    68574,
                    39708
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 150015,
                "isValidForBest": true,
                "splits": [
                    43674,
                    66693,
                    39648
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 146766,
                "isValidForBest": true,
                "splits": [
                    42867,
                    64602,
                    39297
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 146112,
                "isValidForBest": true,
                "splits": [
                    42891,
                    65046,
                    38175
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 145917,
                "isValidForBest": true,
                "splits": [
                    42099,
                    64788,
                    39030
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 147291,
                "isValidForBest": true,
                "splits": [
                    42906,
                    65115,
                    39270
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 147438,
                "isValidForBest": true,
                "splits": [
                    42855,
                    65586,
                    38997
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 150168,
                "isValidForBest": true,
                "splits": [
                    43473,
                    67614,
                    39081
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 147987,
                "isValidForBest": true,
                "splits": [
                    43293,
                    66048,
                    38646
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 146688,
                "isValidForBest": true,
                "splits": [
                    43356,
                    65130,
                    38202
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 145722,
                "isValidForBest": true,
                "splits": [
                    42780,
                    64728,
                    38214
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 145656,
                "isValidForBest": true,
                "splits": [
                    42021,
                    64455,
                    39180
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 147051,
                "isValidForBest": true,
                "splits": [
                    43017,
                    64893,
                    39141
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 147216,
                "isValidForBest": true,
                "splits": [
                    42651,
                    65496,
                    39069
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 149481,
                "isValidForBest": true,
                "splits": [
                    43110,
                    66891,
                    39480
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 150384,
                "isValidForBest": true,
                "splits": [
                    43020,
                    68127,
                    39237
                ]
            },
            {
                "carId": 1014,
                "driverIndex": 0,
                "laptime": 143283,
                "isValidForBest": true,
                "splits": [
                    42336,
                    63216,
                    37731
                ]
            },
            {
                "carId": 1006,
                "driverIndex": 0,
                "laptime": 144381,
                "isValidForBest": true,
                "splits": [
                    42273,
                    64104,
                    38004
                ]
            },
            {
                "carId": 1003,
                "driverIndex": 0,
                "laptime": 144126,
                "isValidForBest": true,
                "splits": [
                    41853,
                    63828,
                    38445
                ]
            },
            {
                "carId": 1015,
                "driverIndex": 0,
                "laptime": 146859,
                "isValidForBest": true,
                "splits": [
                    42687,
                    64989,
                    39183
                ]
            },
            {
                "carId": 1013,
                "driverIndex": 0,
                "laptime": 148284,
                "isValidForBest": true,
                "splits": [
                    42612,
                    66612,
                    39060
                ]
            },
            {
                "carId": 1011,
                "driverIndex": 0,
                "laptime": 149019,
                "isValidForBest": true,
                "splits": [
                    43494,
                    65961,
                    39564
                ]
            },
            {
                "carId": 1004,
                "driverIndex": 0,
                "laptime": 149352,
                "isValidForBest": true,
                "splits": [
                    42966,
                    66924,
                    39462
                ]
            }
        ],
        "penalties": []
    }
    The formatting seems weird and is very hard for a human to read, there are {'s and ['s and :'s everywhere. Some stuff is in quotes, some isn't, sometimes where you might expect words there is a number (carModel for example). It is very hard to work out which bits of data correspond to which driver and so on.

    These files have the extension .json which stands for JavaScript Object Notation. This refers to the standardised structure of data within the file and is very useful because there are ready made and easily implemented tools to step through this data within various programming languages, but primarily within JavaScript (one of the essential programming languages for web development if you are not familiar). For a computer, this standardised structure makes the file extremely easy to read and for a programmer this makes it a great way to move big chunks of complex data around, find things within it and grab them when you need them.

    All of the brackets surround different groupings of data. For example there is a group of data near the start called "bestSplits". This is an indexed array and it contains three values within square brackets [ & ], each separated by a comma.

    Code:
    "bestSplits": [
                40896,
                60030,
                36702
            ]
    
    An array is a named place where you can store more than one value, indexed means you can find each individual value within it by referring to it's position in the array (it's index). As indexes start at 0 in programming, I can refer to the first value in the array bestSplits by typing this:

    Code:
    bestSplits[0]
    
    The value of bestSplits[0] is 40896, the value of bestSplits[1] would be 60030 and so on. Indexed arrays are great because you can loop through all of the values contained within by adding 1 to the index on each iteration of a loop.

    You can also see similar things but with different brackets - these ones { & }.

    These are known as associative arrays (or sometimes objects but lets talk about that later...maybe). They are very similar to indexed arrays but instead of finding values by referring to an idex, you can refer to their key. A key is associated with a particular value, for example an associative array could look like this:

    Code:
    awesomeHuman {
       "firstName": "Steve",
       "lastName": "DrivingSlowly"
    }
    
    In this case we can find the values by using the key, instead of an index, for example

    Code:
    awesomeHiuman.firstName
    
    The value of awesomeHuman.firstName would be "Steve" in this case. aswesomeHuman.lastName would be DrivingSlowly.

    You can see that within the .json file from ACC, there are many examples of both of these kinds of array, and even arrays within arrays within arrays....!!!!

    knowing this, you can find any piece of data within the file, once you have done a few other things to get the JSON cleaned up.

    Final example, this time from the actual ACC file:

    Code:
    sessionResult.leaderBoardLines[0].car.carModel
    This would refer to the carModel stored within an array called car which is itself the first element of the leaderBoardLines array (remember 0 is the first element of an indexed array) stored within the sessionResult array. The first element of the leaderBoardLines array is all of the data that refers to a particular team, and as we only have single drivers in each team for the race in this data, then this is the carModel for that individual driver. There is a mixture here of both associative and indexed arrays.

    If you go to:

    http://roozresults.epizy.com

    and paste in the whole of the .json from the first code block in this post above, you can see this in action, taking the raw data and when you press the button, grabbing the interesting bits and creating a table.

    DISCLAIMER: I am likely incorrectly using the terms array in place of object in this for simplification - this is meant to be a purely practical explanation as opposed to the single source of absolute truth. If that is what you want, use google! I would also recommend https://www.w3schools.com/ as a great place to start learning about web development and code.
    Last edited: Aug 14, 2019