IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14114


Ignore:
Timestamp:
Jul 10, 2007, 3:18:03 PM (19 years ago)
Author:
eugene
Message:

added features to protected fields with spaces using quotes, added methods for getting the NAN values by type and the values by their flag

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Metadata/Stats.pm

    r14086 r14114  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Stats.pm,v 1.21 2007-07-09 21:06:22 eugene Exp $
     3# $Id: Stats.pm,v 1.22 2007-07-11 01:18:03 eugene Exp $
    44
    55package PS::IPP::Metadata::Stats;
     
    5151}
    5252
     53sub cmdflags {
     54
     55    my $self = shift;                # Where we'll put the information
     56
     57    # apply the needed calculation to the data based on the type
     58   
     59    my $cmdflags;
     60    my $entries = $self->{entries};
     61   
     62    foreach my $entry (@$entries) {
     63        my $value = $entry->{value};
     64        my $flag = $entry->{flag};
     65        if ($value =~ m|\S+\s+\S+|) {
     66            # protect values with whitespace
     67            $cmdflags .= " $flag '$value'";
     68        } else {
     69            $cmdflags .= " $flag $value";
     70        }
     71    }
     72
     73    return $cmdflags;
     74}
     75
    5376# Given a parsed metadata from ppStats, assemble summary statistics
    5477sub parse {
     
    6891        if ($type eq "constant") {
    6992            if (not defined $entry->{value}) {
    70                 $entry->{value} = 'NAN';
     93                $self->_null_for_type ($entry);
    7194            }
    7295            next;
     
    80103                $entry->{value} = $stats->mean();
    81104            } else {
    82                 $entry->{value} = 'NAN';
     105                $self->_null_for_type ($entry);
    83106            }
    84107            next;
     
    97120                next;
    98121            }
    99             $entry->{value} = 'NAN';
     122            $self->_null_for_type ($entry);
    100123            next;
    101124        }
     
    109132                $entry->{value} = sqrt($stats->mean());
    110133            } else {
    111                 $entry->{value} = 'NAN';
     134                $self->_null_for_type ($entry);
    112135            }
    113136        }
     
    120143                $entry->{value} = $stats->sum();
    121144            } else {
    122                 $entry->{value} = 'NAN';
     145                $self->_null_for_type ($entry);
    123146            }
    124147        }
     
    126149
    127150    return $self;
     151}
     152
     153sub _null_for_type {
     154
     155    my ($self, $entry) = @_;
     156
     157    if ($entry->{dtype} eq "float") {
     158        $entry->{value} = 'NAN';
     159        return;
     160    }
     161    if ($entry->{dtype} eq "int") {
     162        $entry->{value} = '0';
     163        return;
     164    }
     165    if ($entry->{dtype} eq "string") {
     166        $entry->{value} = 'NULL';
     167        return;
     168    }
     169    $entry->{value} = 'NAN';
     170    return;
    128171}
    129172
     
    200243}
    201244
     245sub value_for_flag {
     246
     247    my $self = shift;
     248    my $flag = shift;
     249
     250    my $entries = $self->{entries};
     251
     252    foreach my $entry (@$entries) {
     253        if ($flag eq $entry->{flag}) {
     254            return $entry->{value};
     255        }
     256    }
     257    return 'NULL'; #
     258}
     259
     260
    202261# Return the data structure for a particular value, or the entire hash
    203262sub data {
Note: See TracChangeset for help on using the changeset viewer.