egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sort file data
Goto page Previous  1, 2
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3401
Location: Area 51

PostPosted: Mon Apr 17, 2017 1:41 pm    Post subject: Reply with quote

As expected. The -stride option has been added in 8.6, hence the error. Smile

Try with the change i said above.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Mon Apr 17, 2017 1:42 pm    Post subject: Reply with quote

Error: Tcl error [averages]: element 1 missing from sublist "10"
_________________
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks Smile
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3401
Location: Area 51

PostPosted: Mon Apr 17, 2017 1:56 pm    Post subject: Reply with quote

Yeah, had a feeling that will fail miserably. Rolling Eyes

Here is a TCL 8.4/8.5 version that should be compatible with newer versions of TCL, if you decide to install a new one (a good idea security wise by the way).
Code:

bind pub - !avgs averages

proc averages {nick uhost hand chan text} {
   set fp [open "ranking" "r"]
   set data [read -nonewline $fp]
   close $fp
   foreach line [split $data "\n"] {
      if {[scan $line {%s%d} name rank] != 2} continue
      lappend ranking($name) $rank
   }
   foreach {name values} [array get ranking] {
      set average [expr ([join $values +]) / [llength $values]]
      lappend result [list $name $average]
   }
   set results [lsort -index 1 -integer -decreasing [lsort -index 0 $result]]
   foreach pair $results {
      scan $pair {%s%d} name rank
      puts "$name $rank"
   }
}

Result:
Quote:

Maria 12
Jose 10
Ana 9
Pedro 7
Ben 3
Luis 3

_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Mon Apr 17, 2017 2:20 pm    Post subject: Reply with quote

caesar is almost perfect.
There is only one small detail that I can not solve.
It is about applying the rounding rule with the "round" function.
If you look at the values of Pedro
9 + 10 + 4 = 23
23/3 = 7.66
The final result of Pedro should be 8, not 7.
It can be fixed?
_________________
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks Smile
Back to top
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Mon Apr 17, 2017 4:17 pm    Post subject: [Solved!] Reply with quote

Fixed! This is what I wanted. Smile Smile Smile Smile
Thank you so much to caesar and willyw.
Code:

proc averages {nick uhost hand chan text} {
   set fp [open "ranking" "r"]
   set data [read -nonewline $fp]
   close $fp
   foreach line [split $data "\n"] {
      if {[scan $line {%s%d} name rank] != 2} continue
      lappend ranking($name) [format "%.2f" $rank]
   }
   foreach {name values} [array get ranking] {
      set average [expr ([join $values +]) / [llength $values]]
      lappend result [list $name [expr round ([format "%.2f" $average])]]
      #putlog "debugging decimal: $average"
   }
   set results [lsort -index 1 -real -decreasing [lsort -index 0 $result]]
   foreach pair $results {
      scan $pair {%s%d} name rank
      putlog "$name $rank"
   }
}

_________________
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks Smile
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3401
Location: Area 51

PostPosted: Tue Apr 18, 2017 12:49 am    Post subject: Reply with quote

Since the rank you read from the file is an integer you don't really need to format it to real cos when doing the average it won't matter if it was real or not.

Anyway, glad you sorted it out. De nada. Smile
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Tue Apr 18, 2017 6:14 am    Post subject: Reply with quote

You're right, I've changed it back to -integer and it works fine. Smile
I had changed it to -real because earlier it gave me an error of the type:
Tcl error: expected floating-point number but got "5.00 15.00 11.00 14.00 2.00".

I understood that a floating number was expected and got a list of floating numbers.

Now I changed it again as you advise me and it works ..

It's just that I made so many changes and tests that I forgot about the mistakes it gave me. Laughing

Thank you so much caesar Very Happy
_________________
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber