IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33494 for trunk/ippToPsps


Ignore:
Timestamp:
Mar 13, 2012, 10:08:18 AM (14 years ago)
Author:
rhenders
Message:

changes to how ids are returns from gpc1db method; now printing a value of detections per batch in last 24 hours; using new base-class printUsage() method; added a safe divide method to avoid divide-by-zero issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/metrics.py

    r33351 r33494  
    1010from czardb import CzarDb
    1111from gpc1db import Gpc1Db
     12from plot import Plot
    1213
    1314'''
     
    2728        self.czarDb = CzarDb(self.logger, self.config)
    2829        self.gpc1Db = Gpc1Db(self.logger, self.config)
     30        self.plot = Plot(self.logger, self.config, self.ippToPspsDb)
    2931   
    3032    '''
     
    4345       
    4446            self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
    45             self.logger.info("|Type| batches per hour | last 24 hours | per day this week | total detections | last published |")
     47            self.logger.info("|Type| batches per hour | last 24 hours | per day this week | detections/batch | last published |")
    4648            self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
    4749            rateP2 = self.printStats("P2")
     
    7375       
    7476            self.checkClientStatus()
     77
     78            # create a density plot of pending stuff for czartool
     79            self.plot.createDensityPlot("P2", True)
     80            self.plot.createDensityPlot("ST", True)
     81
    7582            if not self.waitForPollTime(): break
    7683
     
    8996   
    9097        # 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)
     98        rows = self.gpc1Db.getItemsInThisDVODbForThisStage(self.config.dvoLabel,
     99                batchType,
     100                self.config.minRa,
     101                self.config.maxRa,
     102                self.config.minDec,
     103                self.config.maxDec)
     104
     105        # we only want to IDs
     106        allIDs = []
     107        for row in rows:
     108            try: allIDs.append(row[0])
     109            except: pass
     110
     111        #allIDs = self.ippToPspsDb.getPendingIdsForThisConfig(self.config.name)
     112
    93113        prevList = allIDs
    94114        numEverything = len(allIDs)
     
    97117   
    98118        tempFilename = batchType + '.dat'
    99         DATFILE = open(tempFilename,'w')
    100         print >> DATFILE, "DVO", numEverything, 0, 0
    101119        for stage in stages:
    102120   
     
    114132           #    for n in fail: print n
    115133   
    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))
     134           str = "\033[1;34m%5s\033[1;m \033[1;32m%5s\033[1;m \033[1;31m%5s\033[1;m  " % (
     135                   self.getIntAsString(numPending),
     136                   self.getIntAsString(numSuccess),
     137                   self.getIntAsString(numFail))
    117138           sys.stdout.write("|%-19s" % str)
    118139   
    119140           prevList = success
    120            print >> DATFILE, stage, numSuccess, numFail, numPending
    121141   
    122142           self.czarDb.insertStats(stage, self.config.dvoLabel, batchType, numPending, numSuccess, numFail)
     
    125145   
    126146        sys.stdout.write("|\n")
    127         DATFILE.close()
    128147   
    129148        return numPendingProcessed
     
    137156        for i in range(0, colCount): sys.stdout.write("+-------------------")
    138157        sys.stdout.write("+\n")
    139    
     158   
     159    '''
     160    Safe divide function
     161    '''
     162    def divide(self, num, denom):
     163        if denom == 0: return 0
     164        else: return num / denom
     165
    140166    '''
    141167    Prints various timing stats for this batch type
     
    143169    def printStats(self, batchType):
    144170   
    145         rate = self.ippToPspsDb.countBatchesInLastPeriod(batchType, self.config.epoch, self.config.dvoLabel, "1 HOUR") / 1.0
    146    
     171        rate = self.ippToPspsDb.countBatches(batchType, self.config.epoch, self.config.dvoLabel, "1 HOUR") / 1.0
     172   
     173
     174        batchesInLast24Hours = self.ippToPspsDb.countBatches(batchType, self.config.epoch, self.config.dvoLabel, "24 HOUR")
     175        detectionsInLast24Hours = self.ippToPspsDb.getTotalDetectionsPublished(batchType, self.config.epoch, self.config.dvoLabel, "24 HOUR")
     176
    147177        self.logger.info("| %2s | %16.1f | %13d | %17.1f | %16d | %14s |" %
    148178                (batchType,
    149179                 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),
     180                 batchesInLast24Hours,
     181                 self.ippToPspsDb.countBatches(batchType, self.config.epoch, self.config.dvoLabel, "1 WEEK") / 7.0,
     182                 self.divide(detectionsInLast24Hours, batchesInLast24Hours),
    153183                 self.ippToPspsDb.getTimeOfLastBatchPublished(batchType, self.config.epoch, self.config.dvoLabel)))
    154184   
     
    160190    '''
    161191    def printUsage(self):
    162         super(Metrics, self).printUsage()
    163         print " [hours]"
     192        super(Metrics, self).printUsage("[<hours>]")
    164193
    165194
Note: See TracChangeset for help on using the changeset viewer.