Author Topic: simple stat script  (Read 6361 times)

0 Members and 1 Guest are viewing this topic.

Offline coreno

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
simple stat script
« on: 19 January, 2007, 17:13:58 »
All I need is a simple script to save the current number of users and total hub share, to a file. You can take it a step further and also have it save the max share and the max number of users. I would do this myself, but currently don't have the time or patience to learn LUA.

My goal is to create a web interface using PHP to view basic hub information. I've already have it reading the userlists, and plan/hope to take it further. i.e. allow management of registrations, view user data, etc...

It is theoretically possible to go as far as to interact with users on the hub from the web... but i'm not worried about that at the moment :p

PtokaX forum

simple stat script
« on: 19 January, 2007, 17:13:58 »

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: simple stat script
« Reply #1 on: 19 January, 2007, 19:52:33 »
when is it suppose to save ? on script start ? on hub close ? on timer ?

Offline coreno

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
Re: simple stat script
« Reply #2 on: 19 January, 2007, 21:10:34 »
hmm, is it possible to have it save at every join/part? if not, I guess a timer works

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: simple stat script
« Reply #3 on: 19 January, 2007, 22:06:10 »
sure it is possible at every login/removal ( although I wouldn't call that optimal )

Code: [Select]
fStats = "stats.log" --filename it is stored in, in scripts folder

NewUserConnected = function(User)
local sInfo = "usertotal="..frmHub:GetUsersCount()
.."\nusermax="..frmHub:GetMaxUsers()
.."\nsharetotal="..frmHub:GetCurrentShareAmount()
.."\nsharemax="..frmHub:GetMaxShare()
local fHandle = io.open(fStats, "w+")
if fHandle then
fHandle:write(sInfo)
fHandle:flush()
fHandle:close()
end
collectgarbage("count")
end
OpConnected = NewUserConnected
UserDisconnected = NewUserConnected
OpDisconnected = NewUserConnected

During testing, I noticed the stats are 1 function call behind.
If you have 2 users, the file will show 1 file. If 1 disconnects, it will show 2  :P
The stats are correct, just updated a bit later

also i wanted to point out that you wanted the hubs total share, and the max share.
Note that max share is max share per user, not per hub

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: simple stat script
« Reply #4 on: 19 January, 2007, 22:18:36 »
just to be clear i'll add this reply rather than updating the first so it shows why i did what i did.
This should fix the 1 user behind issue

Code: [Select]

fStats = "stats.log" --filename it is stored in, in scripts folder

NewUserConnected = function(User)
SaveInfo(1, User.iShareSize)
end
OpConnected = NewUserConnected

UserDisconnected = function(User)
SaveInfo(-1, (User.iShareSize * -1))
end
OpDisconnected = UserDisconnected

SaveInfo = function(iCor, iShare)
local sInfo = "usertotal="..(frmHub:GetUsersCount() + iCor)
.."\nusermax="..frmHub:GetMaxUsers()
.."\nsharetotal="..(frmHub:GetCurrentShareAmount() + iShare)
.."\nsharemax="..frmHub:GetMaxShare()
local fHandle = io.open(fStats, "w+")
if fHandle then
fHandle:write(sInfo)
fHandle:flush()
fHandle:close()
end
collectgarbage("count")
end

Offline coreno

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
Re: simple stat script
« Reply #5 on: 19 January, 2007, 22:33:05 »
thanks a lot :)

hope i'm not being too much of a pest, but i meant peak # of users, seems like you've got it grabbing the... well, maximum allowed.
also the peak share (which is also what meant, i think you understood that though) remains at 0.

Thanks for the help, and sorry for the confusion.

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: simple stat script
« Reply #6 on: 20 January, 2007, 10:13:23 »
I found 2 function calls in the API that will help on the peak user level.

frmHub:GetActualUsersPeak()
frmHub:GetMaxUsersPeak()

I'm not a 100% sure on which you will need, so therefor I put both here and you can change the line of code in the above script with the appropriate one.
Assumed is that GetActualUsersPeak() shows peak since hub start while GetMaxUsersPeak() shows peak since hubsoft installation.
Here's how to use the first one:

change this line of code
Code: [Select]
.."\nusermax="..frmHub:GetMaxUsers()

to this line
Code: [Select]
.."\nuserpeak="..frmHub:GetActualUsersPeak()

If you'd like to use the other 1 then change the same line accordingly.

I was not able to find an exportation of the hub's peak share however.
So with that I won't be able to help out.
It would still be possible, by storing the sharesize on login and comparing it to a stored value, but it will be some more work.

Offline coreno

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
Re: simple stat script
« Reply #7 on: 21 January, 2007, 04:45:41 »
Thanks a bunch for the help guys... i need to get around to learning LUA so I don't have to keep bugging you :p

I'm getting this error from the script everytime someone joins/parts:
stats.lua:24: bad argument #1 to `collectgarbage' (number expected, got string)

Offline coreno

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
Re: simple stat script
« Reply #8 on: 21 January, 2007, 07:40:52 »
Here is the PHP script that goes along with it.
Code: [Select]
function getStats(){
/*****************
Written by coreno (coreno {at} gmail.com)
Jan. 2007
Code may be distributed freely, please leave credits intact
Please note any changes
For use with custom PtokaX script:
http://forum.ptokax.org/index.php?topic=6744.0

returns multi-dimensional array
$stat[0][1] = current # of users in hub
$stat[1][1] = peak # of users in hub since restart
$stat[2][1] = current total shared
*****************/
$file = ""; //location of log file
if (is_readable($file)){
$temp = file($file);
for($i=0; $i<count($temp); $i++){
$stat[] = split("=",$temp[$i]);
  }
return $stat;
}
else{
echo "Error: <tt>$file</tt> is not readable.";
return false;
  }
}

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: simple stat script
« Reply #9 on: 21 January, 2007, 15:18:51 »
I'm not sure why you receive that error, but you can simply remove the line
Code: [Select]
collectgarbage("count")
It will not alter the functionality of the script

Offline coreno

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
Re: simple stat script
« Reply #10 on: 21 January, 2007, 16:48:31 »
I think I tried upgrading to a later PtokaX, but I remember it causing issues with many of the scripts I used or wanted to use, so I went back to the old one for now, until the scripts could catch up.

Offline coreno

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
Re: simple stat script
« Reply #11 on: 21 January, 2007, 17:18:37 »
ou have many options to convert scripts. There isn't very
much different but enough to cause fatal errors :P

Download 50to51.lua [script] or 50to51_1.02.rar [executable GUI] here:

.::Mutor's Archive - 5.1.1 Downloads::.

if interested.
lol, I remember trying that, but it wasn't perfect. :p Well, when I get the chance to upgrade, I'll be here trying to get everything fixed :p

PtokaX forum

Re: simple stat script
« Reply #11 on: 21 January, 2007, 17:18:37 »