PDA

View Full Version : PHP4/5 - LFSWorldSDK, class for stats retrieval


Pages : 1 [2]

Dygear
4th April 2010, 13:04
A vivid imagination, often a good sign of a strong overall programmer.

Dygear
6th April 2010, 07:21
I've made some gaint strides with this, that fell stunninly short due to a limitation in the PHP engine not allowing for consts to be assigned by expression within the class. (Augh!)

This is not valid PHP code, and it's such a pitty.

final class WorldSDK extends LFS
{
/* Constants */
// Strings
# 0: Makes no change to the LFS mark'ed up strings.
const STRING_NONE = (1 << 0);
# 1: Changes player names only.
const STRING_NAMES = (1 << 1);
# 2: Changes host names only.
const STRING_HOSTS = (1 << 2);
# 3: Changes both player names and host names.
const STRING_BOTH = STRING_NAMES & STRING_HOSTS;


Back to the drawing board.

DarkTimes
7th April 2010, 11:07
A const value needs to be a literal in most all languages I think. In C# you can work around this by using static readonly parameters to make the result of an expression constant, I don't know if PHP may have an equivalent you could use.

static readonly string STRING_NONE = (1 << 0).ToString();

Dygear
7th April 2010, 11:20
It's a constant value as it pertains to run time information. It's bugging the crap out of me that I can't find a work around for this as it would improve readability of the code by leaps and bounds.

Okram
24th May 2010, 14:49
In LFSWorldSDK1.9.5-Alpha-1 is warning:
Warning: Invalid error type specified in lfsworldsdk.php on line 49

Line 49 is
trigger_error('Your server\'s configuration is not supported by this version of LFSWorldSDK.', E_WARNING);

i do not understand what is wrong. Only {} was missing after else but this don't help.

PHP: php-5.2.9-2.fc10.i386
httpd: httpd-2.2.14-1.fc10.i386
Operating system is Linux - Fedora 10

Okram

filur
24th May 2010, 15:20
In LFSWorldSDK1.9.5-Alpha-1 is warning:

Change E_WARNING to E_USER_WARNING

Okram
24th May 2010, 15:47
Change E_WARNING to E_USER_WARNING
Nice, now this work. What does this warning is mean? What change in server configuration?

Okram

Dygear
24th May 2010, 16:41
Change E_WARNING to E_USER_WARNING

Your right, but I thought it would not ever get to that point unless file_get_contents was not enabled for remote warppers and cURL was not installed.

Speaking of file_get_contents and cURL, i've seen some benchmarks that show cURL is much faster. So I'll love that up to the first operation from now on.

Nice, now this work. What does this warning is mean? What change in server configuration?

Okram

nothing changed server side really, unless someone installed cURL on enabled fopen urls while you where waiting for an answer on this. He did fix my stupid mistake tho as only the engine can produce a E_WARNING, but I've never seen this to be a show stopping bug.

juniox_dias
16th December 2010, 02:26
hello, im trying to embed on a website some informations of get_pst.php , so i can't use that way of inserting username like this:

?racer=username

i need to know where i insert the racername on the code, i've tried to insert on code but didnt work, look what i've tried:

$pst = $SDK->get_pst($_GET['juniox_dias'])

it didnt work, so how can i embed this on a website without using ?racer=username ???

misiek08
16th December 2010, 06:33
$pst = $SDK->get_pst('juniox_dias');
Try this.

juniox_dias
16th December 2010, 12:18
$pst = $SDK->get_pst('juniox_dias');Try this.

i've tried what u said but, didnt work, look:

http://img338.imageshack.us/img338/690/semttulohhd.png


i think it didnt work becouse of this code above the one u said on get_pst.php :

<?php if (empty($_GET['racer'])): ?>
<form target="_SELF" method="GET">
<lable for="racer">LFS Username:</lable><input type="textbox" id="racer" name="racer" /><br />
<input type="submit" value="Get Info" />
</form>

yes, the ($_GET['racer']) is empty on the link , but this is what im trying to do :D

i tried to delete this line "if" but didnt work to =/ .


But thank u for helping, maybe u know how to help me.

thank u guys, im waiting more posts :D

juniox_dias
17th December 2010, 13:38
can someone help me ?

Dygear
17th December 2010, 19:13
<?php include('lfsworldsdk.php');
$racer = (empty($_GET['racer'])) ? 'juniox_dias' : urldecode($_GET['racer']);
?>
<html>
<head>
<title><?php echo (empty($racer)) ? 'Please Input a Racer\'s Name' : 'Page for ' . htmlentities($racer, ENT_QUOTES); ?></title>
</head>
<body>
<?php if (empty($racer)): ?>
<form target="_SELF" method="GET">
<label for="racer">LFS Username:</label><input type="textbox" id="racer" name="racer" /><br />
<input type="submit" value="Get Info" />
</form>
<?php else: ?>
<table>
<tbody>
<?php $pst = $SDK->get_pst($racer);
forEach ($pst[0] as $key => $val): ?>
<tr>
<?php switch ($key):
case 'distance': ?>
<th>Meters Driven</th>
<td><?php echo $val; ?></td>
<?php break;
case 'fuel': ?>
<th>Fuel burned in cl</th>
<td><?php echo $val; ?></td>
<?php break;
case 'laps': ?>
<th>Laps Driven</th>
<td><?php echo $val; ?></td>
<?php break;
case 'joined': ?>
<th>Hosts joined</th>
<td><?php echo $val; ?></td>
<?php break;
case 'win': ?>
<th>Race wins</th>
<td><?php echo $val; ?></td>
<?php break;
case 'races_finished': ?>
<th>Races finished</th>
<td><?php echo $val; ?></td>
<?php break;
case 'qual': ?>
<th>Qualifications</th>
<td><?php echo $val; ?></td>
<?php break;
case 'pole': ?>
<th>Pole positions</th>
<td><?php echo $val; ?></td>
<?php break;
case 'dragwins': ?>
<th>Drags won</th>
<td><?php echo $val; ?></td>
<?php break;
case 'ostatus': ?>
<th>Online status</th>
<td><?php
switch ($val) {
case 0: echo 'Offline'; break;
case 1: echo 'Spectating'; break;
case 2: echo 'In pits'; break;
case 3: echo 'In race'; break;
}
?></td>
<?php break;
case 'hostname': ?>
<th>Hostname</th>
<td><?php echo LFSWorldSDK::convert_lfs_text($val); ?></td>
<?php break;
case 'last_time': ?>
<th>Last active on</th>
<td><?php echo date('M jS Y @ H:i', $val); ?></td>
<?php break;
case 'track': ?>
<th>Track</th>
<td><?php echo LFSWorldSDK::convert_track_name($val); ?></td>
<?php break;
default:
?>
<th><?php echo ucwords($key); ?></th>
<td><?php echo $val; ?></td>
<?php endSwitch; ?>
</tr>
<?php endForEach; ?>
</tbody>
</table>
<?php endIf; ?>
</body>
</html>

juniox_dias
18th December 2010, 21:52
thank you a lot @Dygear ! it will works for me, i will insert a variable on racername for gridlfs league forum.


i just got this error, every information above hostname are ok but on hostname i got this:

Hostname
Fatal error: Call to undefined method LFSWorldSDK::convert_lfs_text() in /home2/gridlfsc/public_html/forum/lfswsdk/get_pst2.php on line 70

line 70:
<td><?php echo LFSWorldSDK::convert_lfs_text($val); ?></td>

what i have to do here?

Dygear
19th December 2010, 05:43
Make sure you have the latest version of LFSWorldSDK, as that has the function you need.

juniox_dias
19th December 2010, 19:06
thank you dygear, i updated the lfswsdk, now everything is ok :)

i just had a problem with that line 48 or 49 i've changed e_warning to e_user_warning, didnt work so i deleted the line and everything works good :D

im sorry that im noob on programming but im trying to get better =)

avetere
19th February 2011, 13:59
Just for info: Your missing at least one error-message, namely
pb: no valid username

Dygear
19th February 2011, 16:51
I'll keep that in mind, I was pretty sure that Victor gave me that list too.

avetere
1st March 2011, 13:08
Well, maybe that is a new one ...
also missing (I came across that one today): "fuel: no valid username"

Dygear
1st March 2011, 16:12
Victor, can you please post the whole list of error messages in the LFSWorld Stats thread.

Dygear
25th May 2011, 09:19
Victor, can you please post the whole list of error messages in the LFSWorld Stats thread.

And on that subject:

These should be all of them :

don't block your ip please.
Identification is required - http://www.lfsforum.net/showthread.php?t=14480
Invalid Ident-Key
not authed (invalid identkey)
not authed (ip)
Invalid login details provided
No authentication method provided.
can't reload this page that quickly after another
hl_log is only available since version 1.2 and later
no output
ch: invalid track
ch: invalid car
fuel: no valid username
hl: no racer
hl: no hotlaps found
pb: no valid username
pb: racer has no pbs
pst: no valid username

gandlers
27th July 2011, 21:37
Just discovered the SDK and am currently having a play.... fantastic work btw.
I have however noticed a "feature"; the SDK->get_pb function isnt retrieving (or returning maybe) the fuel column, if i query LFSW manually using the pubstat url i get a final fuel column.

I have tried to decypher the code to work out where the issue lies, but the code is a bit too complex for me to work out what the hell is going on.

I am using 1.9.5 alpha btw

cheers

Dygear
27th July 2011, 21:46
I'll be sure to update that when I get home, expect a fix in the next 12 hours.

gandlers
27th July 2011, 21:54
wow,

uber fast response... impressed :)

while im on i did make a slight change to the convert_lfsw_time function. changed the padding to make the second have a leading zero as times such as 1:07.34 would display as 1:7.34


function convert_lfsw_time($time) {
return sprintf('%d:%06.3F', floor($time / 60000), (($time % 60000) / 1000));
}

Dygear
27th July 2011, 22:26
Ok, I'll merge that in as well.

[Edit] The next version will be 1.9.9, and it will be the last version of this branch.

Dygear
28th July 2011, 06:04
Changed my mind, here is 1.9.6 with support for LFS Pub stats version 1.5 and so all of the things that come with it. All showcase pages are present, some have been updated, some have not.

gandlers
28th July 2011, 06:52
Dygear,

thanks, fuel column now appearing.

Excellent work.

Dygear
28th July 2011, 07:13
Version 1.9.7 includes full support for what was added in Version 1.5 of Victor's LFS World Pub Stats. Even more show case pages where updated, but not all of them are done.

gandlers
2nd August 2011, 17:46
Dygear,

just updated to 1.9.7, I'm afraid that PB retrieval isn't returning vales for split3. tried 1.9.6 and thats doing the same: just returns 0 for split 3 time.

cheers

G

gandlers
2nd August 2011, 18:08
scratch that...
its LFSW stats not returning split3 time.

avetere
2nd August 2011, 20:10
Be sure to get stats from a config that has 4 sectors.
Pubstat will always return the last split as laptime. So for example on BL1 you will get split1, split2 and laptime while split3 will be 0.
Thus you'll get split3 > 0 only on FE4, AS6 and AS7 ...
Any 2-sector-config will have split2 as 0 too ;)

Dygear
2nd August 2011, 20:25
Pretty much what avetere just said.

gandlers
2nd August 2011, 22:02
yeah, i'm having a retard moment.

had an error in the code i have been working on and was reading from the wrong bit of the array.

false alarm:chair:

three_jump
11th August 2011, 12:21
Is it intentional that the first post links to 1.9.3 instead to the more current 1.9.7 of the SDK?

Dygear
11th August 2011, 12:33
Is it intentional that the first post links to 1.9.3 instead to the more current 1.9.7 of the SDK?

Nope, over sight on my part. Thanks, going to fix this now.

paXton
11th August 2011, 19:48
Hi Dygear!

I just found a little mistake in the SDK.

IMHO the lines 430-433

if (($result = $this->make_query("&action=wr&track={$track}&car={$car}")) !== FALSE) {
foreach ($result as $i => $data)
$result[$i]['flags_hlaps'] = $this->convert_flags_hlaps($data);
}

should be

if (($result = $this->make_query("&action=wr&track={$track}&car={$car}")) !== FALSE) {
foreach ($result as $i => $data)
$result[$i]['flags_hlaps'] = $this->convert_flags_hlaps($data['flags_hlaps']);
}


Besides I would like to have the original flags_value stored somewhere like:

[flags_hlaps_raw] => 1537
[flags_hlaps] => Array
(
[1] => LEFTHANDDRIVE
[512] => AUTOCLUTCH
[1024] => MOUSESTEER
)

Otherwise I had to array_sum(array_keys(flags_hlaps)) to get it.

Keep up the good work.

Pascal aka paXton

Dygear
12th August 2011, 05:01
I tend to shy away from adding a property that does not belong there, but I agree that the information should be more flexible. I think in the case you described, there will be a proper fix for it in 2.0.0 as you can say how you want the data given to you.