% of Time Logged into hub.
 

% of Time Logged into hub.

Started by merlin_xl54, 04 July, 2008, 04:53:27

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

merlin_xl54

Hi,

I'm looking for a script to track % of time a user is logged in. Private Hub/All Registered Users. 130 steady users of 400 Registered. Rest drop in time to time. No IP info needed.

Something like user <merlin_xl54> has been online 26.29% of the time (since -07-03-2003 or First seen)
I found one of Mutor's scrips, NetLog or something but does not do quite what I want.
I would like it to store a table or file with initial login date/time etc. and go from there. Hub is online 24/7. Minor stop/starts.

Is this possible?

PtokaX 0.4.0.0
Get Password 3.0
User Alert 2.0
AwayMsg 1.0b
freshstuff3 5.1
Snowball War
TIA

M
Living is easy with eyes closed.

CrazyGuy

I recently wrote a script for myself that does about the same thing.
It shows last login, last spoken in main/pm , number of times spoken and searched.
It's pretty basic but it might cover your needs.

To get info on a user, type !accountstats <nick>

--[[
Account activity Checker
by CrazyGuy
requested by [FIN]miku82
written in LUA 5.1.x
Last updated June 11th 2008

This script stores the date/time a registered user last logged in
Command to get the info is !accountstats <nick>
Only profile 0 (Master) is allowed to use this command
]]--

OnStartup = function()
	sBotname = "<"..SetMan.GetString(21).."> "
	tLoginTable = {}
	local hFile = io.open(Core.GetPtokaXPath().."scripts/accountstats.tbl")
	if hFile then
		hFile:close()
		tLoginTable.items = dofile(Core.GetPtokaXPath().."scripts/accountstats.tbl")
	end
	local tRegs = Core.GetOnlineRegs()
	for k in pairs(tRegs) do
		if tLoginTable[tRegs[k].sNick] then
			tLoginTable[tRegs[k].sNick][1] = os.date().." (script start)"
			tLoginTable[tRegs[k].sNick][2] = "Online"
		else
			tLoginTable[tRegs[k].sNick] = { os.date().." (script start)", "Online", "Never", 0, "Never", 0, "Never", 0, }
		end
	end
end

OnExit = function()
	if (tLoginTable) then
		local hFile = io.open(Core.GetPtokaXPath().."scripts/accountstats.tbl", "w+")
		if hFile then
			hFile:write(Serialize(tLoginTable,"tLoginTable"))
			hFile:flush()
			hFile:close()
		else
			Core.SendToAll(sBotname.."Unable to store loginstats to disk. Disk full?")
		end
	end
end

OnError = function(sError)
	Core.SendToAll(sBotname..sError.."|")
end

ChatArrival = function(tUser,sData)
	if tUser.iProfile > -1 then
		tLoginTable[tUser.sNick][3] = os.date()
		tLoginTable[tUser.sNick][4] = tLoginTable[tUser.sNick][4] + 1
	end
	local _,_,sCmd,sNick = sData:find("%b<>%s%p(%S+)%s(.*)|")
	if sCmd and sNick then
		if sCmd == "accountstats" then
			if tUser.iProfile == 0 then
				if tLoginTable[sNick] then
					Core.SendToUser(tUser,sData..sBotname.."Showing accountstats of "..sNick.."\n\n"
						.."\t\tLast Login:\t\t\t"..tLoginTable[sNick][1].."\n"
						.."\t\tCurrent status:\t\t\t"..tLoginTable[sNick][2].."\n"
						.."\t\tLast spoken in mainchat:\t\t"..tLoginTable[sNick][3].."\n"
						.."\t\tTotal number of mainchat messages:\t"..tLoginTable[sNick][4].."\n"
						.."\t\tLast spoken in pm:\t\t\t"..tLoginTable[sNick][5].."\n"
						.."\t\tTotal number of private messages:\t"..tLoginTable[sNick][6].."\n"
						.."\t\tLast searched the hub:\t\t"..tLoginTable[sNick][7].."\n"
						.."\t\tTotal number of search requests:\t"..tLoginTable[sNick][8].."\n|")
				else
					Core.SendToUser(tUser,sData..sBotname..sNick.." has never been online.|")
				end
			else
				Core.SendToUser(tUser, sData..sBotname.."You are not allowed to use this command.|")
			end
			return true
		end
	end
end

ToArrival = function(tUser,sData)
	if tUser.iProfile > -1 then
		tLoginTable[tUser.sNick][5] = os.date()
		tLoginTable[tUser.sNick][6] = tLoginTable[tUser.sNick][4] + 1
	end
	local _,_,sTo,sCmd,sNick = sData:find("%$To%:%s(%S+)%sFrom%:%s%S+%s%$%b<>%s%p(%S+)%s(.*)|")
	if sTo and sCmd and sNick then
		if sTo == SetMan.GetString(21) then
			if sCmd == "accountstats" then
				if tUser.iProfile == 0 then
					if tLoginTable[sNick] then
						Core.SendPmToUser(tUser,SetMan.GetString(21),"Showing accountstats of "..sNick.."\n\n"
						.."\t\tLast Login:\t\t\t"..tLoginTable[sNick][1].."\n"
						.."\t\tCurrent status:\t\t\t"..tLoginTable[sNick][2].."\n"
						.."\t\tLast spoken in mainchat:\t\t"..tLoginTable[sNick][3].."\n"
						.."\t\tTotal number of mainchat messages:\t"..tLoginTable[sNick][4].."\n"
						.."\t\tLast spoken in pm:\t\t\t"..tLoginTable[sNick][5].."\n"
						.."\t\tTotal number of private messages:\t"..tLoginTable[sNick][6].."\n"
						.."\t\tLast searched the hub:\t\t"..tLoginTable[sNick][7].."\n"
						.."\t\tTotal number of search requests:\t"..tLoginTable[sNick][8].."\n|")
					else
						Core.SendPmToUser(tUser,SetMan.GetString(21),sNick.." has never been online.|")
					end
				else
					Core.SendPmToUser(tUser,SetMan.GetString(21),"You are not allowed to use this command.|")
				end
				return true
			end
		end
	end
end

RegConnected = function(tUser)
	if tLoginTable[tUser.sNick] then
		tLoginTable[tUser.sNick][1] = os.date()
		tLoginTable[tUser.sNick][2] = "Online"
	else
		tLoginTable[tUser.sNick] = { os.date(), "Online", "Never", 0, "Never", 0, "Never", 0, }
	end
end
OpConnected = RegConnected

RegDisconnected = function(tUser)
	tLoginTable[tUser.sNick][2] = "Offline since "..os.date()
end
OpDisconnected = RegDisconnected

SearchArrival = function(tUser,sData)
	if tUser.iProfile > -1 then
		tLoginTable[tUser.sNick][7] = os.date()
		tLoginTable[tUser.sNick][8] = tLoginTable[tUser.sNick][4] + 1
	end
end

Serialize = function(tTable, sTableName, sTab)
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in pairs(tTable) do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end
		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end



merlin_xl54

Quote from: CrazyGuy on 04 July, 2008, 15:09:05
I recently wrote a script for myself that does about the same thing.
It shows last login, last spoken in main/pm , number of times spoken and searched.
It's pretty basic but it might cover your needs.

To get info on a user, type !accountstats <nick>

Thanks,

That only shows me the last login etc. I was hoping to fine one that keeps track of the time a user is on. It is a small Hub.
Example user x 7/4 16 hours, 7/5 4 hours. (20 hours in 2 24 hour days) Then will output stats User X has been online 41.66% of the time.
Example user y 7/1 24 hours, 7/2 18 hours, 7/3 12 hours. (54 hours in 3 24 hour days) Then will output stats User y has been online 75.00%% of the time.

Maybe it's a web thing. This site shows how long I've been logged in etc.


TIA,

M

Living is easy with eyes closed.

CrazyGuy

that can be done.
Just right now I don't have the time for that, but maybe someone else

merlin_xl54

Thank You,

Maybe someone else will have time. I hope someday to learn this for myself and return all the favors....

M
Living is easy with eyes closed.

merlin_xl54

Quote from: Mutor on 06 July, 2008, 22:50:26
I'd done this in my top ten script.
If you don't want all of that, feel free to use it as example.

Thanks Mutor...

The Uptimes is what I want the most. Would it be easy to change that for all users and remove the other info? If not, does it use a lot of resources? I could leave the other info and not use it. If I can change a value or something to make it for all users I would love to try it.

TIA,

M
Living is easy with eyes closed.

merlin_xl54

Hi Mutor,

Sorry for any confusion. I should have been more clear. What I meant by all users was all registered (say 100) users. I want to show the uptime count for all users. I figured out how to remove the menu commands and I know how to disable all profiles but master. Some scripts let you change counts from 10 to 100 etc.

If there is a way to change the uptime count I would appreciate it.

Thanks again,

M
Living is easy with eyes closed.

merlin_xl54

Thanks anyway....

You've helped quite a bit with other scripts for me. ;)

M
Living is easy with eyes closed.

SMF spam blocked by CleanTalk