mIRC Home    About    Download    Register    News    Help

Print Thread
#9950 06/02/03 04:59 PM
Joined: Feb 2003
Posts: 14
F
Pikka bird
OP Offline
Pikka bird
F
Joined: Feb 2003
Posts: 14
Hi im working on a stats generator script to generat stats in a .htm file.... So far so good but I have a problem... I have set up so the channel im logging adds a file called stats.$chan.user.ini ... it contains the following

[Nicks]
Nick1=2
Nick2=12
Nick3=5
Nick4=1
Nick5=22

where nick is the name of a person who has typet something in the channel and the number represents how many times he or she has type a msg... I want to be able to set them as a value for example
set %stats.top15.user1 user <-- the person who has the highest value (eg the most written lines)
set %stats.top15.user2 user <-- second place and so on...
I would also like to set %stats.top15.lines.user1 to the number of line the person wrote... The problem is that I cant get the nick from the ini file because I dont know who it is so I cant use the $readini and if-the-else...

Any suggestions how I can fix this ?

#9951 06/02/03 05:20 PM
Joined: Dec 2002
Posts: 143
A
Vogon poet
Offline
Vogon poet
A
Joined: Dec 2002
Posts: 143
From the help file:

Code:
[b]$ini(file,topic/N,item/N)[/b]
Returns the name/Nth position of the specified topic/item in an ini/text file.

$ini(mirc.ini,0)  returns total number of topics in mirc.ini
$ini(mirc.ini,1)  returns name of 1st topic in mirc.ini
$ini(mirc.ini,help) returns Nth position of topic help if it exists, or returns 0 if it doesn't exist

The item/N parameter is optional. If you specify specify N = 0, it returns the total number of topics/items.

So, if you use (for eg):

$ini(stats.#Aubs.user.ini,Nicks,1)

that would return the first nick,

$readini(stats.#Aubs.user.ini,Nicks,$ini(stats.#Aubs.user.ini,Nicks,1)) would return the number.

Use a while loop to get each nick/value to variables/hash table(for big channels) and and see which is the greatest that way...

If you catch the drift?!

Hometime, gotta go!!


Aubs.
cool

#9952 06/02/03 06:07 PM
Joined: Feb 2003
Posts: 14
F
Pikka bird
OP Offline
Pikka bird
F
Joined: Feb 2003
Posts: 14
Yes i think I see what you mean but how can i set mirc up to the check which ones has the highest value?

#9953 06/02/03 11:13 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
The simplest way is to create a sorted hidden window, add all the lines from [Nicks] in the form value item; then just work backwards from the end of $line(@window,%i) to get the highest down to the lowest (or as far as you wish to go.
Code:

  [color:#006600]
  ;  Create the hidden sorted window.
  ;[/color]
  window -sh @Sorted
  [color:#006600]
  ;  Create a variable to hold the filename so you don't have to keep resolving it.
  ;[/color]
  var %ini = $+(stats.,$chan,.user.ini)
  [color:#006600]
  ;  Find out how many values are in the [Nicks] section so we'll know how many
  ;  0's to left-pad with to ensure proper sorting order.
  ;[/color]
  var %0Pad = $str(0, $len($ini(%ini, Nicks, 0)))
  [color:#006600]
  ;  Create the loop index.
  ;[/color]
  var %i = 1
  [color:#006600]
  ;  Work through each of the nicks in the [Nicks] section.
  ;[/color]
  while ($ini(%ini, Nicks, %i)) {
  [color:#006600]
    ;  Save the line in a variable so you can switch the order without having to re-read the file.
    ;[/color]
    var %line = $readini(%ini, Nicks, $ifmatch)
  [color:#006600]
    ;  Add each nick=lines backwards, in the form: lines nick. We will also need to 0-pad the
    ;  number in order to get them to sort correctly.
    ;[/color]
    aline @Sorted $right($+(%0Pad,$gettok(%line, 2, 32)), $len(%0Pad)) $gettok(%line, 1, 32)
  [color:#006600]
    ;  Go on to the next nick, if there is one.
    ;[/color]
    inc %i
  }
  [color:#006600]
  ;  At this point, the @Sorted window contains all the lines nicks in sorted order.
  ;[/color]
  [color:#006600]
  ;  Unset the old top15 variables, if any.
  ;[/color]
  unset %stats.top15.user*
  [color:#006600]
  ;  Create the variable to be used to increment the .userN value.
  ;[/color]
  var %j = 1
  [color:#006600]
  ;  Set %i equal to the last line number of the @Sorted window, to work backwards through it.
  ;[/color]
  %i = $line(@Sorted, 0)
  [color:#006600]
  ;  Loop through @Sorted backwards.
  ;[/color]
  while ($line(@Sorted, %i)) {
  [color:#006600]
    ;  Set the %stats.top15.userN equal to the nick and the un-0padded number.
    ;  Remove the 0 padding by adding 0 to the number.
    ;[/color]
    set $+(%,stats.top15.user,%j) $gettok($line(@Sorted,%i), 2, 32) $calc($gettok($line(@Sorted,%i), 1, 32) + 0)
  [color:#006600]
    ;  Increment the userN number
    ;[/color]
    inc %j
  [color:#006600]
    ;  Check to see if we've exceeded the 15 we want; if so, drop out of the loop.
    ;[/color]
    if (%j &gt; 15) break
  [color:#006600]
    ;  Go to the previous line in @Sorted, if any exists.
    ;[/color]
    dec %i
  }
  [color:#006600]
  ;  At this point, you will have created all of your %stats.top15.userN variables with their values = nick lines.
  ;[/color]



DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#9954 07/02/03 08:09 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Why are you using the total number of items in [Nicks] section to calculate the zeropad? The calculation should be based on the highest number of lines msg'ed by a nick, so, ideally, you should first find this number and set the zeropad to its length. This has nothing to do with the number of nicks in [Nicks]. Fex, in this list:

[Nicks]
one=56
two=223
three=8
four=92
five=2

zeropad should be 3 (because the highest number is 223), not 5 (the number of items). Anyway, this would be the ideal solution; in practice, selecting a zeropad large enough (like 7) would be ok (it's very unlikely that somebody would write more than 10 million lines in a channel). Also, instead of setting %0Pad to a string of 0's and use $right($+(%0Pad,$gettok(%line, 2, 32)), $len(%0Pad)) you could just use $base($gettok(%line,2,32),10,10,%0Pad), where %0Pad would be a number (not a string of 0's). Not very important, but it's cleaner, smaller and (maybe insignificantly) faster.

Zeropadding is a smart way to make a numeric sort when the sorting routine is alphabetical. However, there's a faster way to make this sorted list, if you take advantage of /filter's power. Not only /filter can do a numeric sort, which eliminates the need for zeropad, but it can also do it on a specified column, with the -t switch. This makes it ideal for the case, as you can use /loadbuf -tNicks to load the .ini section directly to the hidden window and then use /filter to sort it. Here's how:
Code:
[color:green]; syntax: /maketop15 &lt;channel&gt;
; e.g. /maketop15 #mirc[/color]
alias maketop15 {
  window -h @@
  loadbuf -tNicks @@ $+(stats.,$$1,.user.ini)
  [color:green]; 61 is the ASCII value of "=", which is considered the column separator here.[/color]
  filter -wwcute 2 61 @@ @@
  unset %stats.top15.*
  var %i = 1
  while %i &lt; 16 &amp;&amp; $line(@@,%i) {
    tokenize 61 $ifmatch
    set %stats.top15.user $+ %i $1
    set %stats.top15.lines.user $+ %i $2
    inc %i
  }
  close -@ @@
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#9955 07/02/03 02:37 PM
Joined: Feb 2003
Posts: 14
F
Pikka bird
OP Offline
Pikka bird
F
Joined: Feb 2003
Posts: 14
smile smile smile smile smile smile smile smile smile smile smile smile smile smile smile smile

Thanks a lot guys!!! Both the scripts worked !!!

smile smile smile smile smile smile smile smile smile smile smile smile smile smile smile smile

#9956 07/02/03 03:20 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Oops. You're right, I definitely zero-padded on the wrong data. I definitely need to spend more time with /filter and /loadbuf since I don't seem to be able to remember their switches very well, much less remember to use them.

Nice algorithm, too, qwerty. laugh


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#9957 09/02/03 11:47 AM
Joined: Feb 2003
Posts: 14
F
Pikka bird
OP Offline
Pikka bird
F
Joined: Feb 2003
Posts: 14
Okey I got everything to work !!! until i did the last part which was when I deactivated it, it would remove all stats files... I was so stupid... I didnt realise that it would delete my stats.mrc which contained the stats word :P... So now i have recreated the whole thing again.. But I am having problems with my on QUIT and on KICK...

My on PART works perfect but on QUIT which adds the information to the same ini file isnt working... My on KICK with $knick works but not when I am trying to do a kickers ($nick) the nick of the person who kicked the most user... I think is a simple misstake but I cant seem to find it.. So I will just paste my code here (the wrong part) and you will help me find the problem laugh


P.S. The %stas.channel1-4 is the name of the channel it is logging...



on *:QUIT: {
if ($chan == %stats.channel1) { set %stats.temp stats. $+ $chan }
if ($chan == %stats.channel1) { set %stats.temp %stats.temp $+ .part.ini }
if ($chan == %stats.channel1) && ($readini(%stats.temp, Nicks, $nick) != $null) { writeini %stats.temp Nicks $nick $calc($readini(%stats.temp, Nicks, $nick) + 1) }
else if ($chan == %stats.channel1) { writeini %stats.temp Nicks $nick 1 }
if ($chan == %stats.channel2) { set %stats.temp stats. $+ $chan }
if ($chan == %stats.channel2) { set %stats.temp %stats.temp $+ .part.ini }
if ($chan == %stats.channel2) && ($readini(%stats.temp, Nicks, $nick) != $null) { writeini %stats.temp Nicks $nick $calc($readini(%stats.temp, Nicks, $nick) + 1) }
else if ($chan == %stats.channel2) { writeini %stats.temp Nicks $nick 1 }
if ($chan == %stats.channel3) { set %stats.temp stats. $+ $chan }
if ($chan == %stats.channel3) { set %stats.temp %stats.temp $+ .part.ini }
if ($chan == %stats.channel3) && ($readini(%stats.temp, Nicks, $nick) != $null) { writeini %stats.temp Nicks $nick $calc($readini(%stats.temp, Nicks, $nick) + 1) }
else if ($chan == %stats.channel3) { writeini %stats.temp Nicks $nick 1 }
if ($chan == %stats.channel4) { set %stats.temp stats. $+ $chan }
if ($chan == %stats.channel4) { set %stats.temp %stats.temp $+ .part.ini }
if ($chan == %stats.channel4) && ($readini(%stats.temp, Nicks, $nick) != $null) { writeini %stats.temp Nicks $nick $calc($readini(%stats.temp, Nicks, $nick) + 1) }
else if ($chan == %stats.channel4) { writeini %stats.temp Nicks $nick 1 }
}

This on QUIT will not work...





on *:KICK:#: {
if ($chan == %stats.channel1) { set %stats.temp stats. $+ $chan }
if ($chan == %stats.channel1) { set %stats.temp %stats.temp $+ .kickers.ini }
if ($chan == %stats.channel1) && ($readini(%stats.temp, Nicks, $nick) != $null) { writeini %stats.temp Nicks $nick $calc($readini(%stats.temp, Nicks, $nick) + 1) }
else if ($chan == %stats.channel1) { writeini %stats.temp Nicks $nick 1 }
if ($chan == %stats.channel2) { set %stats.temp stats. $+ $chan }
if ($chan == %stats.channel2) { set %stats.temp %stats.temp $+ .kickers.ini }
if ($chan == %stats.channel2) && ($readini(%stats.temp, Nicks, $nick) != $null) { writeini %stats.temp Nicks $nick $calc($readini(%stats.temp, Nicks, $nick) + 1) }
else if ($chan == %stats.channel2) { writeini %stats.temp Nicks $nick 1 }
if ($chan == %stats.channel3) { set %stats.temp stats. $+ $chan }
if ($chan == %stats.channel3) { set %stats.temp %stats.temp $+ .kickers.ini }
if ($chan == %stats.channel3) && ($readini(%stats.temp, Nicks, $nick) != $null) { writeini %stats.temp Nicks $nick $calc($readini(%stats.temp, Nicks, $nick) + 1) }
else if ($chan == %stats.channel3) { writeini %stats.temp Nicks $nick 1 }
if ($chan == %stats.channel4) { set %stats.temp stats. $+ $chan }
if ($chan == %stats.channel4) { set %stats.temp %stats.temp $+ .kickers.ini }
if ($chan == %stats.channel4) && ($readini(%stats.temp, Nicks, $nick) != $null) { writeini %stats.temp Nicks $nick $calc($readini(%stats.temp, Nicks, $nick) + 1) }
else if ($chan == %stats.channel4) { writeini %stats.temp Nicks $nick 1 }
}

This on kick (which saves who kicks most people) isnt working... I have a copy of this one but replaced set %stats.temp %stats.temp $+ .kickers.ini with set %stats.temp %stats.temp $+ .kick.ini and changed $nick to $knick that one works perfect...


Can you see whats wrong with it ?!


Link Copied to Clipboard