1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
# copyright (C) 1997-98 Jean-Luc Fontaine (mailto:jfontain@mygale.org)
# this program is free software: please read the COPYRIGHT file enclosed in this package or use the Help Copyright menu
set rcsId {$Id: random.tcl,v 1.14 1998/09/04 22:02:55 jfontain Exp $}
# module sample file with random data
# corresponding pkgIndex.tcl file content:
# package ifneeded random 2.0 "source [file join $dir random.tcl]"
package provide random 3.0
namespace eval random { ;# namespace name must match package name
# Module data is arranged in a single array that can be used by many views, such as tables, graphs, pies,...
# It contains configuration values as well as dynamic data (see update procedure).
# Number of updates counter which may also serve as a variable to be traced on write to detect updates
# Label is the title displayed on the top cell of the data column.
# Valid types are those that the lsort command can handle.
# Message is a short help string that appears in the message area at the bottom of the data window when the mouse cursor passes
# over the column title cell.
# Poll times in seconds are placed in a list with the default poll time in first position. The other times can be in any order,
# as the core will sort them and use the lowest value as the minimum poll time value.
# The minimum poll seconds must be a reasonable value depending on the processing time of the moduleData procedure.
# The visibleColumns member is an optional list that specifies the table columns that should be displayed. If not specified,
# all the table columns are visible.
# The columns array member is the total number of data columns to be displayed (obsolete, no longer required).
# The sort list defines the initial column to be used for sorting the table data and in which direction. The specified column
# must be visible (see visibleColumns member above).
# The indexColumns list speficies the columns required to uniquely identify a row in the table. It is optional and defaults to
# the column 0, unless of course you do not have a 0 column index, in which case it is mandatory to specify this list. When
# specified, all the columns in the list must be visible (see visibleColumns member above).
# The help text will be displayed when the module help is launched from the main window help menu.
# The views member is optional. If specified, it defines one or more views to be used in place of the default view. One table
# will be displayed per view. Each view is a list of array members, suitable as an argument to an "array set" command. For
# each view, 2 members must be defined: visibleColumns and sort (syntax and usage are identical to the default table members).
array set data {
updates 0
0,label name 0,type ascii 0,message {user name}
1,label cpu 1,type real 1,message {cpu usage in percent}
2,label disk 2,type integer 2,message {disk usage in megabytes}
3,label memory 3,type integer 3,message {memory usage in kilobytes}
4,label command 4,type dictionary 4,message {command name}
pollTimes {10 5 20 30 60 120 300}
sort {1 decreasing}
indexColumns {0 4}
helpText {
This is a simple demonstration module for the moodss (Modular Object Oriented Dynamic SpreadSheet) utility. Most of the data is randomly generated.
Data is presented in 2 tables: one for the CPU and memory usage, the other for disk usage.
}
views {
{visibleColumns {0 1 3 4} sort {1 decreasing}}
{visibleColumns {0 2 4} sort {2 decreasing}}
}
}
set asynchronous 0 ;# set to true for asynchronous mode simulation
if {$asynchronous} {
# for a module to be asynchronous, the pollTimes member must be a single negative integer value. It the represents the
# preferred time interval for viewers that require one.
array set data {pollTimes -10}
after 3000 random::update ;# boot simulation
}
# the dynamic data array index is the row number followed by the column number separated by a comma
# the column number must start from 0 up to the total number of columns minus 1 (no holes are allowed in the column sequence)
# the row number can take any integer value and be defined in any order, as long as it is unique during the lifetime of the
# module data. if a new row is created, it must take a value that was never used: thus, the number of a row that has disappeared
# is not allowed. Row numbers need not be consecutive.
# the update procedure is mandatory only for synchronous modules, as it is never invoked by the core for asynchronous modules.
# the function is to update module data.
proc update {} {
variable data
variable asynchronous
array set data "
0,0 john 0,1 [format %.1f [expr {rand()*30}]] 0,2 [expr {100+int(rand()*50)}] 0,3 [expr {10+int(rand()*50)}] 0,4 cc
1,0 bill 1,1 [format %.1f [expr {rand()*3}]] 1,2 [expr {300+int(rand()*100)}] 1,3 [expr {30+int(rand()*100)}] 1,4 xedit
2,0 anny 2,1 [format %.1f [expr {rand()*5}]] 2,2 [expr {200+int(rand()*30)}] 2,3 [expr {20+int(rand()*30)}] 2,4 ps
4,0 peter 4,1 [format %.1f [expr {rand()*8}]] 4,2 [expr {50+int(rand()*10)}] 4,3 [expr {5+int(rand()*10)}] 4,4 ls
6,0 laura 6,1 [format %.1f [expr {rand()*20}]] 6,2 [expr {90+int(rand()*20)}] 6,3 [expr {9+int(rand()*20)}] 6,4 emacs
3,0 robert 3,1 [format %.1f [expr {rand()*10}]] 3,2 [expr {500+int(rand()*150)}] 3,3 [expr {50+int(rand()*150)}] 3,4 top
9,0 laura 9,1 [format %.1f [expr {rand()*30}]] 9,2 [expr {100+int(rand()*50)}] 9,3 [expr {10+int(rand()*50)}] 9,4 cc
"
incr data(updates) ;# write variable so that update can be detected with an eventual tcl write trace
if {$asynchronous} { ;# eventually simulate asynchronous operation
after [expr {2000+round(rand()*8000)}] random::update
}
}
}
|