- Timestamp:
- Jun 19, 2012, 5:24:19 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/jython/metrics.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/ippToPsps/jython/metrics.py
r33415 r34041 9 9 from ipptopsps import IppToPsps 10 10 from czardb import CzarDb 11 from gpc1db import Gpc1Db11 from plot import Plot 12 12 13 13 ''' … … 24 24 if len(sys.argv) > 2: self.parsePollTimeArg(sys.argv[2]) 25 25 26 # create database objects27 26 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) 29 28 30 29 ''' … … 38 37 now = datetime.datetime.now() 39 38 self.logger.infoPair("Time now", now.strftime("%Y-%m-%d %H:%M:%S")) 39 self.logger.infoPair("Config", self.config.name) 40 40 self.logger.infoPair("Loading epoch", self.config.epoch) 41 41 self.logger.infoPair("DVO label", self.config.dvoLabel) … … 43 43 44 44 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 |") 46 46 self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+") 47 47 rateP2 = self.printStats("P2") 48 48 rateST = self.printStats("ST") 49 rateOB = self.printStats("OB") 49 50 self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+") 50 51 … … 54 55 colCount = len(stages) 55 56 self.writeTableSeparator(colCount) 56 sys.stdout.write("|Type | DVO")57 sys.stdout.write("|Type") 57 58 58 59 for stage in stages: sys.stdout.write("|%19s" % stage) 59 60 sys.stdout.write("|\n") 60 sys.stdout.write("| |")61 sys.stdout.write("| ") 61 62 for stage in stages: sys.stdout.write("| Pend Succ Fail ") 62 63 sys.stdout.write("|\n") … … 64 65 pendP2Processed = self.printTableRow(stages, "P2") 65 66 pendSTProcessed = self.printTableRow(stages, "ST") 67 pendOBProcessed = self.printTableRow(stages, "OB") 66 68 self.writeTableSeparator(colCount) 67 69 … … 71 73 try: self.logger.infoPair("Estimated time for STs", "%.1f hours" % (pendSTProcessed / rateST)) 72 74 except: pass 75 try: self.logger.infoPair("Estimated time for OBs", "%.1f hours" % (pendOBProcessed / rateOB)) 76 except: pass 73 77 74 78 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() 75 87 if not self.waitForPollTime(): break 76 88 … … 88 100 def printTableRow(self, stages, batchType): 89 101 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 101 107 for stage in stages: 102 108 103 109 # 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)) 107 117 108 118 # count stuff … … 114 124 # for n in fail: print n 115 125 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)) 117 130 sys.stdout.write("|%-19s" % str) 118 131 119 132 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) 123 135 124 136 if stage == 'processed': numPendingProcessed = numPending 125 137 138 firstStage = False 139 126 140 sys.stdout.write("|\n") 127 DATFILE.close()128 141 129 142 return numPendingProcessed … … 134 147 def writeTableSeparator(self, colCount): 135 148 136 sys.stdout.write("+---- +-------")149 sys.stdout.write("+----") 137 150 for i in range(0, colCount): sys.stdout.write("+-------------------") 138 151 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 140 160 ''' 141 161 Prints various timing stats for this batch type … … 143 163 def printStats(self, batchType): 144 164 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 147 171 self.logger.info("| %2s | %16.1f | %13d | %17.1f | %16d | %14s |" % 148 172 (batchType, 149 173 rate, 150 self.ippToPspsDb.countBatchesInLastPeriod(batchType, self.config.epoch, self.config.dvoLabel, "24 HOUR"),151 self.ippToPspsDb.countBatches InLastPeriod(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))) 154 178 155 179 return rate … … 160 184 ''' 161 185 def printUsage(self): 162 super(Metrics, self).printUsage() 163 print " [hours]" 186 super(Metrics, self).printUsage("[<hours>]") 164 187 165 188 … … 168 191 Start of program. 169 192 ''' 170 metrics = Metrics(sys.argv) 171 metrics.run() 172 metrics.exitProgram("finished") 173 174 175 193 try: 194 metrics = Metrics(sys.argv) 195 metrics.run() 196 metrics.exitProgram("completed") 197 except: pass 198 199 200
Note:
See TracChangeset
for help on using the changeset viewer.
