mIRC Home    About    Download    Register    News    Help

Print Thread
#171952 03/03/07 09:07 AM
Joined: Mar 2006
Posts: 25
T
tekano Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Mar 2006
Posts: 25
I have a very basic top 10 stats script that allows me to create a top10 of the talkers in a channel.
The thing is, I can't use it in a large channel because the .ini file the data is stored in, is too large at some point.

Here's the code to call the top10:
Code:
alias top {
  var %d = 1, %w = @top10, %file = wordsso.ini
  window -hn %w
  clear %w
  while $ini(%file,%d) {
    aline %w $v1 $readini(%file,$v1,words)
    inc %d
  }
  filter -cteuww 2 32 %w %w
  var %k = 1, %c
  while %k <= 10  {
    %c = %c $+($chr(32),12,$chr(35),%k,) $iif($line(%w,%k),$v1,*)
    inc %k
  }
  window -c %w
  return %c
}


Now is there a better solution, than to just store the info in a .ini file?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I'd check the information that is being saved to the ini file, and ensure that it's just what is needed to track the top 10, as I've seen people use scripts like what you're using on channels where there are hundreds of chatters and they haven't had any problems.

Joined: Mar 2006
Posts: 25
T
tekano Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Mar 2006
Posts: 25
Code:
on *:text:*:#: {
    if ( $readini words.ini $nick $right(words,5) == $null ) {
      writeini words.ini $nick $right(words,5) $0
    }
    else {
      set %words $readini words.ini $nick $right(words,5)
      set %newwords $calc(%words + $0)
      writeini words.ini $nick $right(words,5) %newwords
      unset %words
      unset %newwords
    }
}


Forgive me for the whole set/unset thingy, but I couldn't find any other way to make it work.

Anyway, this just counts the amount of words everyone speaks.

Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
use mine.
Code:
on *:start:hmake top10 1000 | hload top10 top10.hsh
on *:exit:hsave -a top10 top10.hsh
on me:*:join:#:hadd top10 $+(joined/,#) $ctime
on *:text:*:#:{
  hinc -m top10 $+($nick,/,#)
  if (%top10v) unset %top10v
  if ($1 = !lines) { top10 # $nick | set -z %top10p 5 }
  if ($regex(top10,$1,/^\!top(\d\d?)$/)) {
    if (%top10p) { .notice TopUsers: flood protection triggered. please wait 20 | return }
    if ($regml(top10,1) isnum 5-10) {
      .notice $nick TopUsers: The list is according to the time i've joined the channel on which: $asctime($hget(top10,$+(joined/,#)))
      top10 # $regml(top10,1) $nick
      .notice $nick TopUsers: Average lines difference is %top10v
      set -z %top10p 20
    }
    elseif ($regml(top10,1) isnum 5-10) .notice $nick TopUsers: please specify a number within this range 5-10
  }
}
alias top10 {
  if (!$window(@top10)) window -h @top10
  var %a = 1,%r
  while %a <= $hget(top10,0).item {
    if ($1 isin $hget(top10,%a).item) && (joined/ !isin $hget(top10,%a).item) {
      aline @top10 $+($hget(top10,%a).item,=,$hget(top10,%a).data)
    }
    inc %a
  }
  filter -cwwtue 2 $asc(=) @top10 @top10 *
  if ($left($2,1) !isnum) goto next
  %a = 1
  while $line(@top10,%a) {
    var %b = %b $+($chr(22),[,%a,],$chr(22)) $iif($token($token($ifmatch,1,$asc(=)),1,$asc(/)) ison $1,$+($chr(2),$v1,$chr(2)),$v1) $+($chr(40),$token($line(@top10,%a),2,$asc(=)),$chr(41))
    set %top10v $addtok(%top10v,$token($ifmatch,2,$asc(=)),$asc(-))
    if (%a = $2) break
    inc %a
  }
  msg $1 Top $+ $2 $+ (Lines): %b $+($chr(22),$chr(32),$chr(2),$chr(32),$chr(2),$chr(22))
  set %top10v $abs($calc($calc(%top10v) / $numtok(%top10v,$asc(-))))
  :next
  if ($left($2,1) !isnum) .notice $2 TopUsers: You wrote on $remove($1,#) $hget(top10,$+($2,/,$1)) $iif($hget(top10,$+($2,/,$1)) > 1,lines,lines) $+ . (You are at the $ord($fline(@top10,$+(/,$2,\//i),1,2)) position in the rank.)
  window -c @top10
}


Kind Regards, blink
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Yeah, hash tables are much faster and better for such a script. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Mar 2006
Posts: 25
T
tekano Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Mar 2006
Posts: 25
how would I make this for words instead of lines?

Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
replace hinc -m top10 $+($nick,/,#) with:
Code:
hinc -m top10 $+($nick,/,#) $regex($1-,/\S+/g)


Kind Regards, blink
Joined: Mar 2006
Posts: 25
T
tekano Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Mar 2006
Posts: 25
and should the top10 option automatically replace the "lines" top10 with the "words" top10?

Or do I have to reset the scores or something?

Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
you could do hfree -s top10 then change anything you want.


Kind Regards, blink
Joined: Mar 2006
Posts: 25
T
tekano Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Mar 2006
Posts: 25
So, now I have this, and now it doesn't make any sense anymore :P (the top10 gives me something totally different than what I have to get):

Code:
on *:start:hmake top10 1000 | hload top10 top10.hsh
on *:exit:hsave -a top10 top10.hsh
on me:*:join:#:hadd top10 $+(joined/,#) $ctime
on *:text:*:#:{
  hinc -m top10 $+($nick,/,#) $regex($1-,/\S=/g)
  if (%top10v) unset %top10v
  if ($1 = !lines) { top10 # $nick | set -z %top10p 5 }
  if ($nick isop #) {
    if ($regex(top10,$1,/^\!top(\d\d?)$/)) {
      if (%top10p) { .notice TopUsers: flood protection triggered. please wait 20 | return }
      if ($regml(top10,1) isnum 5-10) {
        .notice $nick TopUsers: The list is according to the time i've joined the channel on which: $asctime($hget(top10,$+(joined/,#)))
        top10 # $regml(top10,1) $nick
        .notice $nick TopUsers: Average lines difference is %top10v
        set -z %top10p 20
      }
      elseif ($regml(top10,1) isnum 5-10) .notice $nick TopUsers: please specify a number within this range 5-10
    }
  }
}

alias top10 {
  if (!$window(@top10)) window -h @top10
  var %a = 1,%r
  while %a <= $hget(top10,0).item {
    if ($1 isin $hget(top10,%a).item) && (joined/ !isin $hget(top10,%a).item) {
      aline @top10 $+($hget(top10,%a).item,=,$hget(top10,%a).data)
    }
    inc %a
  }
  filter -cwwtue 2 $asc(=) @top10 @top10 *
  if ($left($2,1) !isnum) goto next
  %a = 1
  while $line(@top10,%a) {
    var %b = %b $+($chr(22),[,%a,],$chr(22)) $iif($token($token($ifmatch,1,$asc(=)),1,$asc(/)) ison $1,$+($chr(2),$v1,$chr(2)),$v1) $+($chr(40),$token($line(@top10,%a),2,$asc(=)),$chr(41))
    set %top10v $addtok(%top10v,$token($ifmatch,2,$asc(=)),$asc(-))
    if (%a = $2) break
    inc %a
  }
  msg $1 Top $+ $2 $+ (Lines): %b $+($chr(22),$chr(32),$chr(2),$chr(32),$chr(2),$chr(22))
  set %top10v $abs($calc($calc(%top10v) / $numtok(%top10v,$asc(-))))
  :next
  if ($left($2,1) !isnum) .notice $2 TopUsers: You wrote on $remove($1,#) $hget(top10,$+($2,/,$1)) $iif($hget(top10,$+($2,/,$1)) > 1,lines,lines) $+ . (You are at the $ord($fline(@top10,$+(/,$2,\//i),1,2)) position in the rank.)
  window -c @top10
}


* thinks he should learn some more about hash tables.

Last edited by tekano; 03/03/07 08:31 PM.

Link Copied to Clipboard