IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 29, 2010, 12:38:27 PM (16 years ago)
Author:
rhenders
Message:

Improved xtics on time series; now only one time series function for both types of plots (all stages/1 stage)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/czartool/Czarplot.pm

    r28752 r28774  
    6565    my %gnuplotFiles;
    6666    my $stage = undef;
     67    my $gnuplotFile = undef;
    6768    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
    6973    }                                                           
    7074
    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);
    7390}                                                   
    7491
     
    131148###########################################################################
    132149#
     150# Sorts out plotting max/min x/y
     151#
     152###########################################################################
     153sub 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#
    133164# Plots a time-series of pending/faults
    134165#
    135166###########################################################################
    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;
     167sub 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;
    146194
    147195    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     
    156204        "set xdata time;" .
    157205        "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\";" .
    161208        "set xtics \"$minX\", $divX, \"$maxX\";" .
    162209        "set grid xtics;" .
     
    168215    foreach my $stage (keys %$gnuplotFiles) {
    169216        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        }
    171229        $firstIn = 0;
    172230    }
    173231
    174232    print GP "\n";
    175     close GP;
    176 }
    177 
    178 ###########################################################################
    179 #
    180 # Plots a time-series of pending/faults
    181 #
    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 GP
    199         "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";
    215233    close GP;
    216234}
     
    237255        "set style histogram cluster gap 3;" .
    238256        "set style fill solid border -1;" .
    239 #        "set boxwidth 1.5;" .
    240257        "set bmargin 5;" .
    241 #        "set xtic rotate by -90;" .
    242 #        "plot '$inputFile' using 2:xtic(1) notitle\n";
    243258        "set ylabel \"Exposures\";" .
    244259        "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.