IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 19, 2012, 5:24:19 PM (14 years ago)
Author:
mhuber
Message:

merging latest r34040 trunk changes to branch

Location:
branches/meh_branches/ppstack_test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/ippToPsps/jython/metrics.py

    r33415 r34041  
    99from ipptopsps import IppToPsps
    1010from czardb import CzarDb
    11 from gpc1db import Gpc1Db
     11from plot import Plot
    1212
    1313'''
     
    2424        if len(sys.argv) > 2: self.parsePollTimeArg(sys.argv[2])
    2525   
    26         # create database objects
    2726        self.czarDb = CzarDb(self.logger, self.config)
    28         self.gpc1Db = Gpc1Db(self.logger, self.config)
     27        self.plot = Plot(self.logger, self.config, self.ippToPspsDb)
    2928   
    3029    '''
     
    3837            now = datetime.datetime.now()
    3938            self.logger.infoPair("Time now", now.strftime("%Y-%m-%d %H:%M:%S"))
     39            self.logger.infoPair("Config", self.config.name)
    4040            self.logger.infoPair("Loading epoch", self.config.epoch)
    4141            self.logger.infoPair("DVO label", self.config.dvoLabel)
     
    4343       
    4444            self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
    45             self.logger.info("|Type| batches per hour | last 24 hours | per day this week | total detections | last published |")
     45            self.logger.info("|Type| batches per hour | last 24 hours | per day this week | detections/batch | last published |")
    4646            self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
    4747            rateP2 = self.printStats("P2")
    4848            rateST = self.printStats("ST")
     49            rateOB = self.printStats("OB")
    4950            self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
    5051       
     
    5455            colCount = len(stages)
    5556            self.writeTableSeparator(colCount)
    56             sys.stdout.write("|Type|  DVO  ")
     57            sys.stdout.write("|Type")
    5758       
    5859            for stage in stages: sys.stdout.write("|%19s" % stage)
    5960            sys.stdout.write("|\n")
    60             sys.stdout.write("|    |       ")
     61            sys.stdout.write("|    ")
    6162            for stage in stages: sys.stdout.write("| Pend  Succ  Fail  ")
    6263            sys.stdout.write("|\n")
     
    6465            pendP2Processed = self.printTableRow(stages, "P2")
    6566            pendSTProcessed = self.printTableRow(stages, "ST")
     67            pendOBProcessed = self.printTableRow(stages, "OB")
    6668            self.writeTableSeparator(colCount)
    6769
     
    7173            try: self.logger.infoPair("Estimated time for STs", "%.1f hours" % (pendSTProcessed / rateST))
    7274            except: pass
     75            try: self.logger.infoPair("Estimated time for OBs", "%.1f hours" % (pendOBProcessed / rateOB))
     76            except: pass
    7377       
    7478            self.checkClientStatus()
     79
     80            # create a density plot of pending stuff for czartool
     81            self.plot.createDensityPlot("P2", True)
     82            self.plot.createDensityPlot("ST", True)
     83            self.plot.createDensityPlot("OB", True)
     84
     85            # some clean-up before going to sleep
     86            self.ippToPspsDb.purgeDeadClients()
    7587            if not self.waitForPollTime(): break
    7688
     
    88100    def printTableRow(self, stages, batchType):
    89101   
    90         # get a master list of IDs in DVO for this batch type
    91         #allIDs = self.gpc1Db.getIDsInThisDVODbForThisStage(self.config.dvoLabel, batchType, self.config.minRa, self.config.maxRa, self.config.minDec, self.config.maxDec)
    92         allIDs = self.gpc1Db.getIDsInThisDVODbForThisStage(self.config.dvoLabel, batchType)
    93         prevList = allIDs
    94         numEverything = len(allIDs)
    95    
    96         sys.stdout.write("| %2s |%6d " % (batchType, numEverything))
    97    
    98         tempFilename = batchType + '.dat'
    99         DATFILE = open(tempFilename,'w')
    100         print >> DATFILE, "DVO", numEverything, 0, 0
     102        pending = self.ippToPspsDb.getPendingIds(batchType)
     103
     104        sys.stdout.write("| %2s " % (batchType))
     105   
     106        firstStage = True
    101107        for stage in stages:
    102108   
    103109           # get lists. Use unions with prev list to make sure the right stuff is included
    104            success = list(set(self.ippToPspsDb.getStageIDs(batchType, self.config.epoch, self.config.dvoLabel, stage, 1)) & set(prevList))
    105            fail = list(set(self.ippToPspsDb.getStageIDs(batchType, self.config.epoch, self.config.dvoLabel, stage, -1)) & set(prevList) - set(success))
    106            pending = list(set(prevList) - set(success) - set(fail))
     110           if firstStage:
     111               success = self.ippToPspsDb.getStageIDs(batchType, stage, 1)
     112               fail = list(set(self.ippToPspsDb.getStageIDs(batchType, stage, -1)) - set(success))
     113           else:
     114               success = list(set(self.ippToPspsDb.getStageIDs(batchType, stage, 1)) & set(prevList))
     115               fail = list(set(self.ippToPspsDb.getStageIDs(batchType, stage, -1)) & set(prevList) - set(success))
     116               pending = list(set(prevList) - set(success) - set(fail))
    107117   
    108118           # count stuff
     
    114124           #    for n in fail: print n
    115125   
    116            str = "\033[1;34m%5s\033[1;m \033[1;32m%5s\033[1;m \033[1;31m%5s\033[1;m  " % (self.getIntAsString(numPending), self.getIntAsString(numSuccess), self.getIntAsString(numFail))
     126           str = "\033[1;34m%5s\033[1;m \033[1;32m%5s\033[1;m \033[1;31m%5s\033[1;m  " % (
     127                   self.getIntAsString(numPending),
     128                   self.getIntAsString(numSuccess),
     129                   self.getIntAsString(numFail))
    117130           sys.stdout.write("|%-19s" % str)
    118131   
    119132           prevList = success
    120            print >> DATFILE, stage, numSuccess, numFail, numPending
    121    
    122            self.czarDb.insertStats(stage, self.config.dvoLabel, batchType, numPending, numSuccess, numFail)
     133   
     134           self.czarDb.insertStats(stage, self.config.name, batchType, numPending, numSuccess, numFail)
    123135   
    124136           if stage == 'processed': numPendingProcessed = numPending
    125137   
     138           firstStage = False
     139
    126140        sys.stdout.write("|\n")
    127         DATFILE.close()
    128141   
    129142        return numPendingProcessed
     
    134147    def writeTableSeparator(self, colCount):
    135148   
    136         sys.stdout.write("+----+-------")
     149        sys.stdout.write("+----")
    137150        for i in range(0, colCount): sys.stdout.write("+-------------------")
    138151        sys.stdout.write("+\n")
    139    
     152   
     153    '''
     154    Safe divide function
     155    '''
     156    def divide(self, num, denom):
     157        if denom == 0: return 0
     158        else: return num / denom
     159
    140160    '''
    141161    Prints various timing stats for this batch type
     
    143163    def printStats(self, batchType):
    144164   
    145         rate = self.ippToPspsDb.countBatchesInLastPeriod(batchType, self.config.epoch, self.config.dvoLabel, "1 HOUR") / 1.0
    146    
     165        rate = self.ippToPspsDb.countBatches(batchType, "1 HOUR") / 1.0
     166   
     167
     168        batchesInLast24Hours = self.ippToPspsDb.countBatches(batchType, "24 HOUR")
     169        detectionsInLast24Hours = self.ippToPspsDb.getTotalDetectionsPublished(batchType, "24 HOUR")
     170
    147171        self.logger.info("| %2s | %16.1f | %13d | %17.1f | %16d | %14s |" %
    148172                (batchType,
    149173                 rate,
    150                  self.ippToPspsDb.countBatchesInLastPeriod(batchType, self.config.epoch, self.config.dvoLabel, "24 HOUR"),
    151                  self.ippToPspsDb.countBatchesInLastPeriod(batchType, self.config.epoch, self.config.dvoLabel, "1 WEEK") / 7.0,
    152                  self.ippToPspsDb.getTotalDetectionsPublished(batchType, self.config.epoch, self.config.dvoLabel),
    153                  self.ippToPspsDb.getTimeOfLastBatchPublished(batchType, self.config.epoch, self.config.dvoLabel)))
     174                 batchesInLast24Hours,
     175                 self.ippToPspsDb.countBatches(batchType, "1 WEEK") / 7.0,
     176                 self.divide(detectionsInLast24Hours, batchesInLast24Hours),
     177                 self.ippToPspsDb.getTimeOfLastBatchPublished(batchType)))
    154178   
    155179        return rate
     
    160184    '''
    161185    def printUsage(self):
    162         super(Metrics, self).printUsage()
    163         print " [hours]"
     186        super(Metrics, self).printUsage("[<hours>]")
    164187
    165188
     
    168191Start of program.
    169192'''
    170 metrics = Metrics(sys.argv)
    171 metrics.run()
    172 metrics.exitProgram("finished")
    173 
    174 
    175 
     193try:
     194    metrics = Metrics(sys.argv)
     195    metrics.run()
     196    metrics.exitProgram("completed")
     197except: pass
     198
     199
     200
Note: See TracChangeset for help on using the changeset viewer.