Changeset 14114
- Timestamp:
- Jul 10, 2007, 3:18:03 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-Config/lib/PS/IPP/Metadata/Stats.pm (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Config/lib/PS/IPP/Metadata/Stats.pm
r14086 r14114 1 1 # Copyright (c) 2006 Paul Price, Joshua Hoblitt 2 2 # 3 # $Id: Stats.pm,v 1.2 1 2007-07-09 21:06:22eugene Exp $3 # $Id: Stats.pm,v 1.22 2007-07-11 01:18:03 eugene Exp $ 4 4 5 5 package PS::IPP::Metadata::Stats; … … 51 51 } 52 52 53 sub 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 53 76 # Given a parsed metadata from ppStats, assemble summary statistics 54 77 sub parse { … … 68 91 if ($type eq "constant") { 69 92 if (not defined $entry->{value}) { 70 $ entry->{value} = 'NAN';93 $self->_null_for_type ($entry); 71 94 } 72 95 next; … … 80 103 $entry->{value} = $stats->mean(); 81 104 } else { 82 $ entry->{value} = 'NAN';105 $self->_null_for_type ($entry); 83 106 } 84 107 next; … … 97 120 next; 98 121 } 99 $ entry->{value} = 'NAN';122 $self->_null_for_type ($entry); 100 123 next; 101 124 } … … 109 132 $entry->{value} = sqrt($stats->mean()); 110 133 } else { 111 $ entry->{value} = 'NAN';134 $self->_null_for_type ($entry); 112 135 } 113 136 } … … 120 143 $entry->{value} = $stats->sum(); 121 144 } else { 122 $ entry->{value} = 'NAN';145 $self->_null_for_type ($entry); 123 146 } 124 147 } … … 126 149 127 150 return $self; 151 } 152 153 sub _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; 128 171 } 129 172 … … 200 243 } 201 244 245 sub 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 202 261 # Return the data structure for a particular value, or the entire hash 203 262 sub data {
Note:
See TracChangeset
for help on using the changeset viewer.
