IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29373


Ignore:
Timestamp:
Oct 11, 2010, 3:11:19 PM (16 years ago)
Author:
rhenders
Message:

Big changes to introduce rate=of-procesing plots as well as removing misleading cleanup from other plots

Location:
trunk/tools/czartool
Files:
2 edited

Legend:

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

    r29281 r29373  
    4343SQL
    4444
    45 
    46     if (!$query->execute) {
    47 
    48         return 0;
    49     }
     45    if (!$query->execute) {return 0;}
    5046
    5147    ${$labels} = $query->fetchall_arrayref();
     
    242238###########################################################################
    243239#
    244 # Gets time series data and stores it to temp file
    245 #
    246 ###########################################################################
    247 sub createTimeSeriesData {
    248     my ($self, $label, $stage, $fromTime, $toTime, $minX, $maxX, $minY, $maxY, $timeDiff, $dataFile, $isLog) = @_;
    249 
    250     ${$dataFile} = "/tmp/czarplot_gnuplot_".$label."_".$stage."_t.dat";
    251 
    252     open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
     240# Gets time min/max/diff for a given period
     241#
     242###########################################################################
     243sub getTimeMinMaxDiff {
     244    my ($self, $label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff) = @_;
    253245
    254246    my $query = $self->{_db}->prepare(<<SQL);
    255247    SELECT
    256         MIN(processed), GREATEST(MAX(pending), MAX(faults), max(processed)-min(processed)) AS maxY,
    257         LEAST(MIN(pending), MIN(faults), max(processed)-min(processed)) AS minY,
    258248        DATE_FORMAT(MAX(timestamp),'$self->{_dateFormat}'),
    259249        DATE_FORMAT(MIN(timestamp),'$self->{_dateFormat}'),
     
    266256    if (!$query->execute) {return 0;}
    267257
    268     my $minProcessed = undef;
    269     my ($_maxY, $_minY, $_timeDiff);
    270     ($minProcessed, $_maxY, $_minY, ${$maxX}, ${$minX}, $_timeDiff) = $query->fetchrow_array();
    271 
    272     if ($_maxY > ${$maxY}) {${$maxY} = $_maxY;}
    273     if ($_minY < ${$minY}) {${$minY} = $_minY;}
     258    my ($_timeDiff);
     259    (${$maxX}, ${$minX}, $_timeDiff) = $query->fetchrow_array();
     260
    274261    if ($_timeDiff > ${$timeDiff}) {${$timeDiff} = $_timeDiff;}
    275262
     263return 1;
     264}
     265
     266
     267###########################################################################
     268#
     269# Gets time series data and stores it to temp file
     270#
     271###########################################################################
     272sub createTimeSeriesData {
     273    my ($self, $label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff, $dataFile, $isLog, $showCleanup) = @_;
     274
     275    my $query = $self->{_db}->prepare(<<SQL);
     276    SELECT
     277        MIN(processed)
     278        FROM $stage
     279        WHERE label LIKE '$label'
     280        AND timestamp >= '$fromTime' AND timestamp <= '$toTime';
     281SQL
     282
     283    if (!$query->execute) {return 0;}
     284    my $minProcessed = scalar  $query->fetchrow_array(); # TODO remove
    276285    if (!defined $minProcessed) {return 0;}
     286
     287    $self->getTimeMinMaxDiff($label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff);
    277288
    278289    $query = $self->{_db}->prepare(<<SQL);
    279290    SELECT
    280         DATE_FORMAT(timestamp, '$self->{_dateFormat}'), pending, faults, processed-$minProcessed
     291        DATE_FORMAT(timestamp, '$self->{_dateFormat}'), pending, faults, processed
    281292        FROM $stage
    282293        WHERE label LIKE '$label'
     
    287298    $query->execute;
    288299
    289     # loop round results
     300    ${$dataFile} = "/tmp/czarplot_gnuplot_".$label."_".$stage."_t.dat";
     301    open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
     302
     303    my $lastProcessed = -1;
     304    my $processed = 0;
    290305    while (my @row = $query->fetchrow_array()) {
    291         my ($timestamp, $pending, $faults, $processed) = @row;
     306        my ($timestamp, $pending, $faults, $thisProcessed) = @row;
     307
     308        if ($showCleanup) {
     309       
     310        $processed = $thisProcessed - $minProcessed;
     311        }
     312        elsif($lastProcessed != -1 && $thisProcessed > $lastProcessed) {
     313           
     314            $processed = $processed + ($thisProcessed - $lastProcessed);
     315        }
    292316
    293317        if ($isLog) {
     
    303327
    304328        print GNUDAT "$timestamp $pending $faults $processed\n";
     329        $lastProcessed = $thisProcessed;
    305330    }
    306331
     
    365390sub countProcessedPendingAndFaults {
    366391    my ($self, $label, $stage, $fromTime, $toTime, $processed, $pending, $faults) = @_;
    367 
    368392
    369393    my $query = $self->{_db}->prepare(<<SQL);
     
    379403    (${$pending}, ${$faults}) = $query->fetchrow_array();   
    380404
    381     $query = $self->{_db}->prepare(<<SQL);
    382     SELECT
    383         MAX(processed) - MIN(processed)
    384         FROM $stage
    385         WHERE label LIKE '$label'
    386         AND timestamp >= '$fromTime' AND timestamp <= '$toTime';
    387 SQL
    388     $query->execute;
    389     (${$processed}) = $query->fetchrow_array();
     405    ${$processed} = $self->countProcessed($label, $stage, $fromTime, $toTime);
     406
     407    return 1;
    390408}
    391409
     
    510528        print GNUDAT "$timestamp $available\n";
    511529    }
     530
    512531    close(GNUDAT);
    513532
    514533    return $dataFile;
    515534}
    516 ###########################################################################
    517 #
    518 # Determines how much has been processed in the provided interval of time
    519 # (format: 1 HOUR, 1 MINUTE 1 DAY etc)
    520 #
    521 ###########################################################################
    522 sub countProcessed { # TODO use time not interval
    523     my ($self, $label, $stage, $interval) = @_;
     535
     536###########################################################################
     537#
     538# TODO implement isLog
     539#
     540###########################################################################
     541sub createProcessingRateData {
     542    my ($self, $stage, $label, $startDay, $endDay, $interval, $dataFile, $isLog) = @_;
     543
     544    my $startTime = $startDay;
     545    my $endTime;
     546    my $quit = 0;
     547    my $processed;
     548    my $pending;
     549    my $faults;
     550    my $timestamp;
     551    ${$dataFile} = "/tmp/czarplot_gnuplot_".$label."_".$stage."_r.dat";
     552    open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
     553    my $cleanupCarry = 0;
     554    while(1) {
     555
     556        if (!$self->isBefore($startTime, $endDay)) {last;}
     557        $endTime = $self->addInterval($startTime, $interval);
     558print "NNN $startTime, $endTime\n";
     559        $self->countProcessedPendingAndFaults($label, $stage, $startTime, $endTime, \$processed, \$pending, \$faults);
     560        $timestamp = $self->getFormattedDate($endTime);
     561        print GNUDAT "$timestamp $processed 0 0\n";
     562        print  "FILE $timestamp $processed 0 0\n";
     563
     564        $startTime = $endTime;
     565    }
     566
     567    close(GNUDAT) or print "* Problem closing gnuplot data file for rate plot for '$label' '$stage'\n"
     568}
     569
     570###########################################################################
     571#
     572# Gets count of processed stuff in a given time period
     573#
     574###########################################################################
     575sub countProcessed {
     576    my ($self, $label, $stage, $begin, $end) = @_;
    524577
    525578    my $query = $self->{_db}->prepare(<<SQL);
    526579    SELECT
    527         MAX(processed) - MIN(processed)
    528         FROM $stage 
     580        processed
     581        FROM $stage
    529582        WHERE label LIKE '$label'
    530         AND timestamp > (now() - INTERVAL $interval);
    531 SQL
    532         $query->execute;
    533 
    534     return scalar $query->fetchrow_array();
    535 }
    536 
     583        AND timestamp >= '$begin'
     584        AND timestamp < '$end'
     585SQL
     586    $query->execute;
     587
     588    my $processedArray = $query->fetchall_arrayref();
     589
     590    my $processed;
     591    my $thisCount = -1;
     592    my $lastCount = -1;
     593    my $count = 0;
     594    foreach $processed ( @{$processedArray} ){
     595
     596        ($thisCount) = @{$processed};
     597
     598        if ($thisCount > $lastCount && $lastCount != -1) {$count = $count + ($thisCount -  $lastCount);}
     599        print "thisCount = $thisCount lastCount=$lastCount processed=$count\n";
     600        $lastCount = $thisCount;
     601    }
     602
     603    return $count;
     604}
    537605
    538606###########################################################################
  • trunk/tools/czartool/Plotter.pm

    r29121 r29373  
    3333###########################################################################
    3434sub createImageFileName {
    35     my ($self, $label, $stage, $suffix, $isLog) = @_;
     35    my ($self, $label, $stage, $suffix, $isLog, $isRate) = @_;
    3636
    3737    my $prefix = $self->{_outputPath} ? $self->{_outputPath} : ".";
     
    5555###########################################################################
    5656#
     57# Plots a time series of processing rate for all stages for this label TODO duplication below. combine
     58#
     59###########################################################################
     60sub createRateTimeSeries {
     61    my ($self, $label, $selectedStage, $beginTime, $endTime, $interval, $isLog) = @_;
     62
     63    my $minX = 999999999;     
     64    my $maxX = -9999999999;
     65    my $timeDiff = -1;
     66
     67    my $stages = undef;                 
     68
     69    if (!$selectedStage) {$stages = \@allStages;}
     70    else {$stages = ["$selectedStage"]};       
     71
     72    $self->{_czarDb}->getTimeMinMaxDiff($label, $selectedStage, $beginTime, $endTime, \$minX, \$maxX, \$timeDiff);
     73
     74    my $divX;
     75    my $timeFormat;
     76    $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat);
     77
     78print "$beginTime, $endTime  | $divX $minX $maxX $timeFormat\n";
     79
     80    my %gnuplotFiles;
     81    my $stage = undef;
     82    my $gnuplotFile = undef;
     83    my $outputFile = createImageFileName($self, $label, $selectedStage, "r", $isLog);
     84    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     85    use FileHandle;
     86    GP->autoflush(1);
     87    print GP
     88        "set term $self->{_outputFormat};" .
     89        "set output \"$outputFile\";" .
     90        "set title \"'$label', '$selectedStage' during '$beginTime' to '$endTime'\";" .
     91        #"set xdata time;" .
     92        "set timefmt \"$self->{_dateFormat}\";" .
     93       "set format x \"$timeFormat\";" .
     94        "set xtics \"$minX\", $divX, \"$maxX\";" .
     95#        "set xrange [\"$minX\":\"$maxX\"];" .
     96        "set grid;" .
     97        "set boxwidth;" .
     98        "set style data histogram;" .
     99        "set style histogram rowstacked;" .
     100        "set style fill solid border -1;" .
     101        "set ylabel \"Exposures processed per $interval\";" .
     102        "set boxwidth 0.75;" .
     103        "plot ";
     104
     105    my $first = 1;
     106    foreach $stage (@{$stages}) {
     107
     108        if ($self->{_czarDb}->createProcessingRateData(
     109                    $stage,
     110                    $label,
     111                    $beginTime,
     112                    $endTime,
     113                    $interval,
     114                    \$gnuplotFile,
     115                    $isLog)) {
     116
     117            $gnuplotFiles{$stage} = $gnuplotFile;
     118
     119            if (!$first) { print GP ","; }
     120            print GP "'$gnuplotFile' using 2:xtic(1) title \"$stage\" ";
     121            $first = 0;
     122        }
     123    }
     124
     125    print GP ";\n";
     126    close GP;
     127}                                                   
     128###########################################################################
     129#
    57130# Plots a time series for all stages for this label
    58131#
    59132###########################################################################
    60133sub createTimeSeries {
    61     my ($self, $label, $selectedStage, $beginTime, $endTime, $isLog) = @_;
    62 
    63     my ($minX, $maxX, $minY, $maxY, $timeDiff);
    64     $minX = 999999999;     
    65     $maxX = -9999999999;
    66     $minY = 999999999;         
    67     $maxY = -99999999;
    68     $timeDiff = 0;
     134    my ($self, $label, $selectedStage, $beginTime, $endTime, $isLog, $showCleanup) = @_;
     135
     136    my $minX = 999999999;     
     137    my $maxX = -9999999999;
     138    my $timeDiff = 0;
    69139
    70140    my $stages = undef;                 
     
    85155                    \$minX,
    86156                    \$maxX,
    87                     \$minY,
    88                     \$maxY,
    89157                    \$timeDiff,
    90158                    \$gnuplotFile,
    91                     $isLog)) {
     159                    $isLog,
     160                    $showCleanup)) {
    92161
    93162            $gnuplotFiles{$stage} = $gnuplotFile;
     
    118187            $maxX,
    119188            $minX,
    120             $maxY,
    121             $minY,
    122189            $timeDiff,
    123190            $isLog);
     
    161228    close(GNUDAT);
    162229
    163     plotHistogram($self, $inputFile, $outputFile, $label, $beginTime, $endTime, $maxY);
     230    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     231    use FileHandle;
     232    GP->autoflush(1);
     233
     234    if ($maxY == 0) {$maxY = 1;}
     235    else {$maxY = $maxY*1.1;}
     236
     237    print GP
     238        "set term $self->{_outputFormat};" .
     239        "set output \"$outputFile\";" .
     240        "set title \"'$label', '$beginTime' to '$endTime'\";" .
     241        "set grid;" .
     242        "set boxwidth;" .
     243        "set yrange [\"0\":\"$maxY\"];" .
     244        "set style data histogram;" .
     245        "set style histogram rowstacked;" .
     246        "set style fill solid border -1;" .
     247        "set ylabel \"Exposures\";" .
     248        "set boxwidth 0.75;" .
     249        "plot '$inputFile' using 2:xtic(1) title \"Faults\" lt 1, '' using 3 title \"Processed\" lt 2, '' using 4 title \"Pending\" lt 7;" .
     250        "\n";
     251
     252    close GP;
    164253    unlink($inputFile);
    165254}
    166 
    167255
    168256###########################################################################
     
    239327###########################################################################
    240328sub plotTimeSeries {
    241     my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $maxY, $minY, $timeDiff, $isLog) = @_;
     329    my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $timeDiff, $isLog) = @_;
    242330
    243331    my $timeFormat = undef;
     
    346434    close GP;
    347435    unlink($gnuplotFile);
    348 }
    349 
    350 ###########################################################################
    351 #
    352 # Plots a histogram of processed stuff
    353 #
    354 ###########################################################################
    355 sub plotHistogram {
    356     my ($self, $inputFile, $outputFile, $label, $fromTime, $toTime, $maxY) = @_;
    357 
    358     open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
    359     use FileHandle;
    360     GP->autoflush(1);
    361 
    362     if ($maxY == 0) {$maxY = 1;}
    363     else {$maxY = $maxY*1.1;}
    364 
    365     print GP
    366         "set term $self->{_outputFormat};" .
    367         "set output \"$outputFile\";" .
    368         "set title \"'$label', '$fromTime' to '$toTime'\";" .
    369         "set grid;" .
    370         "set boxwidth;" .
    371         "set yrange [\"0\":\"$maxY\"];" .
    372         "set style data histogram;" .
    373         "set style histogram rowstacked;" .
    374         "set style fill solid border -1;" .
    375         "set ylabel \"Exposures\";" .
    376         "set boxwidth 0.75;" .
    377         "plot '$inputFile' using 2:xtic(1) title \"Faults\" lt 1, '' using 3 title \"Processed\" lt 2, '' using 4 title \"Pending\" lt 7;" .
    378         "\n";
    379 
    380     close GP;
    381436}
    382437
Note: See TracChangeset for help on using the changeset viewer.