
| Current Path : /var/www/web-klick.de/dsh/90_akt/appserv/DivBasicF/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/90_akt/appserv/DivBasicF/ProgressBar.pm2 |
package DivBasicF::ProgressBar;
use strict;
use DBD::SQLite;
use Time::HiRes;
use Data::Dumper;
# An implementation of Progress bars.
# The main structure is an array $self->{'STEPS'},
# which stores sub-Progress bars
sub new {
my $class = shift;
my $self = {};
$self->{'NAME'} = shift;
$self->{'REMARK'} = shift;
$self->{'DONE'} = shift; # Time of work having been done yet
$self->{'PROGRESS'} = shift; # the part of the task that has been done (between 0 and 1)
$self->{'PLAN'} = [@_]; # Planned time OR a list of subtasks
bless($self,$class);
return($self);
}
#******************************************************************************
# 'Jumps' to the task with the $name. This means:
# If the $self task contains a subtask in its task tree underneath
# which contains the $name, then the have been done subtasks
# will be deleted, and its formerly todo efforts will be added
# to $self->{'DONE'}. $self->{'PROGRESS'} is newly computed.
#
# The return value in this case is the lasting todo effort
# with a leading negative sign.
# Otherwise the $self task will no be changed., and the function
# will return the lasting todo effort as a number > 0.
sub jump {
my $self = shift;
my $name = shift;
# We take the first element from the list of subtasks
my $done; my $subtask; my $name1;
# We assume that the $name belongs to a task which
# has no subtasks
# The actual subtask
# a) can be either consist of subtasks or
# b) be an atomic task (with no further subtasks)
# a) firstly we assume the first case where 'DONE'
# shows the work to HAVE been done
my $todo = $self->{'DONE'};
my $o = 1; # $o > 1 will indicate that no subtask containing $name exists
# for case b) we have to compute the $todo firstly
if (@{$self->{'PLAN'}}) {
# we now collect all work efforts of the subtask
# into $todo, so we set it to zero for the start
# of this collection process
$todo = 0;
# checking the subtasks in reverse order because
# the subtask not yet have been executed are in
# the rear part of this list
foreach $subtask (reverse @{$self->{'PLAN'}}) {
# we request the todo effort from the giuven subtask
# via the jump function which
$o = $subtask->jump($name);
# and set $name1 as a mark to that subtask
# and the actual done effort from that subtask, too
$name1 = $subtask->name();
$done = $subtask->done();
# The todo effort will be shown negative or zero,
# (as in the induction assumption) if the
# subtask contains the $name in its subtree,
# in this case we leave the loop
last if ($o <= 0);
# otherwise we add the subtask todo effort
$todo = $todo + $o;
}
}
# if we had leaved the loop WITHOUT finding
# a subtask in which the $name is subtree-contained:
# (this will be indicated that EACH $o has a
# value > 0 (hence, the last $o too)
if ($o > 0) {
# We have to distinguish two cases:
# first case: the $todo is the gross todo effort
return($todo) if ($self->{'NAME'} ne $name);
# otherwise we have the situation that all
# effort yet has been done, so that we have
# to write it down in $self->{'DONE'}
# and zero the $self->{'PLAN'}:
$self->{'DONE'} = $todo;
$self->{'PLAN'} = [];
return(0);
}
# The remaining case is that $name is contained in the
# subtree.
# We jumped out from the loop because we found that a
# subtask with name $name1 contains $name in the subtree
# Firstly we have to add its lasting todo effort
# to our gross $todo:
$todo = $todo - $o;
# (with a subtraction because this effort has been
# given with a negative sign to show that the
# subtask contains the $name in ints subtree).
# Now we delete all leading subtasks UNTIL we find
# the subtask we formerly marked with its name $name1
while (@{$self->{'PLAN'}}) {
last if ($self->{'PLAN'}->[0]->name() eq $name1);
$subtask = shift(@{$self->{'PLAN'}});
# and add all its 'todo' efforts. That efforts have been
# done now, so that we can add them to the $done part whis
# has begun with the $done from the $name1 task.
$done = $done + $subtask->jump($name);
}
# The $self->{'PLAN'} now consists of subtask in which
# all subtasks are not changed - except the first subtask.
# We now have a look whether its $self->{'PLAN'} now
# is empty, and if so, we delete it:
shift(@{$self->{'PLAN'}}) if ($self->{'PLAN'}->[0]->is_empty());
# Compute new PROGRESS and DONE:
$self->{'PROGRESS'} = $self->{'PROGRESS'} + $done /
($done + $todo) * ( 1 - $self->{'PROGRESS'} );
$self->{'DONE'} = $self->{'DONE'} + $done;
# ... beacuse we want to indicate that $self contains the $name:
return( - $todo );
}
#****************************************************************************
sub name { my $self = shift; return($self->{'NAME'}); }
sub done { my $self = shift; return($self->{'DONE'}); }
sub is_empty { my $self = shift; return(0) if (@{$self->{'PLAN'}}); return(1); }
sub change_variables {
my $self = shift;
my $file = shift;
open(FFILE,"<".$file);
my $text = join("",<FFILE>);
close(FILE);
$text =~ s/\'DONE\'/donework/gs;
$text =~ s/\'PROGRESS\'/progress/gs;
$text =~ s/\'PLAN\'/subTasks/gs;
$text =~ s/\'NAME\'/name/gs;
$text =~ s/\'REMARK\'/label/gs;
$text =~ s/\-\>done\(/\-\>setGetDoneWork\(/gs;
$text =~ s/\-\>is_empty\(/\-\>noSubTasks\(/gs;
print $text;
}
1;