Version 53 of Drake Intelligent Life Equation Slot Calculator Example

Updated 2011-05-25 17:11:40 by gold

Drake Intelligent Life Equation Slot Calculator Example

This page is under development. Comments are welcome, but please load any comments in the comments section at the middle of the page. Thanks,gold


gold Here is an eTCL script on to estimate drake equation. For the push buttons, the reccomended procedure is push testcase and fill frame, change entries , push solve, and then push report. Report allows copy and paste from console, but takes away from computer "efficiency".


In planning any software, there is a need to develop testcases.

 Testcase 1.
quantitynumberunits
star formation 10.rate per year
stars with planets .5stars
potential life 2.
actual life 1.
fraction develop civilization .01 none
fraction technology .01none
years available 10000.years
number of civilizations equal 10.* .5 * 2. * 1. * .01 * .01 * 10000.
answer: 10. civilizations

Screenshots Section

http://farm5.static.flickr.com/4128/4951464083_2074292b73.jpg


Comments Section

Please place any comments here, Thanks.

What is your purpose in binding the motion event on your main window to execute the wm title command. I.e., this line:

  bind . <Motion> {wm title . "Drake Equation Calculator "}

The result of that binding is that every time you move the mouse, the "wm title" subcommand is called repeatedly. To set the window title, you just need to call "wm title . title" once, not on every event update upon mouse pointer motion.

Also, why do you define the procs pi, interlinear, pol, errorx, and height5 when you do not appear to use them anywhere in the code presented? In examples, having extra bits defined that are not used adds noise that a reader has to expend effort upon only to later learn that he/she could have ignored that part. Keeping the example focused upon only that which is needed for just the example, and nothing more, makes for a more informative, and educational, example.


gold changes: pulled procs pi,interlinear,pol,errorx,height5. and changed to wm . "title". Former idea was that user could use interpolate routine in the punched console. Conjecture below was that in a namespace version, subroutines would be available, but not all called from the namespace.


In that case, you might consider placing them into a namespace (i.e. ::gold::) and placing that common code on your main "gold" page. Then each other example page can refer to that one common location for the common items. Of course you would want to modify the examples to both load the ::gold definitions file from the gold page, and to make use of the procs therein instead of defining each individually.


References:


Appendix TCL programs and scripts

* Pretty Print Version

        # Pretty print version from autoindent
        # and ased editor
        # program of drake equation
        # written on Windowws XP on eTCL
        # working under TCL version 8.5.6 and eTCL 1.0.1
        # gold on TCL WIKI , 24aug2010
        frame .frame -relief flat -bg aquamarine4
        pack .frame -side top -fill y -anchor center
        set names {{} {star formation /yr:} {fraction w/ planets:} {poss life :} {actual life:} {civiliation develop:}
{detectable signs:} {length years:} { civilizations:} }
            foreach i {1 2 3 4 5 6 7 8} {
             label .frame.label$i -text [lindex $names $i] -anchor e
             entry .frame.entry$i -width 35 -textvariable side$i
             grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1
            }
        proc about {} {
            set msg "Calculator for Drake Equation.
            from TCL WIKI,
            written on eTCL "
            tk_messageBox -title "About" -message $msg
            }
        proc intelligent5 { xx1   } {
            global side1 side2 side3
            global side4 side5 side6 side7 side8
            set side8  [ expr {  1*$side1*$side2*$side3*$side4*$side5*$side6*$side7 } ]
            return $side8
        }
        proc calculate {     } {
            global colorwarning
            global colorback
            global answer2   answer3
            global side1 side2 side3 side4 side5 side6 side7 side8
            set answer2 5
            set answer2  [ intelligent5  $side8     ]
            set side8 $answer2
        }
        proc fillup {aa bb cc dd ee ff gg hh} {
            .frame.entry1 insert 0 "$aa"
            .frame.entry2 insert 0 "$bb"
            .frame.entry3 insert 0 "$cc"
            .frame.entry4 insert 0 "$dd"
            .frame.entry5 insert 0 "$ee"
            .frame.entry6 insert 0 "$ff "
            .frame.entry7 insert 0 "$gg "
            .frame.entry8 insert 0 "$hh "
        }
        proc clearx {} {
            foreach i {1 2 3 4 5 6 7 8} {
                .frame.entry$i delete 0 end
            }
        }
        proc reportx {} {
            global side1 side2 side3 side4 side5 side6 side7 side8
            console show;
            puts "
            puts " $side1  star formation /yr:  "
            puts " $side2  fraction w/ planets:  "
            puts " $side3  poss life :  "
            puts " $side4  actual life:  "
            puts " $side5  civiliation develop:  "
            puts " $side6  detectable signs:  "
            puts " $side7  length years:  "
            puts " $side1  civilizations:  "
            puts " $side2    "
            puts " $side3    "
            puts " $side4    "
            puts " $side5    "
            puts " $side6    "
            puts " $side7    "
            puts " $side8    "
            puts "answer   $side8 "
        }
        frame .buttons -bg aquamarine4
        ::ttk::button .calculator -text "Solve" -command { calculate   }
        ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 10. .5 2. 1.  .01 .01 10000. 10.}
        ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 10. .5 2. 1.  .01 .01 10000. 10. }
        ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 10. .5 2. 1.  .01 .01 10000. 10.  }
        ::ttk::button .clearallx -text clear -command {clearx  }
        ::ttk::button .about -text about -command about
        ::ttk::button .cons -text report -command { reportx }
        ::ttk::button .exit -text exit -command {exit}
        pack .calculator  -in .buttons -side top -padx 10 -pady 5
        pack  .clearallx .cons .about .exit .test4 .test3  .test2   -side bottom -in .buttons
        grid .frame .buttons -sticky ns -pady {0 10}
        . configure -background aquamarine4 -highlightcolor brown -relief raised -border 30
        wm title . "Drake Equation Calculator "

Context and starter code for namespace version

aspect /excerpted/ many of your examples seem to have a common presentation, with a similar GUI consisting of:

a set of labelled boxes for user input a "Solve" button which calls your main logic with the inputs as arguments a few "Testcase" buttons to illustrate examples and test the code "About", "Clear" and "Exit" buttons

I for one would love to see the GUI side of the code factored out into a common framework which each example could share. That way the wiki page for each calculator example could be focussed on the logic, looking something more like this:

namespace eval linear_interp {
  set name "Linear Interpolation Calculator"
  set inputs {"First X value" x1 "First Y value" y1 "Second X value" x2 "Second y value" y2 "Solve for x" xx}
  set about "This is Gold's linear interpolation calculator, © 2011
  .. with some more information on how it works and is used, etc"
  set testcases {
    {10. 10. 200. 50. 123.}
    # etc
  }
  proc calculate {x1 x2 y1 y2 xx} {
    return [expr {some magic here to calculate the result}]
  }
}
load generic_calculator_gui.tcl
generic_calculator_gui linear_interp

As a secondary advantage, your calculator could then without modification be used in other contexts, such as a command line or web tool or automatically invoking all the test cases. Of course, the GUI can also be easily re-skinned to the user's preferences without impacting the main code.

I hope you don't find the above overly critical or discouraging, that's certainly not my intention -- but I do think keeping the above points in mind will make your pages more appealing to other wiki'ers and encourage collaboration .. which is what we're all here for, after all!


gold test on calculator in namespace. The original program used global statements to pass data among subroutines. Some routines are working in canvas, clear,fillup,exit,load new testcase and solve with button. With number and all of variables so specified upfront, not sure how to float the calculations into the shell, other than to put an statement if not zero, answer is expr{ side1*side2...}

         package provide calculatorslot 1.0
            namespace eval slot {
                variable colorhigh
                variable colorback
                variable answer2
                variable answer3
                variable side1
                variable side2
                variable side3
                variable side4
                variable side5
                variable side6
                variable side7
                variable side8
                namespace export clearx
                namespace export fillup
                # drake equation
                # written on Windows XP on eTCL
                # working under TCL version 8.5.6 and eTCL 1.0.1
                # gold on TCL WIKI , 24aug2010
                proc initdisplay {} {
                    variable titlex
                    variable colorhigh
                    variable colorback
                    variable quantitylist
                    frame .frame -relief flat -bg $slot::colorback
                    pack .frame -side top -fill y -anchor center
                    set names $slot::quantitylist
                    foreach i {1 2 3 4 5 6 7 8} {
                        label .frame.label$i -text [lindex $names $i] -anchor e
                        entry .frame.entry$i -width 35 -textvariable slot::side$i
                        grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1
                    }
                    frame .buttons -bg $slot::colorback
                    ::ttk::button .calculator -text "Solve" -command { slot::calculate   }
                    ::ttk::button .test2 -text "Testcase1" -command {slot::clearx;slot::fillup 10. .5 2. 1.  .01 .01 10000. 10.}
                    ::ttk::button .test3 -text "Testcase2" -command {slot::clearx;slot::fillup 10. .5 2. 1.  .01 .01 10000. 10. }
                    ::ttk::button .test4 -text "Testcase3" -command {slot::clearx;slot::fillup 10. .5 2. 1.  .01 .01 10000. 10.  }
                    ::ttk::button .clearallx -text clear -command {slot::clearx  }
                    ::ttk::button .about -text about -command {slot::about}
                    ::ttk::button .cons -text report -command { slot::reportx }
                    ::ttk::button .exit -text exit -command {exit}
                    pack .calculator  -in .buttons -side top -padx 10 -pady 5
                    pack  .clearallx .cons .about .exit .test4 .test3  .test2   -side bottom -in .buttons
                    grid .frame .buttons -sticky ns -pady {0 10}
                    . configure -background $slot::colorback -highlightcolor $slot::colorhigh -relief raised -border 30
                    wm title . $slot::titlex
                }
                proc about {} {
                    variable msgx
                    set msg $slot::msgx
                    tk_messageBox -title "About" -message $msg
                }
                proc intelligent5 { xx1   } {
                    variable side1
                    variable side2
                    variable side3
                    variable side4
                    variable side5
                    variable side6
                    variable side7
                    variable side8
                    set side8  [ expr {  1*$side1*$side2*$side3*$side4*$side5*$side6*$side7 } ]
                    return $side8
                }
                proc calculate {     } {
                    variable answer2
                    variable answer3
                    variable side1
                    variable side2
                    variable side3
                    variable side4
                    variable side5
                    variable side6
                    variable side7
                    variable side8
                    set side8 8
                    set  answer2 5
                    set  answer2  [ intelligent5 $side8 ]
                    set  side8  $answer2
                }
                proc fillup {aa bb cc dd ee ff gg hh} {
                    .frame.entry1 insert 0 "$aa"
                    .frame.entry2 insert 0 "$bb"
                    .frame.entry3 insert 0 "$cc"
                    .frame.entry4 insert 0 "$dd"
                    .frame.entry5 insert 0 "$ee"
                    .frame.entry6 insert 0 "$ff "
                    .frame.entry7 insert 0 "$gg "
                    .frame.entry8 insert 0 "$hh "
                }
                proc clearx {} {
                    foreach i {1 2 3 4 5 6 7 8} {
                        .frame.entry$i delete 0 end
                    }
                }
                proc reportx {} {
                    variable colorwarning
                    variable colorback
                    variable answer2
                    variable answer3
                    variable side1
                    variable side2
                    variable side3
                    variable side4
                    variable side5
                    variable side6
                    variable side7
                    variable side8
                    console show;
                    puts " "
                    puts " $side1  star formation /yr:  "
                    puts " $side2  fraction w/ planets:  "
                    puts " $side3  poss life :  "
                    puts " $side4  actual life:  "
                    puts " $side5  civiliation develop:  "
                    puts " $side6  detectable signs:  "
                    puts " $side7  length years:  "
                    puts " $side8  civilizations:  "
                    puts " $side2    "
                    puts " $side3    "
                    puts " $side4    "
                    puts " $side5    "
                    puts " $side6    "
                    puts " $side7    "
                    puts " $side8    "
                    puts "answer is $side8 "
                }
            }
            #-------------------------- end namespace
            proc slotshell {} {
                set slot::titlex "Drake Equation Calculator in Namespace"
                set slot::colorback aquamarine4
                set slot::colorhigh brown
                set slot::msgx "Drake Calculator in Namespace.
                from TCL WIKI,
                written on eTCL "
                set slot::quantitylist  {{} {star formation /yr:} {fraction w/ planets:} {poss life :} {actual life:} {civiliation develop:}
                    {detectable signs:} {length years:} { civilizations:} }
                if {0} {  planned  >>>> here
                new slot::testcases {10. 10. 200. 50. 123....}
                    magic xproc calculate {x1 x2 y1 y2 xx ...}
                    return [expr {some magic here to calculate the result}]
                }
                namespace import slot::*
                slot::initdisplay
                set xcalls [clearx]
                set xcalls [fillup 7. .5 2. 1.  .01 .01 10000. 10.]                
                puts " clear&fillup called, push button solve"
                puts " program calculated data loaded from shell"
                }
            slotshell