[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.7, Tue Sep 30 15:18:59 2008 UTC
# Line 215  Line 215 
215      my $retVal = "";      my $retVal = "";
216      # Get the map.      # Get the map.
217      my $map = $self->{Map};      my $map = $self->{Map};
218        # Get the key list.
219        my @keys = sort keys %{$map};
220        # Convert all the statistics to integers.
221        my %intMap;
222        for my $statKey (@keys) {
223            $intMap{$statKey} = sprintf("%d", $map->{$statKey});
224        }
225      # Compute the key size.      # Compute the key size.
226      my $keySize = Tracer::Max(map { length $_ } keys %{$map}) + 1;      my $keySize = Tracer::Max(map { length $_ } @keys) + 1;
227      my $statSize = Tracer::Max(map { length "$map->{$_}" } keys %{$map}) + 1;      my $statSize = Tracer::Max(map { length "$intMap{$_}" } @keys) + 1;
228      # Loop through the statistics.      # Loop through the statistics.
229      for my $statKey (sort keys %{$map}) {      for my $statKey (@keys) {
230          # Add the statistic and its value.          # Add the statistic and its value.
         my $statValue = $map->{$statKey};  
231          $retVal .= Tracer::Pad($statKey, $keySize) .          $retVal .= Tracer::Pad($statKey, $keySize) .
232                     Tracer::Pad($statValue, $statSize, 'left') . "\n";                     Tracer::Pad($intMap{$statKey}, $statSize, 'left') . "\n";
233      }      }
234      # Display the messages.      # Display the messages.
235      $retVal .= "\n" . $self->{Messages} . "\n";      $retVal .= "\n" . $self->{Messages} . "\n";
# Line 291  Line 297 
297      return @retVal;      return @retVal;
298  }  }
299    
300    =head3 Check
301    
302        my $flag = $stats->Check($counter => $period);
303    
304    Increment the specified statistic and return TRUE if the result is a
305    multiple of the specified period. This is a helpful method for generating
306    periodic trace messages. For example,
307    
308        Trace($stats->Ask('frogs') . " frogs processed.") if $stats->Check(frogs => 100) && T(3);
309    
310    will generate a trace message at level 3 for every 100 frogs processed.
311    
312    =over 4
313    
314    =item counter
315    
316    Name of the relevant statistic.
317    
318    =item period
319    
320    Periodicity value.
321    
322    =item RETURN
323    
324    Returns TRUE if the new value of the statistic is a multiple of the periodicity, else FALSE.
325    
326    =back
327    
328    =cut
329    
330    sub Check {
331        # Get the parameters.
332        my ($self, $counter, $period) = @_;
333        # Increment the statistic.
334        my $count = $self->Add($counter => 1);
335        # Check the new value against the periodicity.
336        my $retVal = ($count % $period == 0);
337        # Return the result.
338        return $retVal;
339    }
340    
341    =head3 Progress
342    
343        my $percent = $stats->Progress($counter => $total);
344    
345    Increment a statistic and return the percent progress toward a specified
346    total.
347    
348    =over 4
349    
350    =item counter
351    
352    Name of the relevant statistic.
353    
354    =item total
355    
356    Total number of objects being counted.
357    
358    =item RETURN
359    
360    Returns the percent of the total objects processed, including the current one.
361    
362    =back
363    
364    =cut
365    
366    sub Progress {
367        # Get the parameters.
368        my ($self, $counter, $total) = @_;
369        # Compute the return value.
370        my $retVal = $self->Add($counter => 1) * 100 / $total;
371        # Return the result.
372        return $retVal;
373    }
374    
375    
376  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3