I am looking for a script which shall give me the Chat Statistics, but the Chat Statistics of the users who speaks least! A Chat Stats inverted! :D
Is it possible for a great Developer Man (I'm thinking about Chilla :] ) to write this kind of script for me?
i think in almost most hubs the stats are going too look the same. 10 ppl with 0 chars
funny request but since I wanted to do something , like that anyways once, I decided to do it know :)
it also changeable , cause I'd prefer it the other way around ;).
--Chat stats by chill for xjr13sp.
--Serialisation by RabidWombat
cmd1 = "+showstats" -- Main Command
Max1 = 10 -- How Many top chatters are shown of each genre.
howToSort = 1 -- Stands for the sorting either 1= least first, 2 = highest first.
StatsFile = "ChatStats.txt"
StatsFolder = "txt"
ChatStats = {}
dofile(StatsFolder.."/"..StatsFile)
chatEmotions = {
[":)"] = 1,
[":-)"] = 1,
[":("] = 1,
[":-("] = 1,
[";)"] = 1,
[";-)"] = 1,
[":-p"] = 1,
[":p"] = 1,
[":D"] = 1,
[":-D"] = 1,
}
function Main()
SetTimer(1000*60*5)
StartTimer()
end
function OnTimer()
WriteTable(ChatStats,"ChatStats",StatsFile)
end
function DataArrival(curUser,data)
if strsub(data,1,1) == "<" then
if not ChatStats[curUser.sName] then
ChatStats[curUser.sName] = {}
ChatStats[curUser.sName].words = 0
ChatStats[curUser.sName].chars = 0
ChatStats[curUser.sName].emotions = 0
end
data = strsub(data,strlen(curUser.sName)+4,strlen(data)-1)
curName = curUser.sName
gsub(data,"(%S+)",function(w)
ChatStats[curName].chars = ChatStats[curName].chars + strlen(w)
if chatEmotions[w] then
ChatStats[curName].emotions = ChatStats[curName].emotions + 1
else
ChatStats[curName].words = ChatStats[curName].words + 1
end
end)
curName = nil
local _,_,word1 = strfind(data,"^(%S+)")
if word1 and STATSFUNC[word1] then
SendToAll(STATSFUNC[word1]())
end
end
end
---------------------------------------------------------------------------------------
-- TABLE FUNCTIONS
---------------------------------------------------------------------------------------
STATSFUNC = {
[cmd1] = function()
TCopy = {}
for i,v in ChatStats do
tinsert(TCopy,{i,v})
end
local msg = "----- Current Chat Stats ------\r\n\r\n\tTop "..Max1.." Char Stats\r\n\r\n"
if howToSort == 1 then
sort(TCopy,function(a,b) return(a[2].chars < b[2].chars) end)
else
sort(TCopy,function(a,b) return(a[2].chars > b[2].chars) end)
end
for i = 1,Max1 do
if TCopy[i] then
msg = msg.."\t# "..i.." - "..TCopy[i][1]..", with "..TCopy[i][2].chars.." chars.\r\n"
end
end
if howToSort == 1 then
sort(TCopy,function(a,b) return(a[2].words < b[2].words) end)
else
sort(TCopy,function(a,b) return(a[2].words > b[2].words) end)
end
msg = msg.."\r\n\tTop "..Max1.." Word Stats\r\n\r\n"
for i = 1,Max1 do
if TCopy[i] then
msg = msg.."\t# "..i.." - "..TCopy[i][1]..", with "..TCopy[i][2].words.." words.\r\n"
end
end
if howToSort == 1 then
sort(TCopy,function(a,b) return(a[2].emotions < b[2].emotions) end)
else
sort(TCopy,function(a,b) return(a[2].emotions > b[2].emotions) end)
end
msg = msg.."\r\n\tTop "..Max1.." Emotion Stats\r\n\r\n"
for i = 1,Max1 do
if TCopy[i] then
msg = msg.."\t# "..i.." - "..TCopy[i][1]..", with "..TCopy[i][2].emotions.." emotions.\r\n"
end
end
return(msg)
end,
}
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
function WriteTable(table,tablename,file)
local handle = openfile(StatsFolder.."/"..file,"w")
Serialize(table,tablename,handle)
closefile(handle)
end
--------------------------------------------
function Serialize(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
write(hFile,sTab..sTableName.." = {\n");
for key,value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
write(hFile,sTab.."\t"..sKey.." = "..sValue);
end
write(hFile,",\n");
end
write(hFile,sTab.."}");
end
You are so marvellous Chilla :D
I'll test your script this evening and keep you informed about results....
Many thanks !