I started to do some simple planning for a holiday on my personal wiki, and decided to add a total calulation mechanism. at the moment it only tablulates the numbers downwards until the CALC_TOTAL token....
so you can define your tables like:
| description |
value |
| a |
100 |
| b |
234 |
| c |
9 |
| d |
-2.3 |
| Total |
CALC_TOTAL |
where CALC_TOTAL is replaced by the sum..
unfortuanatly i have put the code into wiki.pm into getRenderedVersion
the other place that you can use this is as the last line in the
WebStatistics page
# SVEN 27-12-2000 table total calculations
sub calc_total
{
my ($rawTableText, $lastLine) = @_;
my ($column) = 0;
my ($sum) = 0;
my ($count) = 0;
my (@col);
foreach ( split( /\|/ ,$lastLine) )
{
if ( /CALC_TOTAL/ )
{
last;
}
$column += 1;
}
foreach( split( /\n/, $rawTableText ) )
{
@col = split(/\|/, $_ );
$sum += @col[$column];
$count += 1;
}
return "$sum";
}
...from getRenderedVersion...
my ( $rawTableText ) = "\n" ; # SVEN 27-12-2000 attempting to add total calculations to tables
...
# Table of format: | cell | cell |
if( $_ =~ /^(\s*)\|.*\|$/ ) {
while ( /CALC_TOTAL/ )
{
s/CALC_TOTAL/&calc_total($rawTableText, $_)/eo; # SVEN 27-12-2000 attempting to add total calculations to tables
}
$rawTableText .= $_."\n" ; # SVEN 27-12-2000 attempting to add total calculations to tables
s/^(\s*)\|(\s*)(.*)/&emitTR($1,$3,$insideTABLE)/eo;
$insideTABLE = 1;
} elsif( $insideTABLE ) {
$result .= "\n";
$insideTABLE = 0;
$rawTableText = "\n"; # SVEN 27-12-2000 attempting to add total calculations to tables
}
....
--
SvenDowideit - 28 Dec 2000
and we could have a simple mod to do percentages as on
TWikiReleaseSpring2001 for the total progress..
--
SvenDowideit - 28 Feb 2001
This can now be solved nicely with a
TWikiPlugin.
See also the
TWikiSpreadSheet idea.
--
PeterThoeny - 08 Mar 2001