IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32354 for trunk/ippToPsps


Ignore:
Timestamp:
Sep 6, 2011, 1:37:06 PM (15 years ago)
Author:
rhenders
Message:

now reporting batches-per-hour and last P2 and St batch published; much cleaner code to determine figures and report them in a more readable way (including colour)

File:
1 edited

Legend:

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

    r32294 r32354  
    44import sys
    55import os
     6import datetime
    67
    78from xml.etree.ElementTree import ElementTree, Element, tostring
     
    3940
    4041'''
    41 Prepares a string of the format:
    42 
    43 n-processed(n-pending)
    44 
     42Formats an int to a string
    4543'''
    46 def prepareStr(masterList, prevList, thisList, FILE, name):
    47 
    48     unsuccessful = list(set(prevList) - set(thisList))
    49 
    50     countTotal = len(masterList)
    51     countSuccessful = len(thisList)
    52     countUnsuccessful = len(unsuccessful)
    53 
    54     str = "%d" % countSuccessful
    55     if countUnsuccessful: str = str + "(%d)" % countUnsuccessful
    56 
    57     print >> FILE, name, countSuccessful, countUnsuccessful, (countTotal - countSuccessful - countUnsuccessful)
    58     #;sys.stdout.softspace=0;
    59     return str
     44def getIntAsString(value):
     45    if value == 0: return ""
     46    return str(value)
    6047
    6148'''
    6249Prints (to the log) one row of data (one row being one batch-type)
    6350'''
    64 def printTableRow(batchType):
     51def printTableRow(stages, batchType):
    6552
     53    # get a master list of IDs in DVO for this batch type
    6654    allIDs = gpc1Db.getIDsInThisDVODbForThisStage(DVOLABEL, batchType)
    67     processedIDs = ippToPspsDb.getProcessedIDs(batchType, EPOCH, DVOLABEL)
    68     datastoreIDs = ippToPspsDb.getloadedToDatastoreIDs(batchType, EPOCH, DVOLABEL)
    69     loadedToODMIDs = ippToPspsDb.getLoadedToODMIDs(batchType, EPOCH, DVOLABEL)
    70     mergeWorthyIDs = ippToPspsDb.getMergeWorthyIDs(batchType, EPOCH, DVOLABEL)
    71     mergedIDs = ippToPspsDb.getMergedIDs(batchType, EPOCH, DVOLABEL)
     55    prevList = allIDs
     56    numEverything = len(allIDs)
     57
     58    sys.stdout.write("| %2s |%6d " % (batchType, numEverything))
    7259
    7360    tempFilename = batchType + '.dat'
    7461    DATFILE = open(tempFilename,'w')
    75     prepareStr(allIDs, allIDs, allIDs, DATFILE, "inDVO"),
     62    print >> DATFILE, "DVO", numEverything, 0, 0
     63    for stage in stages:
    7664
    77     logger.info("|  %2s  |  %-12d  |  %-12s  |  %-12s  |  %-12s  |  %-12s  |  %-12s  |  %-12s  |  %-19s |" % (
    78                 batchType,
    79                 len(allIDs),
    80                 prepareStr(allIDs, allIDs, processedIDs, DATFILE, "processed"),
    81                 prepareStr(allIDs, processedIDs, datastoreIDs, DATFILE, "onDatastore"),
    82                 prepareStr(allIDs, datastoreIDs, loadedToODMIDs, DATFILE, "loadedToODM"),
    83                 prepareStr(allIDs, loadedToODMIDs, mergeWorthyIDs, DATFILE, "MergeWorthy"),
    84                 prepareStr(allIDs, mergeWorthyIDs, mergedIDs, DATFILE, "Merged"),
    85                 len(list(set(allIDs) - set(mergedIDs))),
    86                 ippToPspsDb.getTimeOfLastBatchPublished(batchType, EPOCH, DVOLABEL)))
     65       # get lists. Use unions with prev list to make sure the right stuff is included
     66       success = list(set(ippToPspsDb.getStageIDs(batchType, EPOCH, DVOLABEL, stage, 1)) & set(prevList))
     67       fail = list(set(ippToPspsDb.getStageIDs(batchType, EPOCH, DVOLABEL, stage, -1)) & set(prevList) - set(success))
     68       pending = list(set(prevList) - set(success) - set(fail))
    8769
     70       # count stuff
     71       numSuccess = len(success)
     72       numFail = len(fail)
     73       numPending = len(pending)
     74
     75       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))
     76       sys.stdout.write("|%-19s" % str)
     77
     78       prevList = success
     79       print >> DATFILE, stage, numSuccess, numFail, numPending
     80
     81    sys.stdout.write("|\n")
    8882    plotMe(batchType, tempFilename)
    8983    DATFILE.close()
    90     #os.remove(tempFilename)
    9184
    92     unprocessedIDs = list(set(allIDs) - set(processedIDs))
    93     if len(unprocessedIDs) > 0:
    94         UNPROCESSEDFILE = open("unprocessed" + DVOLABEL + "_" + batchType,'w')
    95         for id in unprocessedIDs: print >> UNPROCESSEDFILE, id
    96         UNPROCESSEDFILE.close()
     85'''
     86Writes table separator
     87'''
     88def writetableSeparator(colCount):
     89
     90    sys.stdout.write("+----+-------")
     91    for i in range(0, colCount): sys.stdout.write("+-------------------")
     92    sys.stdout.write("+\n")
    9793
    9894'''
     
    10399    print "** Usage: " + sys.argv[0] + " <configPath>"
    104100    sys.exit(1)
     101
     102now = datetime.datetime.now()
    105103
    106104# open config file
     
    118116
    119117logger.infoTitle("ippToPsps loading summary")
     118logger.infoPair("Time now", now.strftime("%Y-%m-%d %H:%M:%S"))
    120119logger.infoPair("Loading epoch", EPOCH)
    121120logger.infoPair("DVO label", DVOLABEL)
     121logger.infoPair("P2 batches per hour", "%.1f" % ippToPspsDb.getBatchesPerHour("P2", EPOCH, DVOLABEL, 2))
     122logger.infoPair("ST batches per hour", "%.1f" % ippToPspsDb.getBatchesPerHour("ST", EPOCH, DVOLABEL, 2))
     123logger.infoPair("Last P2 batch published", ippToPspsDb.getTimeOfLastBatchPublished("P2", EPOCH, DVOLABEL))
     124logger.infoPair("Last ST batch published", ippToPspsDb.getTimeOfLastBatchPublished("ST", EPOCH, DVOLABEL))
    122125logger.info("")
    123 logger.info("+------+----------------+----------------+----------------+----------------+----------------+----------------+----------------+----------------------+")
    124 logger.info("| Type |  Total in DVO  |   Processed    |  On datastore  | Loaded to ODM  |  Merge-worthy  |     Merged     |  Total missing |    Last published    |")
    125 logger.info("+------+----------------+----------------+----------------+----------------+----------------+----------------+----------------+----------------------+")
    126 printTableRow("P2")
    127 printTableRow("ST")
    128 logger.info("+------+----------------+----------------+----------------+----------------+----------------+----------------+----------------+----------------------+")
    129126
     127stages = ippToPspsDb.getStages()
     128colCount = len(stages)
     129writetableSeparator(colCount)
     130sys.stdout.write("|Type|  DVO  ")
     131for stage in stages: sys.stdout.write("|%19s" % stage)
     132sys.stdout.write("|\n")
     133sys.stdout.write("|    |       ")
     134for stage in stages: sys.stdout.write("| Pend  Succ  Fail  ")
     135sys.stdout.write("|\n")
     136writetableSeparator(colCount)
     137printTableRow(stages, "P2")
     138printTableRow(stages, "ST")
     139writetableSeparator(colCount)
    130140
    131 
Note: See TracChangeset for help on using the changeset viewer.