|
Belhifet
|
Belhifet
|
So I got these points all loaded up in some hash tables..
looks like this
name1=number1 name2=number2 name3=number3
I'd like to be able to put together a !top 10..I'm just not sure I understand how to efficiently iterate over this and how you put it in order?
So I guess the questions are, how would I go about getting the top X values, and how would I got about check a particular value's rank at a given time(example a player is rewarded points for a minigame and they move from rank 299 to rank 250). Can I just iterate over this with a while statement..is that the right way to do it?
|
|
|
|
Belhifet
|
Belhifet
|
https://forums.mirc.com/ubbthreads.php/topics/242007/Re_Find_Highest_Value_in_Hash_I found this via google..It might answer my question. I'll give it a go. On second thought, maybe I don't understand whats being said in that thread. 
var %i = 1, %n = $hget(table,0).data, %high.item, %high.data
while (%i <= %n) {
if ($hget(table,%i).data > %high.item) {
%high.item = $hget(table,%i).item
%high.data = $v1
}
inc %i
}
Ok this is what loki posted..sooo I feel like its the right way to do things. I'm just gotta copy it here so its here. Ok So I've been looking at this and I get what it does..it goes through the hash table and constantly compares the current value %i with the last known high and replaces it when its higher. Ugh this is frustrating, it seems like keeping numbers in order would be a thing a computer should do so naturally and sadly I can't figure out a proper way to do this. Do I need to basically do what is above but just loop through it ten times to get a top 10 list and what if I want 1,000 things sorted? Oh god, its this filter command. This came up the other day and when I saw the helpfile for it I scurried away.
// Sort table in descending order into a temp file (this can also be done in a custom window)
hsave -n table file.tmp
filter -ffcuten 2 32 file.tmp file.tmp
// Get the Nth top value
echo -a $hget(table,$gettok($read(file.tmp,N),1,32)).item
Ok, I guess I'll look into this. /filter [-asgdfwxnpriocteubglL] [n-n2] [c s] <INFILE dialog |> <OUTFILE dialog |> [alias] <MATCHTEXT> Is this real life? Ok I was able to play with this until it worked for me. I do not understand it at all though. 
Last edited by Belhifet; 06/12/14 04:42 PM.
|
|
|
|
Belhifet
|
Belhifet
|
Ok..so I'm having a problem with what I made to calculate the rank of a nick based on their point total.
alias moresatanicfiltercommand {
unset %rank. $+ $1 $+ $2
if ($($+(%,channelisonline.,$1),2) == False) {
hmake $($+($1,.points),2)
hload -i $($+($1,.points),2) $($+(points.,$1,.ini),2)
hsave -i $($+($1,.points),2) file.tmp
var %x $read(file.tmp, nw, $2 $+ *)
var %n $calc($readn - 1)
hsave -n $($+($1,.points),2) file2.tmp
filter -ffcuten 2 32 file2.tmp file3.tmp
var %x $read(file3.tmp, nw, %n *)
set -u1000 %rank. $+ $1 $+ $2 $readn
hfree $($+($1,.points),2)
}
elseif ($($+(%,channelisonline.,$1),2) == True) {
hsave -i $($+($1,.points),2) file.tmp
var %x $read(file.tmp, nw, $2 $+ *)
var %n $calc($readn - 1)
hsave -n $($+($1,.points),2) file2.tmp
filter -ffcuten 2 32 file2.tmp file3.tmp
var %x $read(file3.tmp, nw,%n *)
set -u1000 %rank. $+ $1 $+ $2 $readn
}
}
The first part works properly, when the twitch channel is offline. The hash table is already made when the channel is online so I figured I'd use that. But it doesn't function in the same way and I'm afraid that I only vaguely understand why the first section worked so troubleshooting the second section is difficult. By not working I mean it doesn't come up with an accurate rank based on the total points of the user. I was hoping someone could explain why they are in a different order in the second version and maybe I could figure out how to fix it from there? Also I'm doing var %x $read(file.tmp, nw, $2 $+ *) this just so I can use the $readn on the next line, is there a different/better way to use $readn?
|
|
|
|
Belhifet
|
Belhifet
|
Ok..so when I said the first part works properly, I was unaware that it (of course) doesn't *really* work properly. For the most part when $($+(%,channelisonline.,$1),2) == False this section works. But it doesn't work right away after changing from True to False. Which probably just means I have some logical errors in the script and it just happens to work when the ini file naturalizes itself after being saved from a hash table. I'm still trying to figure this out but every time I come up with an explanation it doesn't explain why both why the false works when offline for a bit, and the true doesn't.
I'm pretty sure I have a reworked version/idea (I haven't got in functioning code wise) that will work but I wish I knew why the first attempt failed.
|
|
|
|
Belhifet
|
Belhifet
|
so after playing with this for way too long I deleted it and started again using Loki's version as a base line..
alias moresatanicfiltercommand {
unset %rank. $+ $1 $+ $2
if ($($+(%,channelisonline.,$1),2) == False) {
hmake $($+($1,.points),2)
hload -i $($+($1,.points),2) $($+(points.,$1,.ini),2)
findrank $1 $2
hfree $($+($1,.points),2)
}
elseif ($($+(%,channelisonline.,$1),2) == True) {
findrank $1 $2
}
}
alias findrank {
var %i = 1, %n = $hget($($+($1,.points),2),0).data, %higherranks = 1,%username $hget($($+($1,.points),2), $2)
while (%i <= %n) {
if ($hget($($+($1,.points),2),%i).data > %username) {
inc %higherranks
}
inc %i
}
set -u1000 %rank. $+ $1 $+ $2 %higherranks
}
This work much better, ty.
|
|
|
|
|