Getting stats

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DarkLink
    New Member
    • Mar 2009
    • 5

    Getting stats

    Hey,
    Is there a way using PHP to get certain statistics from a specific website and arrange them on an image? (Yes, it is typically a dynamic image generator.)
  • Amzul
    New Member
    • Oct 2007
    • 130

    #2
    for the picture part you can use rrdtools to create a graph and jpg it.
    i assume you have access to that website you want to gather information about.
    you can customize your apache log and from that log create the graph.
    by using a script that runs as cronjob and refresh your rrdtools graph.

    Comment

    • DarkLink
      New Member
      • Mar 2009
      • 5

      #3
      In fact, what I'm trying to do is get some stats from a certain game website, such as kills and those stuff depending on the user that has been input. It is for promotional puposes for my website.

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        You will need to make your own for that. You will have to record a history and then query the target user to collect the history for that user. This could become a very big database and could take some time to set up, but when I am finished my game I will have something like that, so it can be done! Not sure about graphing yet though.

        Comment

        • DarkLink
          New Member
          • Mar 2009
          • 5

          #5
          This would probably be an example of what I want:

          Code:
          <?
          $accountName = $_GET['name'];
          $statsURL = "http://example.com/profile/$accountName?xml=true";
          
          $stats = @simplexml_load_file($statsURL) or die("Failed to retreieve stats XML for user $accountName");
          
          header("Content-type: image/png");
          $img = imagecreatefrompng("bg.png");
          
          // Colors
          $c_white = imagecolorallocate($img, 255, 255, 255);
          $c_black = imagecolorallocate($img, 0, 0, 0);
          
          // Misc
          $statsLeft = 160;
          $statsTop = 5;
          
          // Name & Rank
          $nameString = $stats->user_info['military_rank'] . " " . $stats->user_info['username'];
          $size = 18;
          $bbox = imagettfbbox($size, 0, "./helr67w.ttf", $nameString);
          while ($bbox[4] > (imagesx($img) - $statsLeft - 4)) {
          	$size--;
          	$bbox = imagettfbbox($size, 0, "./helr67w.ttf", $nameString);
          }
          
          // Clan
          if ($stats->user_info->clan['clan_name'] != "") $clanString = $stats->user_info->clan['clan_name'] ."\n";
          
          // General Stats
          $timeString = "Hours Played: " . round($stats->misc['total_time_played'] / 3600, 2);
          $xpString = "XP: " . round($stats->total['xp']);
          $rankString = "Rank: " . $stats->user_info['rank'];
          
          // K/D Ratio
          $kills = $stats->misc['total_kills'];
          $deaths = $stats->misc['total_deaths'];
          $ratio = round((float) $stats->total['kill_death_ratio'], 2);
          $ratioString = "K/D: $kills/$deaths ($ratio)";
          
          
          // Favorite Class
          $timeArray = array();
          foreach ($stats->classes->children() as $class) $timeArray[$class->getName()] = (string) $class['time_used'];
          arsort($timeArray);
          $classImg = imagecreatefrompng("classes/".key($timeArray).".png");
          imagecopy($img, $classImg, 5, 5, 0, 0, imagesx($classImg), imagesy($classImg));
          
          // Favorite Vehicle
          $timeArray = array();
          foreach ($stats->vehicles->children() as $vehicle) $timeArray[$vehicle->getName()] = (string) $vehicle['total_time_spent'];
          arsort($timeArray);
          $vehicleImg = imagecreatefrompng("vehicles/".key($timeArray).".png");
          imagecopy($img, $vehicleImg, 82, 6, 0, 0, imagesx($vehicleImg), imagesy($vehicleImg));
          
          // Favorite Weapon
          $timeArray = array();
          foreach ($stats->weapons->children() as $weapon) $timeArray[$weapon->getName()] = (string) $weapon['time_used'];
          arsort($timeArray);
          while ( strstr(key($timeArray),"combined") ) next($timeArray);
          $weaponImg = imagecreatefrompng("weapons/".key($timeArray).".png");
          imagecopy($img, $weaponImg, 82, 53, 0, 0, imagesx($weaponImg), imagesy($weaponImg));
          
          
          // Draw the text
          imagettftext($img, $size, 0, $statsLeft + 2, $statsTop + 22, $c_black, "./helr67w.ttf", $nameString);
          imagettftext($img, $size, 0, $statsLeft, $statsTop + 20, $c_white, "./helr67w.ttf", $nameString);
          
          $statsText = <<<EOT
          $rankString
          $timeString
          $xpString
          $ratioString
          EOT;
          
          imagettftext($img, 10, 0, $statsLeft + 1, $statsTop + 41, $c_black, "./helr65w.ttf", $statsText);
          imagettftext($img, 10, 0, $statsLeft, $statsTop + 40, $c_white, "./helr65w.ttf", $statsText);
          
          imagepng($img);

          Comment

          • Amzul
            New Member
            • Oct 2007
            • 130

            #6
            umm you want to get data from a website... that is not your?
            you can use curl to get the webpage and the game info
            and play with that info

            Comment

            • DarkLink
              New Member
              • Mar 2009
              • 5

              #7
              Yes, but another program would not do, that code was for getting statistics from: http://stats.enemyterritory.com/

              Comment

              Working...