- Timestamp:
- Jan 11, 2012, 11:19:21 PM (15 years ago)
- Location:
- branches/meh_branches/ppsub_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/jython/metrics.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppsub_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppsub_test/ippToPsps/jython/metrics.py
r32112 r33098 1 1 import math 2 import time 2 3 import logging 3 4 import smtplib 4 5 import sys 5 6 import os 6 7 from java.lang import Math 8 from org.apache.commons.math.special import Erf 7 import datetime 8 9 9 from xml.etree.ElementTree import ElementTree, Element, tostring 10 10 11 11 from pslogger import PSLogger 12 12 from ipptopspsdb import IppToPspsDb 13 from czardb import CzarDb 13 14 from gpc1db import Gpc1Db 14 15 … … 41 42 42 43 ''' 43 Prepares a string of the format: 44 45 n-processed(n-pending) 46 47 ''' 48 def prepareStr(masterList, prevList, thisList, FILE, name): 49 50 unsuccessful = list(set(prevList) - set(thisList)) 51 52 countTotal = len(masterList) 53 countSuccessful = len(thisList) 54 countUnsuccessful = len(unsuccessful) 55 56 str = "%d" % countSuccessful 57 if countUnsuccessful: str = str + "(%d)" % countUnsuccessful 58 59 print >> FILE, name, countSuccessful, countUnsuccessful, (countTotal - countSuccessful - countUnsuccessful) 60 #;sys.stdout.softspace=0; 61 return str 44 Formats an int to a string 45 ''' 46 def getIntAsString(value): 47 if value == 0: return "" 48 return str(value) 62 49 63 50 ''' 64 51 Prints (to the log) one row of data (one row being one batch-type) 65 52 ''' 66 def printTableRow(batchType): 67 68 allIDs = gpc1Db.getIDsInThisDVODbForThisStage(DVOLABEL, batchType) 69 processedIDs = ippToPspsDb.getProcessedIDs(batchType, EPOCH, DVOLABEL) 70 datastoreIDs = ippToPspsDb.getloadedToDatastoreIDs(batchType, EPOCH, DVOLABEL) 71 loadedToODMIDs = ippToPspsDb.getLoadedToODMIDs(batchType, EPOCH, DVOLABEL) 72 mergeWorthyIDs = ippToPspsDb.getMergeWothyIDs(batchType, EPOCH, DVOLABEL) 73 mergedIDs = ippToPspsDb.getMergedIDs(batchType, EPOCH, DVOLABEL) 53 def printTableRow(stages, batchType): 54 55 # get a master list of IDs in DVO for this batch type 56 if MINRA and MAXRA and MINDEC and MAXDEC: 57 allIDs = gpc1Db.getIDsInThisDVODbForThisStage(DVOLABEL, batchType, MINRA, MAXRA, MINDEC, MAXDEC) 58 else: 59 allIDs = gpc1Db.getIDsInThisDVODbForThisStage(DVOLABEL, batchType) 60 prevList = allIDs 61 numEverything = len(allIDs) 62 63 sys.stdout.write("| %2s |%6d " % (batchType, numEverything)) 74 64 75 65 tempFilename = batchType + '.dat' 76 66 DATFILE = open(tempFilename,'w') 77 prepareStr(allIDs, allIDs, allIDs, DATFILE, "inDVO"), 78 79 logger.info("| %2s | %-12d | %-12s | %-12s | %-12s | %-12s | %-12s | %-12s | %-19s |" % ( 80 batchType, 81 len(allIDs), 82 prepareStr(allIDs, allIDs, processedIDs, DATFILE, "processed"), 83 prepareStr(allIDs, processedIDs, datastoreIDs, DATFILE, "onDatastore"), 84 prepareStr(allIDs, datastoreIDs, loadedToODMIDs, DATFILE, "loadedToODM"), 85 prepareStr(allIDs, loadedToODMIDs, mergeWorthyIDs, DATFILE, "MergeWorthy"), 86 prepareStr(allIDs, mergeWorthyIDs, mergedIDs, DATFILE, "Merged"), 87 len(list(set(allIDs) - set(mergedIDs))), 88 ippToPspsDb.getTimeOfLastBatchPublished(batchType, EPOCH, DVOLABEL))) 89 67 print >> DATFILE, "DVO", numEverything, 0, 0 68 for stage in stages: 69 70 # get lists. Use unions with prev list to make sure the right stuff is included 71 success = list(set(ippToPspsDb.getStageIDs(batchType, EPOCH, DVOLABEL, stage, 1)) & set(prevList)) 72 fail = list(set(ippToPspsDb.getStageIDs(batchType, EPOCH, DVOLABEL, stage, -1)) & set(prevList) - set(success)) 73 pending = list(set(prevList) - set(success) - set(fail)) 74 75 # count stuff 76 numSuccess = len(success) 77 numFail = len(fail) 78 numPending = len(pending) 79 80 #if stage == 'loaded_to_datastore' and batchType == "P2": 81 # for n in fail: print n 82 83 str = "\033[1;34m%5s\033[1;m \033[1;32m%5s\033[1;m \033[1;31m%5s\033[1;m " % (getIntAsString(numPending), getIntAsString(numSuccess), getIntAsString(numFail)) 84 sys.stdout.write("|%-19s" % str) 85 86 prevList = success 87 print >> DATFILE, stage, numSuccess, numFail, numPending 88 89 czarDb.insertStats(stage, DVOLABEL, batchType, numPending, numSuccess, numFail) 90 91 if stage == 'processed': numPendingProcessed = numPending 92 93 sys.stdout.write("|\n") 90 94 plotMe(batchType, tempFilename) 91 95 DATFILE.close() 92 #os.remove(tempFilename) 96 97 return numPendingProcessed 98 99 ''' 100 Writes table separator 101 ''' 102 def writetableSeparator(colCount): 103 104 sys.stdout.write("+----+-------") 105 for i in range(0, colCount): sys.stdout.write("+-------------------") 106 sys.stdout.write("+\n") 107 108 ''' 109 Prints various timing stats for this batch type 110 ''' 111 def printStats(batchType): 112 113 rate = ippToPspsDb.countBatchesInLastPeriod(batchType, EPOCH, DVOLABEL, "1 HOUR") / 1.0 114 115 logger.info("| %2s | %16.1f | %13d | %17.1f | %16d | %14s |" % 116 (batchType, 117 rate, 118 ippToPspsDb.countBatchesInLastPeriod(batchType, EPOCH, DVOLABEL, "24 HOUR"), 119 ippToPspsDb.countBatchesInLastPeriod(batchType, EPOCH, DVOLABEL, "1 WEEK") / 7.0, 120 ippToPspsDb.getTotalDetectionsPublished(batchType, EPOCH, DVOLABEL), 121 ippToPspsDb.getTimeOfLastBatchPublished(batchType, EPOCH, DVOLABEL))) 122 123 return rate 93 124 94 125 ''' … … 97 128 if len(sys.argv) > 1: CONFIG = sys.argv[1] 98 129 else: 99 print "** Usage: " + sys.argv[0] + " <configPath> "130 print "** Usage: " + sys.argv[0] + " <configPath> [hours]" 100 131 sys.exit(1) 132 133 if len(sys.argv) > 2: 134 HOURS = float(sys.argv[2]) 135 SECONDS = HOURS * 60.0 * 60.0 136 else: 137 SECONDS = None 138 139 101 140 102 141 # open config file … … 107 146 logger.setup(configDoc, "metrics") 108 147 148 # create database objects 109 149 ippToPspsDb = IppToPspsDb(logger, configDoc) 150 czarDb = CzarDb(logger, configDoc) 110 151 gpc1Db = Gpc1Db(logger, configDoc) 111 152 … … 113 154 EPOCH = configDoc.find("options/epoch").text 114 155 115 logger.infoTitle("ippToPsps loading summary") 116 logger.infoPair("Loading epoch", EPOCH) 117 logger.infoPair("DVO label", DVOLABEL) 118 logger.info("") 119 logger.info("+------+----------------+----------------+----------------+----------------+----------------+----------------+----------------+----------------------+") 120 logger.info("| Type | Total in DVO | Processed | On datastore | Loaded to ODM | Merge-worthy | Merged | Total missing | Last published |") 121 logger.info("+------+----------------+----------------+----------------+----------------+----------------+----------------+----------------+----------------------+") 122 printTableRow("P2") 123 printTableRow("ST") 124 logger.info("+------+----------------+----------------+----------------+----------------+----------------+----------------+----------------+----------------------+") 125 126 127 156 while True: 157 158 logger.infoTitle("ippToPsps loading summary") 159 now = datetime.datetime.now() 160 logger.infoPair("Time now", now.strftime("%Y-%m-%d %H:%M:%S")) 161 logger.infoPair("Loading epoch", EPOCH) 162 logger.infoPair("DVO label", DVOLABEL) 163 164 # get equatorial coord constraints, if any 165 MINRA = None 166 MAXRA = None 167 MINDEC = None 168 MAXDEC = None 169 170 try: 171 MINRA = float(configDoc.find("dvo/minRA").text) 172 MAXRA = float(configDoc.find("dvo/maxRA").text) 173 MINDEC = float(configDoc.find("dvo/minDec").text) 174 MAXDEC = float(configDoc.find("dvo/maxDec").text) 175 logger.infoPair("Coordinates", "%.1f to %.1f RA, %.1f to %.1f Dec" % (MINRA, MAXRA, MINDEC, MAXDEC)) 176 except: 177 pass 178 179 180 logger.info("+----+------------------+---------------+-------------------+------------------+----------------+") 181 logger.info("|Type| batches per hour | last 24 hours | per day this week | total detections | last published |") 182 logger.info("+----+------------------+---------------+-------------------+------------------+----------------+") 183 rateP2 = printStats("P2") 184 rateST = printStats("ST") 185 logger.info("+----+------------------+---------------+-------------------+------------------+----------------+") 186 187 logger.info("") 188 189 stages = ippToPspsDb.getStages() 190 colCount = len(stages) 191 writetableSeparator(colCount) 192 sys.stdout.write("|Type| DVO ") 193 194 for stage in stages: sys.stdout.write("|%19s" % stage) 195 sys.stdout.write("|\n") 196 sys.stdout.write("| | ") 197 for stage in stages: sys.stdout.write("| Pend Succ Fail ") 198 sys.stdout.write("|\n") 199 writetableSeparator(colCount) 200 pendP2Processed = printTableRow(stages, "P2") 201 pendSTProcessed = printTableRow(stages, "ST") 202 writetableSeparator(colCount) 203 204 logger.info("") 205 try: logger.infoPair("Estimated time for P2s", "%.1f hours" % (pendP2Processed / rateP2)) 206 except: pass 207 try: logger.infoPair("Estimated time for STs", "%.1f hours" % (pendSTProcessed / rateST)) 208 except: pass 209 210 if SECONDS: 211 logger.infoPair("Waiting for", "%f hours" % HOURS) 212 time.sleep(SECONDS) 213 else: break 214 215
Note:
See TracChangeset
for help on using the changeset viewer.
