IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32777


Ignore:
Timestamp:
Nov 23, 2011, 8:49:00 AM (15 years ago)
Author:
rhenders
Message:

added a timer so program will run in a loop

File:
1 edited

Legend:

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

    r32587 r32777  
    11import math
     2import time
    23import logging
    34import smtplib
     
    1011from pslogger import PSLogger
    1112from ipptopspsdb import IppToPspsDb
     13from czardb import CzarDb
    1214from gpc1db import Gpc1Db
    1315
     
    7678       numPending = len(pending)
    7779
    78        #if stage == 'merge_worthy' and batchType == "P2":
    79        #    for n in pending: print n
     80       #if stage == 'loaded_to_datastore' and batchType == "P2":
     81       #    for n in fail: print n
    8082
    8183       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))
     
    8486       prevList = success
    8587       print >> DATFILE, stage, numSuccess, numFail, numPending
     88
     89       czarDb.insertStats(stage, DVOLABEL, batchType, numPending, numSuccess, numFail)
    8690
    8791       if stage == 'processed': numPendingProcessed = numPending
     
    124128if len(sys.argv) > 1: CONFIG  = sys.argv[1]
    125129else:
    126     print "** Usage: " + sys.argv[0] + " <configPath>"
     130    print "** Usage: " + sys.argv[0] + " <configPath> [hours]"
    127131    sys.exit(1)
    128132
    129 now = datetime.datetime.now()
     133if len(sys.argv) > 2:
     134    HOURS = float(sys.argv[2])
     135    SECONDS = HOURS * 60.0 * 60.0
     136else:
     137    SECONDS = None
     138
     139
    130140
    131141# open config file
     
    136146logger.setup(configDoc, "metrics")
    137147
     148# create database objects
    138149ippToPspsDb = IppToPspsDb(logger, configDoc)
     150czarDb = CzarDb(logger, configDoc)
    139151gpc1Db = Gpc1Db(logger, configDoc)
    140 
    141 MINRA = None
    142 MAXRA = None
    143 MINDEC = None
    144 MAXDEC = None
    145152
    146153DVOLABEL = configDoc.find("dvo/gpc1Label").text
    147154EPOCH = configDoc.find("options/epoch").text
    148155
    149 logger.infoTitle("ippToPsps loading summary")
    150 logger.infoPair("Time now", now.strftime("%Y-%m-%d %H:%M:%S"))
    151 logger.infoPair("Loading epoch", EPOCH)
    152 logger.infoPair("DVO label", DVOLABEL)
    153 
    154 try:
    155     MINRA = float(configDoc.find("dvo/minRA").text)
    156     MAXRA = float(configDoc.find("dvo/maxRA").text)
    157     MINDEC = float(configDoc.find("dvo/minDec").text)
    158     MAXDEC = float(configDoc.find("dvo/maxDec").text)
    159     logger.infoPair("Coordinates", "%.1f to %.1f RA, %.1f to %.1f Dec" % (MINRA, MAXRA, MINDEC, MAXDEC))
    160 except:
    161     pass
     156while 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
    162178   
    163179
    164 logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
    165 logger.info("|Type| batches per hour | last 24 hours | per day this week | total detections | last published |")
    166 logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
    167 rateP2 = printStats("P2")
    168 rateST = printStats("ST")
    169 logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
    170 
    171 logger.info("")
    172 
    173 stages = ippToPspsDb.getStages()
    174 colCount = len(stages)
    175 writetableSeparator(colCount)
    176 sys.stdout.write("|Type|  DVO  ")
    177 for stage in stages: sys.stdout.write("|%19s" % stage)
    178 sys.stdout.write("|\n")
    179 sys.stdout.write("|    |       ")
    180 for stage in stages: sys.stdout.write("| Pend  Succ  Fail  ")
    181 sys.stdout.write("|\n")
    182 writetableSeparator(colCount)
    183 pendP2Processed = printTableRow(stages, "P2")
    184 pendSTProcessed = printTableRow(stages, "ST")
    185 writetableSeparator(colCount)
    186 
    187 logger.info("")
    188 try: logger.infoPair("Estimated time for P2s", "%.1f hours" % (pendP2Processed / rateP2))
    189 except: pass
    190 try: logger.infoPair("Estimated time for STs", "%.1f hours" % (pendSTProcessed / rateST))
    191 except: pass
     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.