mIRC Home    About    Download    Register    News    Help

Print Thread
#142057 15/02/06 07:03 PM
Joined: Feb 2006
Posts: 164
V
vexed Offline OP
Vogon poet
OP Offline
Vogon poet
V
Joined: Feb 2006
Posts: 164
I have a request if someone could gladly help me out.
I made a little alias to show a few stats of my quotes.txt (which works fine) there was one bit i'd like to add to it, but don't really know where to start on this one.
I'd like to add the following to the alias below so it kinda shows like this

Quote stats: Chars: 6262 Words: 953 Size: 6.31KB Quotes: 61
top 3 quoters: #1 nick1 - 10 [%30] #2 nick2 - 7 [%25] #1 nick3 - 4 [%15]


Code:
alias qstats {
  var %file = $mircdirsystem/quotes.txt
  if ($exists(%file)) {
    var %size = $bytes($file(%file).size).suf, %lines = $lines(%file), %loop = 0,%chars = 0,%words = 0, %line
    while (%loop < %lines) {
      %line = $read(%file,%loop)
      %chars = $calc(%chars + $len(%line))
      %words = $calc(%words + $numtok(%line,32))
      inc %loop
    }
    /msg $chan Quote stats: Chars: %chars Words: %words Size: %size Quotes: %lines
  }
}  


i forgot to mention, the nicknames get added like this to the file.

1105977059 vexed <n1ck> 1st quote pls :tongue:
(write system/quotes.txt $ctime $nick $2-)

many thanks for some help.

Last edited by vexed; 15/02/06 07:26 PM.
#142058 15/02/06 07:18 PM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
This will also count spaces as characters, if you don't want to count those, change the following:

$len($line(@qstats,%i))

to

$len($remove($line(@qstats,%i),$chr(32)))

Code:
alias qstats {
  var %file = quotes.txt
  if ($exists(%file)) {
    window -h @qstats
    loadbuf @qstats quotes.txt
    var %i = 1, %l = $line(@qstats,0)
    var %words, %chars
    var %size = $bytes($file(%file).size).suf
    while (%i &lt;= %l) {
      %words = $calc(%words + $numtok($line(@qstats,%i),32))
      %chars = $calc(%chars + $len($line(@qstats,%i)))
      inc %i
    }
    window -c @qstats
    echo -a [Quote Stats] Words: %words - Chars: %chars - Size: %size - Quotes: %l
  }
}

#142059 15/02/06 07:20 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
What does each line look like?

schaefer31: I think he wants the top3 quoters part.

#142060 15/02/06 07:26 PM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Oops, I didn't really read it entirely :tongue:

However, though I'd suggest to use my given code over his for the stats part since overtime, his can be executing several calls to $read. Using loadbuf into an @window will run faster.

But also, it would help to post the line format for the top 3.

#142061 15/02/06 07:52 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
alias qstats {
  var %chars, %line, %lines, %size = $bytes(system\quotes.txt).suf, %user, %words
  window -hs @quotes
  .fopen quotes system\quotes.txt
  if (!$fopen(quotes)) return
  while (!$fopen(quotes).eof) {
    %line = $fread(quotes)
    %user = $gettok(%line,2,32)
    if ($fline(@quotes,%user *,1)) rline @quotes $v1 $calc($gettok($line(@quotes,$v1),2,32) + 1)
    else aline @quotes $gettok(%line,2,32) 1
    inc %chars $len(%line)
    inc %lines
    inc %words $numtok(%line,32)
  }
  .fclose quotes
  window -c @quotes
  msg $chan Quote stats: Chars: %chars Words: %words Size: %size Quotes: %lines
  msg $chan top3 quoters #1 $gettok($line(@quotes,1),1,32) $gettok($line(@quotes,2),1,32) $gettok($line(@quotes,3),1,32)
}


Try that. I haven't tested it but I think it'll work.

#142062 15/02/06 08:02 PM
Joined: Feb 2006
Posts: 164
V
vexed Offline OP
Vogon poet
OP Offline
Vogon poet
V
Joined: Feb 2006
Posts: 164
Quote stats: Chars: 6338 Words: 968 Size: 0B Quotes: 61
top3 quoters #1

i get no error messages appear though.

#142063 15/02/06 10:21 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I made quite a few silly mistakes in that (such as trying to read lines from the window after I'd closed it). That'll teach me to write code in the reply editbox grin

Code:
alias qstats {
  var %chars, %line, %lines, %n, %size = $bytes($file(system\quotes.txt)).suf, %user, %words
  window -hs @quotes
  .fopen quotes system\quotes.txt
  if (!$fopen(quotes)) return
  while (!$fopen(quotes).eof) {
    %line = $fread(quotes)
    %user = $gettok(%line,2,32)
    if ($fline(@quotes,* %user,1)) rline @quotes $v1 $base($calc($gettok($line(@quotes,$v1),1,32) + 1),10,10,8) %user
    else aline @quotes 00000001 $gettok(%line,2,32)
    inc %chars $len(%line)
    inc %lines
    inc %words $numtok(%line,32)
  }
  .fclose quotes
  %n = $line(@quotes,0)
  msg $chan Quote stats: Chars: %chars Words: %words Size: %size Quotes: %lines
  msg $chan top3 quoters #1 $gettok($line(@quotes,%n),2,32) #2 $gettok($line(@quotes,$calc(%n - 1)),2,32) #3 $gettok($line(@quotes,$calc(%n - 2)),2,32)
  window -c @quotes
}


This is tested and it works.

This could break once people reach 10 million or more quotes so you might want to clear the file every 5 years or so.

#142064 16/02/06 01:41 PM
Joined: Feb 2006
Posts: 164
V
vexed Offline OP
Vogon poet
OP Offline
Vogon poet
V
Joined: Feb 2006
Posts: 164
Well it doesn't entirely work, i'm not sure if it's picking out the names from the actual quotes themselves, as i looked through at the people who added the quotes and it doesn't match what it returned, i even added another 50 fake quotes and the top3 never changed.

write system/quotes.txt $ctime $nick $2-

which appears like this

1105977059 n1ck1 <n1ck2> 1st quote pls :tongue:
the blue is the person who added the quote, i wanted it to show the top3 who added the quotes, not who appear in the quothanks.

#142065 16/02/06 02:07 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Really? It works perfectly every time I try it. What version of mIRC are you using?

#142066 16/02/06 02:08 PM
Joined: Feb 2006
Posts: 164
V
vexed Offline OP
Vogon poet
OP Offline
Vogon poet
V
Joined: Feb 2006
Posts: 164
definitely 6.16

The person who is showing #1 only added 2 quotes
The person who is showing #2 has 4 quotes
The person who is showing #3 has 10 quotes

and there are persons who have added between 3 and 7 quotes
so i'm stumped
crazy

Last edited by vexed; 16/02/06 02:16 PM.
#142067 16/02/06 02:33 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
You're right, it wasn't working. I didn't test it enough.

This one seems to be (as well as being a lot faster):

Code:
alias qstats {
  set -u %chars
  set -u %lines
  set -u %words
  window -h @quotes
  filter -fk system\quotes.txt add
  filter -acww @quotes @quotes sort
  msg $chan Quote stats: Chars: %chars Words: %words Size: %size Quotes: %lines
  msg $chan top3 quoters #1 $gettok($line(@quotes,1),2,32) ( $+ $gettok($line(@quotes,1),1,32) $+ ) #2 $gettok($line(@quotes,2),2,32) ( $+ $gettok($line(@quotes,2),1,32) $+ ) #3 $gettok($line(@quotes,3),2,32) ( $+ $gettok($line(@quotes,3),1,32) $+ )
  window -c @quotes
}
alias -l add {
  if ($fline(@quotes,* $gettok($1,2,32),1)) rline @quotes $v1 $calc($gettok($line(@quotes,$v1),1,32) + 1) $gettok($1,2,32)
  else aline @quotes 1 $gettok($1,2,32)
  inc %chars $len($1)
  inc %lines
  inc %words $numtok($1,32)
}
alias -l sort {
  if ($gettok($1,1,32) &gt; $gettok($2,1,32)) return -1
  elseif ($gettok($1,1,32) == $gettok($2,1,32)) return 0
  else return 1
}

#142068 16/02/06 02:40 PM
Joined: Feb 2006
Posts: 164
V
vexed Offline OP
Vogon poet
OP Offline
Vogon poet
V
Joined: Feb 2006
Posts: 164
You're a star! thanks for the time and effort you put in to helping me get that. much appreciated. smile

#142069 16/02/06 02:41 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
You're welcome.
If you have any problems or want anything adding to it (bottom3, for example) feel free to ask smile

#142070 16/02/06 04:06 PM
Joined: Feb 2006
Posts: 164
V
vexed Offline OP
Vogon poet
OP Offline
Vogon poet
V
Joined: Feb 2006
Posts: 164
Incidentally, is it possible to show the percentage the top 3 quoters have used ie, [10] %20 [9] %17 or is it not possible as it's not showing every single quoter?

thanks.

#142071 16/02/06 04:14 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Certainly is. I've used variables in this that don't need to be used to prevent page stretching (and horizontal scrolling in the script editor), you can remove those if you like.

Code:
alias qstats {
  set -u %chars
  set -u %lines
  set -u %words
  window -h @quotes
  filter -fk system\quotes.txt add
  filter -acww @quotes @quotes sort
  msg $chan Quote stats: Chars: %chars Words: %words Size: %size Quotes: %lines
  var %n1 = $gettok($line(@quotes,1),1,32), %1 = #1 $gettok($line(@quotes,1),2,32) [[ $+ %n1 $+ ]] $calc(%n1 / %lines * 100) $+ %
  var %n2 = $gettok($line(@quotes,2),1,32), %2 = #2 $gettok($line(@quotes,2),2,32) [[ $+ %n2 $+ ]] $calc(%n2 / %lines * 100) $+ %
  var %n3 = $gettok($line(@quotes,3),1,32), %3 = #3 $gettok($line(@quotes,3),2,32) [[ $+ %n3 $+ ]] $calc(%n3 / %lines * 100) $+ %
  msg $chan top3 quoters %1 %2 %3
  window -c @quotes
}
alias -l add {
  if ($fline(@quotes,* $gettok($1,2,32),1)) rline @quotes $v1 $calc($gettok($line(@quotes,$v1),1,32) + 1) $gettok($1,2,32)
  else aline @quotes 1 $gettok($1,2,32)
  inc %chars $len($1)
  inc %lines
  inc %words $numtok($1,32)
}
alias -l sort {
  if ($gettok($1,1,32) &gt; $gettok($2,1,32)) return -1
  elseif ($gettok($1,1,32) == $gettok($2,1,32)) return 0
  else return 1
}

#142072 16/02/06 04:35 PM
Joined: Feb 2006
Posts: 164
V
vexed Offline OP
Vogon poet
OP Offline
Vogon poet
V
Joined: Feb 2006
Posts: 164
Excellent!
You people that spend time helping us out deserve more credit.
Thanks very much hixxy! laugh


Link Copied to Clipboard