IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2012, 12:02:48 PM (14 years ago)
Author:
rhenders
Message:

Big changes to support a new Config class that encapuslates the xml config file

File:
1 edited

Legend:

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

    r33191 r33259  
    99from xml.etree.ElementTree import ElementTree, Element, tostring
    1010
     11from config import Config
    1112from pslogger import PSLogger
    1213from ipptopspsdb import IppToPspsDb
     
    1920def plotMe(batchType, file):
    2021
    21     OUTPUTFILE = "plots/" + DVOLABEL + "_" + batchType + ".png"
     22    OUTPUTFILE = "plots/" + config.dvoLabel + "_" + batchType + ".png"
    2223    f=os.popen('gnuplot', 'w')
    2324
     
    2930    print >> f, "set term " + TERM + "; \
    3031              set output \"" + OUTPUTFILE + "\"; \
    31               set title \"ippToPsps : " + batchType + " loading for " + DVOLABEL + "\"; \
     32              set title \"ippToPsps : " + batchType + " loading for " + config.dvoLabel + "\"; \
    3233              set boxwidth; \
    3334              set xtic rotate by -90 scale 0; \
     
    5455
    5556    # 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)
     57    allIDs = gpc1Db.getIDsInThisDVODbForThisStage(config.dvoLabel, batchType, config.minRa, config.maxRa, config.minDec, config.maxDec)
    6058    prevList = allIDs
    6159    numEverything = len(allIDs)
     
    6967
    7068       # 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))
     69       success = list(set(ippToPspsDb.getStageIDs(batchType, config.epoch, config.dvoLabel, stage, 1)) & set(prevList))
     70       fail = list(set(ippToPspsDb.getStageIDs(batchType, config.epoch, config.dvoLabel, stage, -1)) & set(prevList) - set(success))
    7371       pending = list(set(prevList) - set(success) - set(fail))
    7472
     
    8785       print >> DATFILE, stage, numSuccess, numFail, numPending
    8886
    89        czarDb.insertStats(stage, DVOLABEL, batchType, numPending, numSuccess, numFail)
     87       czarDb.insertStats(stage, config.dvoLabel, batchType, numPending, numSuccess, numFail)
    9088
    9189       if stage == 'processed': numPendingProcessed = numPending
    9290
    9391    sys.stdout.write("|\n")
    94     plotMe(batchType, tempFilename)
     92    #plotMe(batchType, tempFilename)
    9593    DATFILE.close()
    9694
     
    111109def printStats(batchType):
    112110
    113     rate = ippToPspsDb.countBatchesInLastPeriod(batchType, EPOCH, DVOLABEL, "1 HOUR") / 1.0
     111    rate = ippToPspsDb.countBatchesInLastPeriod(batchType, config.epoch, config.dvoLabel, "1 HOUR") / 1.0
    114112
    115113    logger.info("| %2s | %16.1f | %13d | %17.1f | %16d | %14s |" %
    116114            (batchType,
    117115             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)))
     116             ippToPspsDb.countBatchesInLastPeriod(batchType, config.epoch, config.dvoLabel, "24 HOUR"),
     117             ippToPspsDb.countBatchesInLastPeriod(batchType, config.epoch, config.dvoLabel, "1 WEEK") / 7.0,
     118             ippToPspsDb.getTotalDetectionsPublished(batchType, config.epoch, config.dvoLabel),
     119             ippToPspsDb.getTimeOfLastBatchPublished(batchType, config.epoch, config.dvoLabel)))
    122120
    123121    return rate
     
    126124Start of program.
    127125'''
    128 if len(sys.argv) > 1: CONFIG  = sys.argv[1]
     126if len(sys.argv) > 1: CONFIGPATH  = sys.argv[1]
    129127else:
    130128    print "** Usage: " + sys.argv[0] + " <configPath> [hours]"
     
    137135    SECONDS = None
    138136
    139 
    140 
    141 # open config file
    142 configDoc = ElementTree(file=CONFIG)
    143 
    144 logging.setLoggerClass(PSLogger)
    145 logger = logging.getLogger("metrics")
    146 logger.setup(configDoc, "metrics")
    147 
    148 # create database objects
    149 ippToPspsDb = IppToPspsDb(logger, configDoc)
    150 czarDb = CzarDb(logger, configDoc)
    151 gpc1Db = Gpc1Db(logger, configDoc)
    152 
    153 DVOLABEL = configDoc.find("dvo/gpc1Label").text
    154 EPOCH = configDoc.find("options/epoch").text
     137# create objects
     138config = Config(CONFIGPATH)
     139logger = config.getLogger("metrics")
     140ippToPspsDb = IppToPspsDb(logger, config)
     141czarDb = CzarDb(logger, config)
     142gpc1Db = Gpc1Db(logger, config)
    155143
    156144while True:
     
    159147    now = datetime.datetime.now()
    160148    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     try:
    166         MINRA = float(configDoc.find("dvo/minRA").text)
    167         MAXRA = float(configDoc.find("dvo/maxRA").text)
    168         MINDEC = float(configDoc.find("dvo/minDec").text)
    169         MAXDEC = float(configDoc.find("dvo/maxDec").text)
    170     except:
    171         MINRA = 0.0
    172         MAXRA = 360.0
    173         MINDEC = -30.0
    174         MAXDEC = 90.0
    175 
    176     logger.infoPair("RA limits", "%.1f to %.1f" % (MINRA, MAXRA))
    177     logger.infoPair("Dec limits", "%.1f to %.1f" % (MINDEC, MAXDEC))
     149    logger.infoPair("Loading epoch", config.epoch)
     150    logger.infoPair("DVO label", config.dvoLabel)
     151    config.printBoxCoords()
    178152
    179153    logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
Note: See TracChangeset for help on using the changeset viewer.