Source: site.view [edit]
Function name: api
Arguments:
Description: OPTIONALARGS: date, round Returns date, question, player1 name, player 1 image, player 1 ref page, player 1 stat value, player2 name, player 2 image, player 2 ref page, player 2 stat value, delta between stat1 and stat2 (0 is very similar, 100 is very different), winner.
Page type: webl
Render function:  
Module: sportstreak

Page source:

  // Set default values if no info passed in.
  var sd = Wub_SimpleDateFormat("MM/dd/yyyy");
  // PST: Calculate 9 hours in milliseconds (9 hours * 60 minutes * 60 seconds * 1000 milliseconds)
  var nineHoursInMilliseconds = 9 * 60 * 60 * 1000;
  var dt = Wub_GetDateClass();
  dt.setTime(Wub_GetDateTime() - nineHoursInMilliseconds);
  var date = sd.format(dt);  
  var round = 0;

  // Update default values with passed in values if present
  if Size(OPTIONALARGS) > 0 then
     date = OPTIONALARGS[0];
     round = ToInt(OPTIONALARGS[1])
  end;


  // Seed is the random number seed
  var seed = round;

  var MAXRND = 503;

  // Returns a random number mod max
  // Seed number makes random number static or not
  var getRndWithDateSeed = fun(date, max, seed)
     var rnd = WubCall("sportstreak.getRandom", [date, MAXRND]);
     seed = seed + 1;
     if (seed > MAXRND) then
        seed = 0
     end;
     return rnd[seed] mod max
  end;


  var stats = [ 
       [. q="Who has more ",                     s="Career Minutes Per Game" .], 
       [.q="Who has more ",                      s="All-star Appearances" .],
       [. q="Who has a better ",                 s="Career Free Throw Percentage" .],
       [. q="Who has more ",                     s="NBA Championships" .], 
       [. q="Who has a better ",                 s="Career Field Goal Percentage" .], 
       [. q="Who has more ",                     s="Career Rebounds Per Game" .], 
       [. q="Who has more ",                     s="Career Turnovers Per Game" .], 
       [. q="Who has more ",                     s="Career Personal Fouls Per Game" .], 
       [. q="Who has more ",                     s="Career Blocks Per Game" .],
       [. q="Who is better according to their ", s="ESPN Ranking" .],
       [. q="Who has more ",                     s="Games Played" .],
       [. q="Who has more ",                     s="Career Points Per Game" .] 
  ];

  var stat = stats[ getRndWithDateSeed(date, Size(stats), seed) ];

  var Players = WubCall("getPlayerData", []);

  var roundData = WubCall("chooseRound", [Players, stat.s, round, date]);

  var res = `{ "date": "` + date + `", "round": ` + ToString(round) + `, "preQuestion": "` +
           stat.q + `", "stat": "` + stat.s + `", "p1Name": "` + Str_Trim(Players[roundData.player1]["Player Name"]) + `", "p1Image": "` + Str_Trim(Players[roundData.player1]["Image"]) + `", "p1Ref": "` 
                               + Str_Trim(Players[roundData.player1]["More Info"]) + `", "p1Stat": ` + ToString(roundData.s1) 
               + `, "p2Name": "` + Str_Trim(Players[roundData.player2]["Player Name"]) + `", "p2Image": "` + Str_Trim(Players[roundData.player2]["Image"]) + `", "p2Ref": "` 
                                    + Str_Trim(Players[roundData.player2]["More Info"]) + `", "p2Stat": ` + ToString(roundData.s2)
                 + `, "delta": ` + ToString(roundData.delta);


    if (roundData.s2 == roundData.s1) then
       res = res + `,"whoWon": "0"}`
    else 
       if (stat.s == "ESPN Ranking") then       
          if (roundData.s2 > roundData.s1) then
             res = res + `,"whoWon": "1"}`
          else
             res = res + `,"whoWon": "2"}`
          end
       else
          if (roundData.s2 > roundData.s1) then
             res = res + `,"whoWon": "2"}`
          else
             res = res + `,"whoWon": "1"}` 
          end
       end
    end;


   NewPage(res, "text/html");


/*
Image,Player Name,Fullname,Position,Height,Weight,Born,More Info,ESPN Ranking,Games Played,Career Minutes Per Game,Durability,Career Points Per Game,Career Field Goal Percentage,Career 3 Point Percentage,Career 2 Point Percentage,Career Effective Field Goal Percentage,Career Free Throw Percentage,Career Offensive Rebounds Per Game,Career Defensive Rebounds Per Game,Career Rebounds Per Game,Career Assists Per Game,Career Steals Per Game,Career Blocks Per Game,Career Turnovers Per Game,Career Personal Fouls Per Game,Career Minutes,Career Points,Career Field Goals,Career 3 Pointers,Career 2 Pointers,Career Free Throws,Career Offensive Rebounds,Career Defensive Rebounds,Career Rebounds,Career Assists,Career Steals,Career Turnovers,Career Player Efficiency Rating,Career True Shooting Percentage,Career 3 Point Attempt Rate,Career Free Throw Attempt Rate,Career Offensive Rebound Percentage,Career Defensive Rebound Percentage,Career Rebound Percentage,Career Assist Percentage,Career Steal Percentage,Career Block Percentage,Career Turnover Percentage,Career Usage Percentage,Career Offensive Win Shares,Career Defensive Win Shares,Career Win Shares,Career Box Plus Minus,MVPs,Rookie of the Year,Finals MVPs,NBA 50 Team,NBA 75 Team,All-star Appearances,NBA Championships,All NBA Team,All Defensive Team,All Rookie Team,Points Per Game Season Champion,Points Per Game Career Champion,Points Career Champion,Rebounds Per Game Season Champion,Rebounds Per Game Career Champion,Rebounds Career Champion,Assists Per Game Season Champion,Assists Per Game Career Champion,Assists Career Champion,Steals Per Game Season Champion,Steals Per Game Career Champion,Steals Career Champion,Blocks Per Game Season Champion,Blocks Per Game Career Champion,Blocks Career Champion,Minutes Per Game Season Champion,Minutes Per Game Career Champion,Minutes Played Career Champion,Player Efficiency Rating Season Champion,Player Efficiency Rating Career Champion,Wins Shares Season Champion,Wins Shares Career Champion,Wins Shares Per 48 Minutes Season Champion,Wins Shares Per 48 Minutes Career Champion,Plus Minus Season Champion,Plus Minus Career Champion,Offensive Rating Season Champion,Offensive Rating Career Champion,Defensive Rating Season Champion,Defensive Rating Career Champion,Field Goal Percentage Season Champion,Field Goal Percentage Career Champion,2 Point Field Goal Percentage Season Champion,2 Point Field Goal Percentage Career Champion,3 Point Field Goal Percentage Season Champion,3 Point Field Goal Percentage Career Champion,Free Throw Percentage Season Champion,Free Throw Percentage Career Champion,Effective Field Goal Percentage Season Champion,Effective Field Goal Percentage Career Champion,True Shooting Percentage Season Champion,True Shooting Percentage Career Champion,Triple Double Season Champion,Triple Double Career Champion */