simple stat script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

simple stat script

Started by coreno, 19 January, 2007, 17:13:58

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

coreno

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

CrazyGuy

when is it suppose to save ? on script start ? on hub close ? on timer ?

coreno

hmm, is it possible to have it save at every join/part? if not, I guess a timer works

CrazyGuy

sure it is possible at every login/removal ( although I wouldn't call that optimal )

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

CrazyGuy

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

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

coreno

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.

CrazyGuy

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
.."\nusermax="..frmHub:GetMaxUsers()


to this line
.."\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.

coreno

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)

coreno

Here is the PHP script that goes along with it.
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;
 	}
}

CrazyGuy

I'm not sure why you receive that error, but you can simply remove the line
collectgarbage("count")


It will not alter the functionality of the script

coreno

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.

coreno

Quote from: Mutor on 21 January, 2007, 17:12:27
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

SMF spam blocked by CleanTalk