473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.)
Mar 12 '09 #1
6 1330
Amzul
130 100+
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.
Mar 12 '09 #2
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.
Mar 12 '09 #3
TheServant
1,168 Expert 1GB
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.
Mar 12 '09 #4
This would probably be an example of what I want:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $accountName = $_GET['name'];
  3. $statsURL = "http://example.com/profile/$accountName?xml=true";
  4.  
  5. $stats = @simplexml_load_file($statsURL) or die("Failed to retreieve stats XML for user $accountName");
  6.  
  7. header("Content-type: image/png");
  8. $img = imagecreatefrompng("bg.png");
  9.  
  10. // Colors
  11. $c_white = imagecolorallocate($img, 255, 255, 255);
  12. $c_black = imagecolorallocate($img, 0, 0, 0);
  13.  
  14. // Misc
  15. $statsLeft = 160;
  16. $statsTop = 5;
  17.  
  18. // Name & Rank
  19. $nameString = $stats->user_info['military_rank'] . " " . $stats->user_info['username'];
  20. $size = 18;
  21. $bbox = imagettfbbox($size, 0, "./helr67w.ttf", $nameString);
  22. while ($bbox[4] > (imagesx($img) - $statsLeft - 4)) {
  23.     $size--;
  24.     $bbox = imagettfbbox($size, 0, "./helr67w.ttf", $nameString);
  25. }
  26.  
  27. // Clan
  28. if ($stats->user_info->clan['clan_name'] != "") $clanString = $stats->user_info->clan['clan_name'] ."\n";
  29.  
  30. // General Stats
  31. $timeString = "Hours Played: " . round($stats->misc['total_time_played'] / 3600, 2);
  32. $xpString = "XP: " . round($stats->total['xp']);
  33. $rankString = "Rank: " . $stats->user_info['rank'];
  34.  
  35. // K/D Ratio
  36. $kills = $stats->misc['total_kills'];
  37. $deaths = $stats->misc['total_deaths'];
  38. $ratio = round((float) $stats->total['kill_death_ratio'], 2);
  39. $ratioString = "K/D: $kills/$deaths ($ratio)";
  40.  
  41.  
  42. // Favorite Class
  43. $timeArray = array();
  44. foreach ($stats->classes->children() as $class) $timeArray[$class->getName()] = (string) $class['time_used'];
  45. arsort($timeArray);
  46. $classImg = imagecreatefrompng("classes/".key($timeArray).".png");
  47. imagecopy($img, $classImg, 5, 5, 0, 0, imagesx($classImg), imagesy($classImg));
  48.  
  49. // Favorite Vehicle
  50. $timeArray = array();
  51. foreach ($stats->vehicles->children() as $vehicle) $timeArray[$vehicle->getName()] = (string) $vehicle['total_time_spent'];
  52. arsort($timeArray);
  53. $vehicleImg = imagecreatefrompng("vehicles/".key($timeArray).".png");
  54. imagecopy($img, $vehicleImg, 82, 6, 0, 0, imagesx($vehicleImg), imagesy($vehicleImg));
  55.  
  56. // Favorite Weapon
  57. $timeArray = array();
  58. foreach ($stats->weapons->children() as $weapon) $timeArray[$weapon->getName()] = (string) $weapon['time_used'];
  59. arsort($timeArray);
  60. while ( strstr(key($timeArray),"combined") ) next($timeArray);
  61. $weaponImg = imagecreatefrompng("weapons/".key($timeArray).".png");
  62. imagecopy($img, $weaponImg, 82, 53, 0, 0, imagesx($weaponImg), imagesy($weaponImg));
  63.  
  64.  
  65. // Draw the text
  66. imagettftext($img, $size, 0, $statsLeft + 2, $statsTop + 22, $c_black, "./helr67w.ttf", $nameString);
  67. imagettftext($img, $size, 0, $statsLeft, $statsTop + 20, $c_white, "./helr67w.ttf", $nameString);
  68.  
  69. $statsText = <<<EOT
  70. $rankString
  71. $timeString
  72. $xpString
  73. $ratioString
  74. EOT;
  75.  
  76. imagettftext($img, 10, 0, $statsLeft + 1, $statsTop + 41, $c_black, "./helr65w.ttf", $statsText);
  77. imagettftext($img, 10, 0, $statsLeft, $statsTop + 40, $c_white, "./helr65w.ttf", $statsText);
  78.  
  79. imagepng($img);
  80.  
Mar 13 '09 #5
Amzul
130 100+
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
Mar 13 '09 #6
Yes, but another program would not do, that code was for getting statistics from: http://stats.enemyterritory.com/
Mar 13 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dan glenn | last post by:
My client wants to see stats which tell him the number of hits he's getting from different countries. I'm coding page hit count stats myself in PHP on his site, which is simple enough, but haven't...
8
by: Bob II | last post by:
Hey, I've never used PHP before. I was wondering if it is possible to use PHP to generate web stats. My web host's stats aren't very good. So I want to generate some custom stats for myself. ...
15
by: middletree | last post by:
How do I request the actual page name that I'm on? This is going to go into an include file, and depending on which page I'm on, I'd like to do different things. I'm looking for "pagename.asp"
0
by: dba | last post by:
Hi I am a new MySQL dba tuning a busy Apache/MySQL installation. Here are some of the statistics for the last 24 hours: Com_admin_commands 978,760 What "Admin_Commands" does this...
2
by: Derrick King | last post by:
COuld someone tell me if its possible to get hold of stats about all Databases on a SQL Server. The sort of things I would like are Name of DB Location of DB Size of DB Location of Logfile...
2
by: (PeteCresswell) | last post by:
Help Desk at a client site steered me to TaskMan's LAN stats window, but advised that Windows makes it's own decisions about how much bandwidth each app gets. Looks to me like there's plenty...
4
by: marklawford | last post by:
Not having earned my DBA badge from the scouts just yet I'm a little lost with an error I'm getting. We've just upgraded our development database from 7.2 to 8.2 as the first step in upgrading...
1
by: MKoool | last post by:
Is there any decent library for basic stats? I am just looking for the basics, like quartiles, median, standard deviation, mean, min, max, regression, etc. I was going to use SciPy, but I use...
1
by: tkpmep | last post by:
I installed SciPy and NumPy (0.9.5, because 0.9.6 does not work with the current version of SciPy), and had some teething troubles. I looked around for help and observed that the tutorial is dated...
4
by: jeff.maildump | last post by:
Hi, I've got multiple xmlhttprequests which are in a loop. So this is the loop I have so far, with the closure given to me in a previous post: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.