Changeset 28774
- Timestamp:
- Jul 29, 2010, 12:38:27 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/tools/czartool/Czarplot.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/czartool/Czarplot.pm
r28752 r28774 65 65 my %gnuplotFiles; 66 66 my $stage = undef; 67 my $gnuplotFile = undef; 67 68 foreach $stage (@{$stages}) { 68 $gnuplotFiles{$stage} = $self->{_czarDb}->createTimeSeriesData($label, $stage, $beginTime, $endTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff); 69 70 $gnuplotFile = $self->{_czarDb}->createTimeSeriesData($label, $stage, $beginTime, $endTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff); 71 if ($gnuplotFile) {$gnuplotFiles{$stage} = $gnuplotFile;} 72 69 73 } 70 74 71 if (!$selectedStage) {plotAllStagesTimeSeries($self, $outputFile, $label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff, \%gnuplotFiles);} 72 else {plotSingleTimeSeries($self, $gnuplotFiles{$selectedStage}, $outputFile, $selectedStage, $label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff);} 75 my $numOfPlots = keys(%gnuplotFiles); 76 77 if ($numOfPlots == 0 ) { 78 79 print "Warning: No plots could be generated for '$label' during time period '$beginTime', '$endTime'\n"; 80 return; 81 } 82 83 if ($timeDiff == 0) { 84 85 print "WARNING: Zero time difference for '$label' during time period '$beginTime', '$endTime'\n"; 86 return; 87 } 88 89 plotTimeSeries($self, \%gnuplotFiles, $outputFile, $label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff); 73 90 } 74 91 … … 131 148 ########################################################################### 132 149 # 150 # Sorts out plotting max/min x/y 151 # 152 ########################################################################### 153 sub sortOutMaxMinY { 154 my ($self, $minY, $maxY) = @_; 155 156 ${$maxY} = ${$maxY} + (${$maxY}/10); 157 ${$minY} = ${$minY} - (${$minY}/10); 158 if (${$maxY} == 0) {${$maxY} = 1;} 159 if (${$minY} == 0) {${$minY} = -1;} 160 } 161 162 ########################################################################### 163 # 133 164 # Plots a time-series of pending/faults 134 165 # 135 166 ########################################################################### 136 sub plotAllStagesTimeSeries { 137 my ($self, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $maxY, $minY, $timeDiff, $gnuplotFiles) = @_; 138 139 $maxY = $maxY + ($maxY/10); 140 $minY = $minY - ($minY/10); 141 if ($maxY == 0) {$maxY = 1;} 142 if ($maxY == 0) {$maxY = 1;} 143 if ($minY == 0) {$minY = -1;} 144 145 my $divX = $timeDiff/2; 167 sub plotTimeSeries { 168 my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $maxY, $minY, $timeDiff) = @_; 169 170 $self->sortOutMaxMinY(\$minY, \$maxY); 171 172 my $timeFormat = undef; 173 174 my $divX = $timeDiff/4; 175 176 # if less than a couple of hours data plotted, show 30 mins tics 177 if ($timeDiff < 7200) { 178 $timeFormat = "%H:%M"; 179 $divX = 1800; 180 } 181 # if less than one days data plotted, show hourly tics 182 elsif ($timeDiff < 86400) { 183 $timeFormat = "%H:%M"; 184 $divX = 3600; 185 } 186 # if more than one days data plotted, show daisy tics 187 else { 188 189 $timeFormat = "%m/%d %H:%M"; 190 $divX = 86400; 191 } 192 193 my $numOfPlots = keys %$gnuplotFiles; 146 194 147 195 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; … … 156 204 "set xdata time;" . 157 205 "set timefmt \"$self->{_dateFormat}\";" . 158 #"set xrange [\"$minX\":\"$maxX\"];" . 159 #"set yrange [$minY:$maxY];" . 160 "set format x \"%m/%d %H:%M\";" . 206 "set xrange [\"$minX\":\"$maxX\"];" . 207 "set format x \"$timeFormat\";" . 161 208 "set xtics \"$minX\", $divX, \"$maxX\";" . 162 209 "set grid xtics;" . … … 168 215 foreach my $stage (keys %$gnuplotFiles) { 169 216 if (!$firstIn) {print GP ",";} 170 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"$stage\" with lines"; 217 218 # for single stage plots, show pending/processed/faults 219 if ($numOfPlots == 1) { 220 221 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"processed\" with lines lt 2,"; 222 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:2 title \"pending\" with lines lt 3,"; 223 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:3 title \"faults\" with lines lt 1"; 224 } 225 # when plotting multiple stages, show only processed 226 else { 227 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"$stage\" with lines"; 228 } 171 229 $firstIn = 0; 172 230 } 173 231 174 232 print GP "\n"; 175 close GP;176 }177 178 ###########################################################################179 #180 # Plots a time-series of pending/faults181 #182 ###########################################################################183 sub plotSingleTimeSeries {184 my ($self, $inputFile, $outputFile, $stage, $label, $fromTime, $toTime, $maxX, $minX, $maxY, $minY, $timeDiff) = @_;185 186 $maxY = $maxY + ($maxY/10);187 $minY = $minY - ($minY/10);188 if ($maxY == 0) {$maxY = 1;}189 if ($maxY == 0) {$maxY = 1;}190 if ($minY == 0) {$minY = -1;}191 192 my $divX = $timeDiff/2;193 194 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";195 use FileHandle;196 GP->autoflush(1);197 198 print GP199 "set term $self->{_outputFormat};" .200 "set output \"$outputFile\";" .201 "set title \"'$stage' stage for '$label' since $fromTime\";" .202 "set key left top;" .203 "set xdata time;" .204 "set timefmt \"$self->{_dateFormat}\";" .205 "set xrange [\"$minX\":\"$maxX\"];" .206 "set yrange [$minY:$maxY];" .207 "set format x \"%m/%d %H:%M\";" .208 "set xtics \"$minX\", $divX, \"$maxX\";" .209 "set grid;" .210 "set xlabel \"Time\";" .211 "set ylabel \"Exposures\";" .212 "plot '$inputFile' using 1:4 title \"processed\" with lines lt 2," .213 "'$inputFile' using 1:2 title \"pending\" with lines lt 3," .214 "'$inputFile' using 1:3 title \"faults\" with lines lt 1\n";215 233 close GP; 216 234 } … … 237 255 "set style histogram cluster gap 3;" . 238 256 "set style fill solid border -1;" . 239 # "set boxwidth 1.5;" .240 257 "set bmargin 5;" . 241 # "set xtic rotate by -90;" .242 # "plot '$inputFile' using 2:xtic(1) notitle\n";243 258 "set ylabel \"Exposures\";" . 244 259 "plot '$inputFile' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 3, '' using 4 title \"Faults\" lt 1\n";
Note:
See TracChangeset
for help on using the changeset viewer.
