mIRC Homepage
Posted By: tekano Ini file getting too large - 03/03/07 09:07 AM
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?
Posted By: RusselB Re: Ini file getting too large - 03/03/07 09:28 AM
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.
Posted By: tekano Re: Ini file getting too large - 03/03/07 10:51 AM
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.
Posted By: b1ink Re: Ini file getting too large - 03/03/07 01:33 PM
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
}
Posted By: Riamus2 Re: Ini file getting too large - 03/03/07 02:22 PM
Yeah, hash tables are much faster and better for such a script. smile
Posted By: tekano Re: Ini file getting too large - 03/03/07 03:20 PM
how would I make this for words instead of lines?
Posted By: b1ink Re: Ini file getting too large - 03/03/07 06:27 PM
replace hinc -m top10 $+($nick,/,#) with:
Code:
hinc -m top10 $+($nick,/,#) $regex($1-,/\S+/g)
Posted By: tekano Re: Ini file getting too large - 03/03/07 07:07 PM
and should the top10 option automatically replace the "lines" top10 with the "words" top10?

Or do I have to reset the scores or something?
Posted By: b1ink Re: Ini file getting too large - 03/03/07 08:11 PM
you could do hfree -s top10 then change anything you want.
Posted By: tekano Re: Ini file getting too large - 03/03/07 08:30 PM
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.
© mIRC Discussion Forums