IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 15, 2011, 4:16:20 PM (15 years ago)
Author:
rhenders
Message:

all time-series plots now created at same time for speed

File:
1 edited

Legend:

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

    r31875 r31886  
    590590###########################################################################
    591591#
    592 # Gets time series data and stores it to temp file
     592# Gets time series data and stores it to temp files
    593593#
    594594###########################################################################
    595595sub createTimeSeriesData {
    596     my ($self, $label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff, $dataFile, $isLog, $showCleanup, $firstDeriv) = @_;
    597 
    598     my $query = $self->{_db}->prepare(<<SQL);
    599     SELECT
    600         MIN(processed)
     596    my ($self, $label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff, $linDataFile, $logDataFile, $ratDataFile) = @_;
     597
     598    # get total number of data points
     599    my $query = $self->{_db}->prepare(<<SQL);
     600    SELECT  COUNT(*)
    601601        FROM $stage
    602602        WHERE label LIKE '$label'
     
    605605
    606606    if (!$query->execute) {return 0;}
    607     my $minProcessed = scalar  $query->fetchrow_array();
    608     if (!defined $minProcessed) {return 0;}
    609 
     607    my ($count) = $query->fetchrow_array();
     608
     609    # decide on a number for the running mean for rate plots - use 10% of total data points
     610    my $range = int($count/10);
    610611    $self->getTimeMinMaxDiff($label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff);
    611 
     612    # grab all the data for the provided time range
    612613    $query = $self->{_db}->prepare(<<SQL);
    613614    SELECT
     
    621622    $query->execute;
    622623
     624    # set up Gnuplot datafiles
    623625    my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_gnuplot_".$label."_".$stage."_t.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
    624626    $tmpFile->unlink_on_destroy( 0 );
    625     ${$dataFile} = $tmpFile->filename;
    626     open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
     627    ${$linDataFile} = $tmpFile->filename;
     628    open (LINDAT, ">${$linDataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
     629
     630    $tmpFile = File::Temp->new( TEMPLATE => "czarplot_gnuplot_".$label."_".$stage."_t.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
     631    $tmpFile->unlink_on_destroy( 0 );
     632    ${$logDataFile} = $tmpFile->filename;
     633    open (LOGDAT, ">${$logDataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
     634
     635    $tmpFile = File::Temp->new( TEMPLATE => "czarplot_gnuplot_".$label."_".$stage."_t.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
     636    $tmpFile->unlink_on_destroy( 0 );
     637    ${$ratDataFile} = $tmpFile->filename;
     638    open (RATDAT, ">${$ratDataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
    627639
    628640    my $lastProcessed = -1;
     
    633645    my ($logProcessed, $logPending, $logFaults);
    634646    my ($derivProcessed, $derivPending, $derivFaults);
    635     my $timestamp = undef;
     647    my (@rateProcessed, @ratePending, @rateFaults);
     648    my $formattedTimestamp = undef;
     649    my $middleTime = undef;
     650    my $formattedMiddleTimestamp = undef;
    636651    my $positiveJump = 0;
     652    my @rateTimes;
     653    my $diffPending = 0;
     654    my $diffProcessed = 0;
     655    my $diffFaults = 0;
     656    my $lastDiffProcessed = 0;
     657    $derivProcessed = 0;
    637658
    638659    $linearProcessed = 0;
    639660    my $someData = 0;
     661    my $timeSep;
    640662    while (my @row = $query->fetchrow_array()) {
     663
    641664        my ($thisTimestamp, $thisPending, $thisFaults, $thisProcessed) = @row;
    642665
    643 
    644         # get first derivative values
     666        $formattedTimestamp = $self->getFormattedDate($thisTimestamp);
     667
     668        # if not first time in....
    645669        if (defined $lastTimestamp) {
    646670
    647             my $timeDiff = $self->diffTimesInSecs($thisTimestamp, $lastTimestamp);
    648                
    649             if ($thisProcessed >= $lastProcessed && $timeDiff){
    650                 $derivProcessed = abs($thisProcessed - $lastProcessed)/$timeDiff;
     671            # times
     672            $timeSep = $self->diffTimesInSecs($thisTimestamp, $lastTimestamp);
     673            $middleTime = $self->getMiddleTime($lastTimestamp, $thisTimestamp);
     674            $formattedMiddleTimestamp = $self->getFormattedDate($middleTime);
     675
     676            $diffPending = $thisPending - $lastPending;
     677            $diffFaults = $thisFaults - $lastFaults;
     678
     679            # we only count increases in processing - drops are due to cleanup etc
     680            if ($thisProcessed > $lastProcessed) {
     681
     682                $diffProcessed = ($thisProcessed - $lastProcessed) - $positiveJump;
     683                $linearProcessed = $linearProcessed + $diffProcessed;
    651684            }
    652             else {$derivProcessed = 0;}
     685            else {
     686           
     687                $diffProcessed = 0;
     688                $linearProcessed = $linearProcessed;
     689            }
     690
     691            # calculate first derivative in units of images per hour
     692            $derivPending = $diffPending/($timeSep/3600);
     693            $derivFaults = $diffFaults/($timeSep/3600);
     694            $derivProcessed = $diffProcessed/($timeSep/3600);
     695
     696            # look for large positive jumps in processed, most likely a label added, and store value to subtract from linear value below
     697            if ($derivProcessed > 1000) {
     698                $positiveJump = $thisProcessed - $lastProcessed;
     699            }
     700            else {
     701
     702                $positiveJump = 0;
     703            }
     704        }
     705        # first time in
     706        else {
     707       
    653708            $derivPending = 0;
    654709            $derivFaults = 0;
    655         #    $derivPending = abs($thisPending - $lastPending)/$timeDiff;   
    656         #    $derivFaults = abs($thisFaults - $lastFaults)/$timeDiff;   
    657 
    658             # look for large positive jumps in processed, most likely a label added, and store value to subtract from linear value below
    659             if ($derivProcessed > 0.3) {
    660 
    661                 $positiveJump = $thisProcessed - $lastProcessed;
    662                 #print "$derivProcessed at $thisTimestamp   $positiveJump\n";
     710            $derivProcessed = 0;
     711            $formattedMiddleTimestamp = $formattedTimestamp;
    663712        }
    664             else {
    665             $positiveJump = 0;
     713
     714        # deal with rate plot
     715        push(@ratePending, $derivPending);
     716        push(@rateFaults, $derivFaults);
     717        push(@rateProcessed, $derivProcessed);
     718        push(@rateTimes, $middleTime);
     719
     720        # get last few values
     721        my $size = scalar (@rateProcessed);
     722        if ($size > $range) {
     723
     724            my $counter = 0;
     725            my $oldTime;
     726            my $newTime = $rateTimes[$size-1];
     727            my $totalProcessed = 0;
     728            my $totalPending = 0;
     729            my $totalFaults = 0;
     730            for (my $i=$size-1; $i>=($size - $range); $i--) {
     731               
     732                $totalPending = $totalPending + $ratePending[$i];
     733                $totalFaults = $totalFaults + $rateFaults[$i];
     734                $totalProcessed = $totalProcessed + $rateProcessed[$i];
     735                $oldTime = $rateTimes[$i];
     736                $counter++;
    666737            }
     738
     739            my $meanPending = $totalPending / $counter;
     740            my $meanFaults = $totalFaults / $counter;
     741            my $meanProcessed = $totalProcessed / $counter;
     742
     743            my $formattedTimestamp = $self->getFormattedDate($self->getMiddleTime($oldTime, $newTime));
     744            print RATDAT "$formattedTimestamp $meanPending $meanFaults $meanProcessed\n";
    667745        }
    668         else {
    669        
    670             $derivProcessed = 0;
    671             $derivPending = 0;
    672             $derivFaults = 0;
    673         }
    674 
    675         # get linear values
    676         if ($showCleanup) {
    677        
    678             $linearProcessed = $thisProcessed - $minProcessed;
    679         }
    680         elsif($lastProcessed != -1 && $thisProcessed > $lastProcessed) {
    681            
    682             $linearProcessed = $linearProcessed + ($thisProcessed - $lastProcessed) - $positiveJump;
    683         }
     746
    684747        $linearPending = $thisPending;
    685748        $linearFaults = $thisFaults;
     
    694757
    695758        # print to data file
    696         $timestamp = $self->getFormattedDate($thisTimestamp);
    697         if ($firstDeriv) {print GNUDAT "$timestamp $derivPending $derivFaults $derivProcessed\n";}
    698         elsif($isLog) {print GNUDAT "$timestamp $logPending $logFaults $logProcessed\n";}
    699         else {print GNUDAT "$timestamp $linearPending $linearFaults $linearProcessed\n";}
     759        print LOGDAT "$formattedTimestamp $logPending $logFaults $logProcessed\n";
     760        print LINDAT "$formattedTimestamp $linearPending $linearFaults $linearProcessed\n";
    700761
    701762        if ($linearPending > 0 || $linearFaults > 0 || $linearProcessed > 0) {$someData = 1;}
     
    705766        $lastFaults = $thisFaults;
    706767        $lastTimestamp = $thisTimestamp;
    707     }
    708 
    709     close(GNUDAT) or print "* Problem closing gnuplot data file for plot for '$label' '$stage'\n";
    710 
    711     #return $someData;
     768        $lastDiffProcessed = $diffProcessed;
     769    }
     770
     771    close(LINDAT) or print "* Problem closing linear gnuplot data file for plot for '$label' '$stage'\n";
     772    close(LOGDAT) or print "* Problem closing log gnuplot data file for plot for '$label' '$stage'\n";
     773    close(RATDAT) or print "* Problem closing rate gnuplot data file for plot for '$label' '$stage'\n";
    712774}
    713775
     
    10171079#
    10181080# Deletes all but one row per interval from all tables for the provided date range
    1019 # TODO this is very clumsy, I just have time to thinmk of something more elegant
     1081# TODO this is very clumsy, I just don't have time to think of something more elegant
    10201082#
    10211083###########################################################################
Note: See TracChangeset for help on using the changeset viewer.