<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/20326" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2017-04-18T06:14:45-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/20326</id>

		<entry>
		<author><name><![CDATA[juanamores]]></name></author>
		<updated>2017-04-18T06:14:45-04:00</updated>

		<published>2017-04-18T06:14:45-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106142#p106142</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106142#p106142"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106142#p106142"><![CDATA[
You're right, I've changed it back to -integer and it works fine. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br>I had changed it to -real because earlier it gave me an error of the type:<br>Tcl error: expected floating-point number but got "5.00 15.00 11.00 14.00 2.00".<br><br>I understood that a floating number was expected and got a list of floating numbers.<br><br>Now I changed it again as you advise me and it works ..<br><br>It's just that I made so many changes and tests that I forgot about the mistakes it gave me. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_lol.gif" width="15" height="15" alt=":lol:" title="Laughing"><br><br>Thank you so much caesar <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12499">juanamores</a> — Tue Apr 18, 2017 6:14 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2017-04-18T00:49:13-04:00</updated>

		<published>2017-04-18T00:49:13-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106139#p106139</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106139#p106139"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106139#p106139"><![CDATA[
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.<br><br>Anyway, glad you sorted it out. De nada. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Tue Apr 18, 2017 12:49 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[juanamores]]></name></author>
		<updated>2017-04-17T16:17:19-04:00</updated>

		<published>2017-04-17T16:17:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106137#p106137</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106137#p106137"/>
		<title type="html"><![CDATA[[Solved!]]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106137#p106137"><![CDATA[
Fixed! This is what I wanted. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br>Thank you so much to <strong class="text-strong">caesar</strong> and <strong class="text-strong">willyw</strong>.<div class="codebox"><p>Code: </p><pre><code>proc averages {nick uhost hand chan text} {set fp [open "ranking" "r"]set data [read -nonewline $fp]close $fpforeach line [split $data "\n"] {if {[scan $line {%s%d} name rank] != 2} continuelappend 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 rankputlog "$name $rank"}}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12499">juanamores</a> — Mon Apr 17, 2017 4:17 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[juanamores]]></name></author>
		<updated>2017-04-17T14:20:09-04:00</updated>

		<published>2017-04-17T14:20:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106135#p106135</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106135#p106135"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106135#p106135"><![CDATA[
caesar is almost perfect.<br>There is only one small detail that I can not solve.<br>It is about applying the rounding rule with the "round" function.<br>If you look at the values of Pedro<br>9 + 10 + 4 = 23<br>23/3 = 7.66<br>The final result of Pedro should be 8, not 7.<br>It can be fixed?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12499">juanamores</a> — Mon Apr 17, 2017 2:20 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2017-04-17T13:56:26-04:00</updated>

		<published>2017-04-17T13:56:26-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106134#p106134</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106134#p106134"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106134#p106134"><![CDATA[
Yeah, had a feeling that will fail miserably. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_rolleyes.gif" width="15" height="15" alt=":roll:" title="Rolling Eyes"> <br><br>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).<div class="codebox"><p>Code: </p><pre><code>bind pub - !avgs averagesproc averages {nick uhost hand chan text} {set fp [open "ranking" "r"]set data [read -nonewline $fp]close $fpforeach line [split $data "\n"] {if {[scan $line {%s%d} name rank] != 2} continuelappend 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 rankputs "$name $rank"}}</code></pre></div>Result:<blockquote class="uncited"><div>Maria 12<br>Jose 10<br>Ana 9<br>Pedro 7<br>Ben 3<br>Luis 3</div></blockquote><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon Apr 17, 2017 1:56 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[juanamores]]></name></author>
		<updated>2017-04-17T13:42:58-04:00</updated>

		<published>2017-04-17T13:42:58-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106133#p106133</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106133#p106133"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106133#p106133"><![CDATA[
<span style="text-decoration:underline">Error</span>: Tcl error [averages]: element 1 missing from sublist "10"<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12499">juanamores</a> — Mon Apr 17, 2017 1:42 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2017-04-17T13:41:41-04:00</updated>

		<published>2017-04-17T13:41:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106132#p106132</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106132#p106132"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106132#p106132"><![CDATA[
As expected. The <em class="text-italics">-stride</em> option has been added in 8.6, hence the error. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>Try with the change i said above.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon Apr 17, 2017 1:41 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[juanamores]]></name></author>
		<updated>2017-04-17T13:39:52-04:00</updated>

		<published>2017-04-17T13:39:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106131#p106131</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106131#p106131"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106131#p106131"><![CDATA[
<blockquote class="uncited"><div>running eggdrop v1.6.21<br>Tcl version: 8.5.13 (header version 8.5.13)</div></blockquote><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12499">juanamores</a> — Mon Apr 17, 2017 1:39 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2017-04-17T13:35:48-04:00</updated>

		<published>2017-04-17T13:35:48-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106130#p106130</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106130#p106130"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106130#p106130"><![CDATA[
<blockquote class="uncited"><div><strong class="text-strong">caesar</strong> your code gives an error:<blockquote class="uncited"><div>Tcl error [averages]: bad option "-stride": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -indices, -integer, -nocase, -real, or -unique</div></blockquote></div></blockquote>do:<br>.status <br>in the partyline, and note the version of TCL your bot is using,  and post it here for caesar .<br><br>edit:<br>We posted at the exact same time! <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Mon Apr 17, 2017 1:35 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2017-04-17T13:35:40-04:00</updated>

		<published>2017-04-17T13:35:40-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106129#p106129</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106129#p106129"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106129#p106129"><![CDATA[
You seem to have an old TCL library, cos <em class="text-italics">stride</em> is in version 8.6 and upwards. Since I got 8.6 I can't test if replacing:<div class="codebox"><p>Code: </p><pre><code>set results [lsort -stride 2 -index 1 -integer -decreasing [lsort -stride 2 -index 0 [array get result]]] </code></pre></div>with:<div class="codebox"><p>Code: </p><pre><code>set results [lsort -index 1 -integer -decreasing [lsort -index 0 [array get result]]] </code></pre></div>will work so let me know to find another solution.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon Apr 17, 2017 1:35 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[juanamores]]></name></author>
		<updated>2017-04-17T13:31:12-04:00</updated>

		<published>2017-04-17T13:31:12-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106128#p106128</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106128#p106128"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106128#p106128"><![CDATA[
<strong class="text-strong">caesar</strong> your code gives an error:<blockquote class="uncited"><div>Tcl error [averages]: bad option "-stride": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -indices, -integer, -nocase, -real, or -unique</div></blockquote><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12499">juanamores</a> — Mon Apr 17, 2017 1:31 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2017-04-17T13:33:15-04:00</updated>

		<published>2017-04-17T12:42:56-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106127#p106127</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106127#p106127"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106127#p106127"><![CDATA[
Here's a clean and a lot shorter code:<div class="codebox"><p>Code: </p><pre><code>bind pub - !avgs averagesproc averages {nick uhost hand chan text} {set fp [open "ranking" "r"]set data [read -nonewline $fp]close $fpforeach line [split $data "\n"] {if {[scan $line {%s%d} name rank] != 2} continuelappend ranking($name) $rank}foreach {name values} [array get ranking] {set average [expr ([join $values +]) / [llength $values]]lappend result($name) $average}set results [lsort -stride 2 -index 1 -integer -decreasing [lsort -stride 2 -index 0 [array get result]]]foreach {name score} $results {putlog "$name $score"}}</code></pre></div>The result is the same:<blockquote class="uncited"><div>Maria 12<br>Jose 10<br>Ana 9<br>Pedro 7<br>Luis 3</div></blockquote>The data I used is from what you posted at your second comment. Isn't the result what you are looking for?<br><br>Edit: Shorted the code removing unnecessarily loops. Don't know why I didn't think about this in the first place. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_rolleyes.gif" width="15" height="15" alt=":roll:" title="Rolling Eyes"><br><br>Second edit: Since your initial list doesn't have two names with an identical result I didn't see:<blockquote class="uncited"><div>Maria 12<br>Jose 10<br>Ana 9<br>Pedro 7<br>Luis 3<br>Ben 3</div></blockquote>Notice that the list is sorted only by average (descending) and member names aren't sorted so to get them sorted as well changed the code to first sort by name as a secondary key and then sort by average (descending) as a primary key.<br>So we:<div class="codebox"><p>Code: </p><pre><code># build a flat listset results [array get result]# sort by name as a secondary keyset results [lsort -stride 2 -index 0 $result]# then sort by average (descending) as a primary key.set results [lsort -stride 2 -index 1 -integer -decreasing $results]</code></pre></div>and all 3 lines combined:<div class="codebox"><p>Code: </p><pre><code>set results [lsort -stride 2 -index 1 -integer -decreasing [lsort -stride 2 -index 0 [array get result]]]</code></pre></div>Result:<blockquote class="uncited"><div>Maria 12<br>Jose 10<br>Ana 9<br>Pedro 7<br>Ben 3<br>Luis 3</div></blockquote>Is this <strong class="text-strong">final</strong> result what you where looking for? <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon Apr 17, 2017 12:42 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[juanamores]]></name></author>
		<updated>2017-04-17T12:33:04-04:00</updated>

		<published>2017-04-17T12:33:04-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106126#p106126</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106126#p106126"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106126#p106126"><![CDATA[
<blockquote class="uncited"><div>I showed you one way to sort it, above.   You can adapt from that.</div></blockquote>In your solution, you get the result by sorting a list, but with the caesar code I have to sort an array.<br>I haven't idea how to integrate both ideas...  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_redface.gif" width="15" height="15" alt=":oops:" title="Embarassed"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12499">juanamores</a> — Mon Apr 17, 2017 12:33 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2017-04-17T12:15:41-04:00</updated>

		<published>2017-04-17T12:15:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106125#p106125</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106125#p106125"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106125#p106125"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>bind pub - !avgs averagesproc averages {nick uhost hand chan text} {set fp [open "ranking" "r"]set data [read -nonewline $fp]close $fpforeach line [split $data "\n"] {if {[scan $line {%s%d} name rank] != 2} continuelappend ranking($name) $rank}foreach name [array names ranking] {set total 0set count [llength $ranking($name)] foreach no $ranking($name) {incr total $no}set average [expr round ([expr $total / $count])]lappend result($name) $average}set data [lsort -stride 2 -index 1 -integer -decreasing [array get result]]foreach {name score} $data {putlog "$name $score"}}</code></pre></div>Should do what you wanted.<blockquote class="uncited"><div>Maria 12<br>Jose 10<br>Ana 9<br>Pedro 8<br>Luis 3</div></blockquote>If you want to get an rounded result like:<blockquote class="uncited"><div>Maria 12.20<br>Jose 10.00<br>Ana 9.40<br>Pedro 7.67<br>Luis 3.00</div></blockquote>then replace:<div class="codebox"><p>Code: </p><pre><code>set average [expr round ([expr $total / $count])]and set data [lsort -stride 2 -index 1 -integer -decreasing $data]</code></pre></div>with:<div class="codebox"><p>Code: </p><pre><code>set average [format "%.2f" [expr $total / $count]]andset data [lsort -stride 2 -index 1 -real -decreasing $data]</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon Apr 17, 2017 12:15 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2017-04-17T11:49:34-04:00</updated>

		<published>2017-04-17T11:49:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106124#p106124</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106124#p106124"/>
		<title type="html"><![CDATA[Sort file data]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106124#p106124"><![CDATA[
<blockquote class="uncited"><div>Now I need to sort the results, from highest to lowest. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br><strong class="text-strong">willyw</strong>, I appreciate your contributions, it is not a game, I did not copy more code because I only need to sort the values ​​of a file.<br><strong class="text-strong">caesar</strong> understood my idea, now I just need to modify the caesar's code to get the ranking ordered from highest to lowest.</div></blockquote>Ok.<br>I showed you one way to sort it, above.   You can adapt from that.<br><br>Good luck with it.    <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Mon Apr 17, 2017 11:49 am</p><hr />
]]></content>
	</entry>
	</feed>
