Index: openacs-4/packages/accounts-finance/tcl/modeling-functions.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/accounts-finance/tcl/modeling-functions.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/accounts-finance/tcl/modeling-functions.tcl 13 Aug 2010 06:41:13 -0000 1.1 +++ openacs-4/packages/accounts-finance/tcl/modeling-functions.tcl 6 Sep 2010 11:01:41 -0000 1.2 @@ -193,6 +193,63 @@ } +ad_proc -public qaf_model_output_to_qss_list { + tcl_list_of_lists +} { + returns a table that is in a list_of_lists format usable by qss_* spreadsheets +} { + set columns_count [llength $tcl_list_of_lists] + set column_number 0 + set rows_count 0 + + foreach column_list $tcl_list_of_lists { + # determine table's row size by examining row size for each column + set row_count($column_number) [llength $column_list] + set row $first_are_titles + set row_prev [lindex $column_list $first_are_titles] + + set is_constant 1 + + while { $row < $row_count($column_number) && $is_constant } { + set row_now [lindex $column_list $row] + # examine the data of each column's row, if constant, maybe display as a constant. + set is_constant [expr { $is_constant && ( $row_prev == $row_now ) } ] + set row_prev $row_now + incr row + } + # title_row_count = the number of rows dedicated to the title, 1 row for spreadsheets + set title_row_count [expr { $first_are_titles + 1 } ] + set true_column($column_number) [expr { !$is_constant } ] + set rows_count [expr { [f::max $rows_count $row_count($column_number) ] } ] + incr column_number + } + # rows_count now contains max rows + set table_list [list ] + if { !$first_are_titles } { + # qss spreadsheet requires first row to be column titles + return $table_list + } + + for {set row_index 0} { $row_index < $rows_count } { incr row_index 1 } { + set row_list [list ] + # process row + for {set column_index 0} { $column_index < $columns_count } { incr column_index 1 } { + if { $true_column($column_index) } { + # process this column / cell + set cell_value [lindex [lindex $tcl_list_of_lists $column_index ] $row_index] + } else { + set cell_value [lindex [lindex $tcl_list_of_lists $column_index ] 1] + } + lappend row_list $cell_value + } + append table_list $row_list + } + # next row + + return $table_list +} + + ad_proc -public acc_fin::list_set { list_of_values {delimiter " "} @@ -320,4 +377,31 @@ return $indexes_unique_list } +ad_proc -public acc_fin::compress_eq { + func +} { + Returns an equation compressed (without spaces). No other substitutions are made. +} { + regsub -all -- { } $func {} func2 + return $func2 +} +ad_proc -public acc_fin::de_compress_eq { + func +} { + Returns an equation uncompressed (with spaces). Each comma is converted to a space. A semicolon is converted to a close bracket/ +} { +proc qaf_decompress_eq { func } { + regsub -all -- {;} $func {\]} func + regsub -all -- {,} $func { } func + regsub -all -- {([\>\<\/\*\)])} $func { \1 } func + regsub -all -- {([\+\-])([^0-9.])} $func { \1 \2} func + regsub -all -- {([^a-zA-Z])[\(]} $func {\1 ( } func + regsub -all -- {[\&][\&]} $func { \&\& } func + regsub -all -- {([a-zA-Z0-9_\.])([\)\+\-\/\=\*])} $func {\1 \2} func + regsub -all -- {([\(\+\-\/\=\*])([a-zA-Z0-9_])} $func {\1 \2} func + regsub -all -- {[ ]+} $func { } func + return $func +} + + Index: openacs-4/packages/accounts-finance/tcl/modeling-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/accounts-finance/tcl/modeling-procs.tcl,v diff -u -N -r1.22 -r1.23 --- openacs-4/packages/accounts-finance/tcl/modeling-procs.tcl 13 Aug 2010 06:41:13 -0000 1.22 +++ openacs-4/packages/accounts-finance/tcl/modeling-procs.tcl 6 Sep 2010 11:01:41 -0000 1.23 @@ -7,6 +7,12 @@ namespace eval acc_fin {} +ad_proc -private acc_fin::qaf_id_new { +} { + returns a unique id from qaf_id_sequence +} { + return db_nextval qaf_id_seq +} ad_proc -private acc_fin::template_model { template_number @@ -296,6 +302,9 @@ Returns a list of lists. First list element denotes how many errors there were. If number_of_iterations is greater than 0, Returns a list of lists, where each list element consists of a variable name and the values that it returns after each iteration, including the initial conditions. The report calculations return the variable name and the value returned from the function evaluation. + +NOTE: this list_of_lists format is diffrent than the standard list_of_lists table format where the first element of the list_of_lists contains ordered variable names, followed by ordered columns of one row of data. Reason: many of the model data may have variable number of values, such as 1 or interactions_count. Using the standard method is would be a bulky way of storing many models. + If there are errors during compile, then subsequent list elements are the results of the model compile, useful for debugging purposes. Loop through model N (number) iterations, 0 iterations means pre-compile only (and check model for immediate errors).