[Bio] / FigKernelPackages / Stats.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/Stats.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5, Tue Apr 29 05:49:26 2008 UTC revision 1.8, Thu Apr 2 01:11:22 2009 UTC
# Line 129  Line 129 
129      $self->AddMessage($other->{Messages});      $self->AddMessage($other->{Messages});
130  }  }
131    
132    =head3 Messages
133    
134        my @text = $stats->Messages();
135    
136    Return a list of the messages stored in this object.
137    
138    =cut
139    
140    sub Messages {
141        # Get the parameters.
142        my ($self) = @_;
143        # Split up the messages.
144        my @retVal = split /\n/, $self->{Messages};
145        # Return the result.
146        return @retVal;
147    }
148    
149  =head3 Ask  =head3 Ask
150    
151      my $counter = $stats->Ask($name);      my $counter = $stats->Ask($name);
# Line 215  Line 232 
232      my $retVal = "";      my $retVal = "";
233      # Get the map.      # Get the map.
234      my $map = $self->{Map};      my $map = $self->{Map};
235        # Get the key list.
236        my @keys = sort keys %{$map};
237        # Convert all the statistics to integers.
238        my %intMap;
239        for my $statKey (@keys) {
240            $intMap{$statKey} = sprintf("%d", $map->{$statKey});
241        }
242      # Compute the key size.      # Compute the key size.
243      my $keySize = Tracer::Max(map { length $_ } keys %{$map}) + 1;      my $keySize = Tracer::Max(map { length $_ } @keys) + 1;
244      my $statSize = Tracer::Max(map { length "$map->{$_}" } keys %{$map}) + 1;      my $statSize = Tracer::Max(map { length "$intMap{$_}" } @keys) + 1;
245      # Loop through the statistics.      # Loop through the statistics.
246      for my $statKey (sort keys %{$map}) {      for my $statKey (@keys) {
247          # Add the statistic and its value.          # Add the statistic and its value.
         my $statValue = $map->{$statKey};  
248          $retVal .= Tracer::Pad($statKey, $keySize) .          $retVal .= Tracer::Pad($statKey, $keySize) .
249                     Tracer::Pad($statValue, $statSize, 'left') . "\n";                     Tracer::Pad($intMap{$statKey}, $statSize, 'left') . "\n";
250      }      }
251      # Display the messages.      # Display the messages.
252      $retVal .= "\n" . $self->{Messages} . "\n";      $retVal .= "\n" . $self->{Messages} . "\n";
# Line 291  Line 314 
314      return @retVal;      return @retVal;
315  }  }
316    
317    =head3 Check
318    
319        my $flag = $stats->Check($counter => $period);
320    
321    Increment the specified statistic and return TRUE if the result is a
322    multiple of the specified period. This is a helpful method for generating
323    periodic trace messages. For example,
324    
325        Trace($stats->Ask('frogs') . " frogs processed.") if $stats->Check(frogs => 100) && T(3);
326    
327    will generate a trace message at level 3 for every 100 frogs processed.
328    
329    =over 4
330    
331    =item counter
332    
333    Name of the relevant statistic.
334    
335    =item period
336    
337    Periodicity value.
338    
339    =item RETURN
340    
341    Returns TRUE if the new value of the statistic is a multiple of the periodicity, else FALSE.
342    
343    =back
344    
345    =cut
346    
347    sub Check {
348        # Get the parameters.
349        my ($self, $counter, $period) = @_;
350        # Increment the statistic.
351        my $count = $self->Add($counter => 1);
352        # Check the new value against the periodicity.
353        my $retVal = ($count % $period == 0);
354        # Return the result.
355        return $retVal;
356    }
357    
358    =head3 Progress
359    
360        my $percent = $stats->Progress($counter => $total);
361    
362    Increment a statistic and return the percent progress toward a specified
363    total.
364    
365    =over 4
366    
367    =item counter
368    
369    Name of the relevant statistic.
370    
371    =item total
372    
373    Total number of objects being counted.
374    
375    =item RETURN
376    
377    Returns the percent of the total objects processed, including the current one.
378    
379    =back
380    
381    =cut
382    
383    sub Progress {
384        # Get the parameters.
385        my ($self, $counter, $total) = @_;
386        # Compute the return value.
387        my $retVal = $self->Add($counter => 1) * 100 / $total;
388        # Return the result.
389        return $retVal;
390    }
391    
392    
393  1;  1;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3