Author Topic: JSON Example?  (Read 1639 times)

efdenny

  • Full Member
  • ***
  • Posts: 166
    • View Profile
JSON Example?
« on: February 21, 2018, 06:35:29 PM »
Does anyone have an example tournamentstatus.html page they have produced using JSON? I'm having a bit of trouble getting started...

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 6216
    • View Profile
Re: JSON Example?
« Reply #1 on: February 22, 2018, 04:26:26 PM »
I thought I had provided sample code in the examples folder in the TD install folder.  Looks like the code that processes the status is in TournamentStatus.js, and it assumes it is of the older format, where it's one variable and value per line (buyins=100, for example).

The JSON status output looks something like this:
Code: [Select]
{
  "RoundNum": 1,
  "BreakNum": 0,
  "Level": 0,
  "IsRound": 1,
  "IsBreak": 0,
  "NextIsRound": 1,
  "NextIsBreak": 0,
  "HasMoreRounds": 1,
  "HasMoreBreaks": 1,
  "FirstAnteRound": 0,
  "FirstAnteAmount": 0,
  "LevelDuration": 30,
  "NextLevelDuration": 30,
  "State": 3,
  "StateDesc": "after",
  "Buyins": 32,
  "DefaultBuyinFee": 55,
  "DefaultBuyinRake": 5,
  "DefaultBuyinChips": 1500,
  "TotalBuyinsAmount": 1760,
  "TotalBuyinsRake": 160,
  "TotalBuyinsChips": 48000,
  "NumberOfLeagueMembers": 0,
  "Pot": 1715,
  "PlayersLeft": 1,
  "TablesLeft": 1,
  "SecondsLeft": 1775,
  "SecondsElapsed": 25,
  "ClockPaused": 1,
  "ClockPausedSeconds": 0,
  "TimeOfDay": "152536",
  "Time": 1510608336,
  "LastPlayerMoveTime": 0,
  "LastPlayerBustoutTime": 1141152613,
  "RebuysAllowed": 0,
  "RebuysOver": 0,
  "RebuysLeft": 0,
  "RebuysSecondsLeft": 0,
  "RebuysLastRound": 0,
  "RebuysMaxPerPlayer": 0,
  "RebuysMinPlayers": 0,
  "RebuysMaxTotal": 0,
  "DefaultRebuyFee": 0,
  "DefaultRebuyRake": 0,
  "DefaultRebuyChips": 0,
  "TotalRebuys": 1,
  "TotalRebuysAmount": 75,
  "TotalRebuysRake": 5,
  "TotalRebuysChips": 1000,
  "AddonsAllowed": 0,
  "AddonsOver": 0,
  "AddonsLeft": 0,
  "AddonsSecondsLeft": 0,
  "AddonsLastRound": 0,
  "AddonsMaxPerPlayer": 0,
  "AddonsMinPlayers": 0,
  "AddonsMaxTotal": 0,
  "DefaultAddonFee": 0,
  "DefaultAddonRake": 0,
  "DefaultAddonChips": 0,
  "TotalAddons": 1,
  "TotalAddonsAmount": 50,
  "TotalAddonsRake": 5,
  "TotalAddonsChips": 500,
  "InTheMoneyRank": 6,
  "TotalFixedRake": 0,
  "FixedRake": 0,
  "Ante": 0,
  "SmallBlind": 10,
  "BigBlind": 20,
  "GameType": 2,
  "GameName": "texas hold em",
  "ChipUp": false,
  "NextAnte": 0,
  "NextSmallBlind": 15,
  "NextBigBlind": 30,
  "NextGameType": 2,
  "NextGameName": "texas hold em",
  "NextChipUp": false,
  "ChipCount": 49500,
  "ChipCountAdjustment": 0,
  "UnadjustedChipCount": 49500,
  "GuaranteedPot": 0,
  "PreGuaranteedPot": 1715,
  "HouseAdds": 0,
  "HouseContribution": 0,
  "BustsUntilMoney": 0,
  "BustsUntilFinalTable": 0,
  "UsePlayerBountyChips": true,
  "RestrictBounties": false,
  "BountyTotal": 160,
  "Limit1": 10,
  "NextLimit1": 15,
  "Limit2": 20,
  "NextLimit2": 30,
  "Limit3": 0,
  "NextLimit3": 0,
  "Limit4": 0,
  "NextLimit4": 0,
  "Limit5": 0,
  "NextLimit5": 0,
  "Limit6": 0,
  "NextLimit6": 0,
  "Limit7": 0,
  "NextLimit7": 0,
  "Limit8": 0,
  "NextLimit8": 0,
  "FixedRakes": [
    0
  ],
  "Players": [
    {
      "Nickname": "Bill (TD)",
      "Firstname": "Bill",
      "Lastname": "Watkins",
      "StreetAddress": "",
      "City": "",
      "State": "",
      "Zipcode": "",
      "Country": "",
      "Phone1": "",
      "Phone2": "",
      "Email1": "",
      "Email2": "",
      "Notes": "",
      "OptID": "",
      "Name": "Bill (TD)",
      "InternalID": "1e189790-8d4c-11da-3528-47708561037409",
      "Paid": true,
      "PaidInFull": false,
      "BuyinCost": 55,
      "BountyChip": 5,
      "TotalBuyinRake": 5,
      "BuyinChips": 1500,
      "Rebuys": 0,
      "RebuysCost": 0,
      "TotalRebuysRake": 0,
      "RebuysChips": 0,
      "Addons": 0,
      "AddonsCost": 0,
      "TotalAddonsRake": 0,
      "AddonsChips": 0,
      "TotalCost": 60,
      "TotalRake": 5,
      "ChipsBought": 1500,
      "TimeOut": 1141152593000,
      "RoundOut": 1,
      "Hitman": [
        "Mark C."
      ],
      "HitmanID": [
        "8e5e9990-8d52-11da-3528-163880350183954"
      ],
      "Rank": 19,
      "Hits": 0,
      "BountiesWon": 0,
      "PrizeWinnings": 0,
      "BountyWinnings": 0,
      "TotalWinnings": 0,
      "Points": 0,
      "Take": -60,
      "ChipCount": 0,
      "BountiesKept": 0,
      "BountyMoneyKept": 0,
      "PlayingTime": 2148548,
      "Seat": "",
      "BuyinTime": 1138362538250,
      "Status": "GameOver",
      "BuyinsList": [
        {
          "Time": 1138362538250,
          "Round": 1,
          "Amount": 55,
          "Bounty": 5,
          "Rake": [
            5
          ],
          "Chips": 1500,
          "Points": 0,
          "BustOut": {
            "Time": 1141152593000,
            "Round": 1,
            "Hitman": [
              "Mark C."
            ],
            "HitmanID": [
              "8e5e9990-8d52-11da-3528-163880350183954"
            ]
          }
        }
      ],
      "AddonsList": []
    }
  ],
  "Title": "Bills NL Holdem Tournament",
  "Description": "Bills NL Holdem Tournament",
  "LeagueId": "",
  "LeagueName": "",
  "LeagueDescription": "",
  "SeasonId": "",
  "SeasonName": "",
  "SeasonDescription": ""
}

You can generate your own to fool around with really easily by simply selecting "Write the status of the tournament to a file" on the Status Updates category of the Preferences tab and then pressing the "Attempt update now" button.

In TournamentStatus.js, in the function TDStatus.processResponse, you'd want to change it to process the JSON instead.  It's not hard.  It would be something like this:

Code: [Select]
TDStatus.processResponse = function(inResp)
{
  TDStatus.LastResponseReceivedTime = new Date();

  try
  {
    // parse the variables
    TDStatus.Vars = JSON.parse(inResp);   
  }
  catch(ex)
  {
    alert(ex);
  }

  TDStatus.updatePage();
}


It really is that easy.  But, the code was designed to look for variables in the TDStatus.Vars array in order to update the page.  Now TDStatus.Vars holds an object.  But all the same data is there, and is accessed in almost exactly the same way.  Most variables will simply be accessible via their "camel-case" format (first letter of each word capitalized, the rest lowercase) , instead of all lowercase.  "chipcount" becomes "ChipCount".

To handle this change, you would need to change TDStatus.updatePage.  For example:
Code: [Select]
  var theChipCount = parseInt(TDStatus.Vars["chipcount"]);

Now you would need to get it like this:
Code: [Select]
  var theChipCount = parseInt(TDStatus.Vars["ChipCount"]);

Accessing the last name of the first player in the tournament would work like this:
Code: [Select]
  var theLastName = TDStatus.Vars.Players[0].Lastname;

Does this help?

efdenny

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: JSON Example?
« Reply #2 on: February 22, 2018, 05:15:42 PM »
Perfect, thanks!!

Linker_Split

  • Full Member
  • ***
  • Posts: 115
    • View Profile
Re: JSON Example?
« Reply #3 on: March 05, 2018, 04:32:16 PM »
Hi Corey,
When I try to load the TournamentStatus.js into jsonLint to check if it's ok, it gives me error at the beginning:


And I cannot figure out what is the problem... any guesses?

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 6216
    • View Profile
Re: JSON Example?
« Reply #4 on: March 06, 2018, 09:14:53 AM »
Yep.  TournamentStatus.js is JavaScript, not JSON.  It won't validate as JSON.