National High Scores

With some digging into the information avaialble in the API, it's possible to determine the highest scores reported for each machine for all the regions being tracked in the API. This is more of a toy-project idea, but to see the highest of all the high scores for each machine is fun information and was a fun challenge to figure out the code to complete so it's being shared here. Admittedly, there's probably a more elegant way to complete this task, but I was able to get this to work. I initially didn't expect the task to be such an undertaking, but since I was able to figure it out, this is a nice wrap-up of the tutorial as it uses nearly all the tools we've been over so far up until this point.

The approach is similar to the approach used to add high scores for machines at individual locations, though rather than determining the scores for each machine at a given location, we fetch all high scores for a region for each region in the pinball map.

   function machineScoreObject(location_id, machine_id, region) {
        this.location_id = location_id;
        this.machine_id = machine_id;
        this.region = region;

    var req = new XMLHttpRequest(); // Get machine name based on machine id'GET', '', false);
    var regionMachines = JSON.parse(req.responseText);  

    /* Determine the regions to check high scores for */
    var req = new XMLHttpRequest();'GET', '', false);
    var data = JSON.parse(req.responseText);

    var regions = [];
    for (region in data.regions) {

    var machinesWithScores = [];
    for (var i=0; i<regions.length; i++) { //For each region, fetch the machines at locations
      var req = new XMLHttpRequest();"GET", '' + regions[i] + '/location_machine_xrefs.json', false);
      var data = JSON.parse(req.responseText);

      var reqScore = new XMLHttpRequest(); //For each region, fetch the high scores'GET', '' + regions[i] + '/machine_score_xrefs.json', false);
      var regionScores = JSON.parse(reqScore.responseText);

      for(machine in data.location_machine_xrefs) { //For each machine at a location
        if (data.location_machine_xrefs[machine].machine_score_xrefs_count >= 1) { 
        //Determine if there are high scores posted. If so, create and populate a machineScoreObject
            var region = regions[i];
            var location_id = data.location_machine_xrefs[machine].id;
            var machine_id = data.location_machine_xrefs[machine].machine_id;
            machineScore = new machineScoreObject(location_id, machine_id, region); 
            for (machine in regionMachines.machines) {
              if (regionMachines.machines[machine].id === machineScore.machine_id) {
        = regionMachines.machines[machine].name;
            for (machine_score_xref in regionScores.machine_score_xrefs) {
              if (regionScores.machine_score_xrefs[machine_score_xref].location_machine_xref_id === machineScore.location_id) {
                machineScore.initials = regionScores.machine_score_xrefs[machine_score_xref].initials;
                machineScore.score = regionScores.machine_score_xrefs[machine_score_xref].score;

    var uniqueMachinesWithScores = []; //Group same machines by machine id
    for (var i=0; i<machinesWithScores.length; i++) {
      var machinePresent = false;
      for (var j=0; j<uniqueMachinesWithScores.length; j++) {
        if (machinesWithScores[i].machine_id === uniqueMachinesWithScores[j].machine_id) {
          machinePresent = true;
          if (machinesWithScores[i].score > uniqueMachinesWithScores[j].score) { //If new machine has higher score
      if(!machinePresent) {

It takes a few minutes to allow all the requests to finish to get the data generated, so rather than providing a link to a dynamic list, here is a link with a table of high scores current as of 3/8/2016. A partial table is can be viewed directly here:

National High Scores
Iron Man22476460ncdayton
Monster Bash77785000JPM MONSTER BASH CHAMPboise
Attack from Mars10772132780JPMboise
The Sopranos46939700JPMboise
Jacks to Open167380DBPtoronto
The Wizard of Oz (Emerald City LE)503484JCFsandiego
Attack from Mars14519670850JRFsandiego
Pirates of the Caribbean413931550RUSsandiego
Scared Stiff111778680DCPsandiego
Batman: The Dark Knight1000000000FARTmichigan-west
Twilight Zone560056030Njwutah
The Addams Family197247000WBKcharleston
Medieval Madness (Remake)56994890WBKcharleston
AC/DC (Pro)130438400DKcharleston
Dirty Harry4566554Tommyoceancity
Slick Chick1953MASreno
Attack from Mars32000000000WHOreno
Indiana Jones100522320DCBreno
Kiss (Stern)110518330DRJorlando
The Walking Dead (Pro)665251050SMK-SMKorlando

Notice that the results are in order of region checked first unless a higher score from a region checked later took over the originally found score.

Wrap Up

This concludes our tutorial on using the pinball map API. Throughout this guide we've examined nearly all the 'GET' request features one would need to retrieve data for purposes of analytics or having personal/professional websites dynamically updated with the information available in the API.