Index: trunk/ippToPsps/jython/metrics.py
===================================================================
--- trunk/ippToPsps/jython/metrics.py	(revision 32587)
+++ trunk/ippToPsps/jython/metrics.py	(revision 32777)
@@ -1,3 +1,4 @@
 import math
+import time
 import logging
 import smtplib
@@ -10,4 +11,5 @@
 from pslogger import PSLogger
 from ipptopspsdb import IppToPspsDb
+from czardb import CzarDb
 from gpc1db import Gpc1Db
 
@@ -76,6 +78,6 @@
        numPending = len(pending)
 
-       #if stage == 'merge_worthy' and batchType == "P2":
-       #    for n in pending: print n
+       #if stage == 'loaded_to_datastore' and batchType == "P2":
+       #    for n in fail: print n
 
        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,4 +86,6 @@
        prevList = success
        print >> DATFILE, stage, numSuccess, numFail, numPending
+
+       czarDb.insertStats(stage, DVOLABEL, batchType, numPending, numSuccess, numFail)
 
        if stage == 'processed': numPendingProcessed = numPending
@@ -124,8 +128,14 @@
 if len(sys.argv) > 1: CONFIG  = sys.argv[1]
 else:
-    print "** Usage: " + sys.argv[0] + " <configPath>"
+    print "** Usage: " + sys.argv[0] + " <configPath> [hours]"
     sys.exit(1)
 
-now = datetime.datetime.now()
+if len(sys.argv) > 2:
+    HOURS = float(sys.argv[2])
+    SECONDS = HOURS * 60.0 * 60.0
+else:
+    SECONDS = None
+
+
 
 # open config file
@@ -136,56 +146,70 @@
 logger.setup(configDoc, "metrics")
 
+# create database objects
 ippToPspsDb = IppToPspsDb(logger, configDoc)
+czarDb = CzarDb(logger, configDoc)
 gpc1Db = Gpc1Db(logger, configDoc)
-
-MINRA = None
-MAXRA = None
-MINDEC = None
-MAXDEC = None
 
 DVOLABEL = configDoc.find("dvo/gpc1Label").text
 EPOCH = configDoc.find("options/epoch").text
 
-logger.infoTitle("ippToPsps loading summary")
-logger.infoPair("Time now", now.strftime("%Y-%m-%d %H:%M:%S"))
-logger.infoPair("Loading epoch", EPOCH)
-logger.infoPair("DVO label", DVOLABEL)
-
-try:
-    MINRA = float(configDoc.find("dvo/minRA").text)
-    MAXRA = float(configDoc.find("dvo/maxRA").text)
-    MINDEC = float(configDoc.find("dvo/minDec").text)
-    MAXDEC = float(configDoc.find("dvo/maxDec").text)
-    logger.infoPair("Coordinates", "%.1f to %.1f RA, %.1f to %.1f Dec" % (MINRA, MAXRA, MINDEC, MAXDEC))
-except:
-    pass
+while True:
+
+    logger.infoTitle("ippToPsps loading summary")
+    now = datetime.datetime.now()
+    logger.infoPair("Time now", now.strftime("%Y-%m-%d %H:%M:%S"))
+    logger.infoPair("Loading epoch", EPOCH)
+    logger.infoPair("DVO label", DVOLABEL)
+
+    # get equatorial coord constraints, if any
+    MINRA = None
+    MAXRA = None
+    MINDEC = None
+    MAXDEC = None
+
+    try:
+        MINRA = float(configDoc.find("dvo/minRA").text)
+        MAXRA = float(configDoc.find("dvo/maxRA").text)
+        MINDEC = float(configDoc.find("dvo/minDec").text)
+        MAXDEC = float(configDoc.find("dvo/maxDec").text)
+        logger.infoPair("Coordinates", "%.1f to %.1f RA, %.1f to %.1f Dec" % (MINRA, MAXRA, MINDEC, MAXDEC))
+    except:
+        pass
    
 
-logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
-logger.info("|Type| batches per hour | last 24 hours | per day this week | total detections | last published |")
-logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
-rateP2 = printStats("P2")
-rateST = printStats("ST")
-logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
-
-logger.info("")
-
-stages = ippToPspsDb.getStages()
-colCount = len(stages)
-writetableSeparator(colCount)
-sys.stdout.write("|Type|  DVO  ")
-for stage in stages: sys.stdout.write("|%19s" % stage)
-sys.stdout.write("|\n")
-sys.stdout.write("|    |       ")
-for stage in stages: sys.stdout.write("| Pend  Succ  Fail  ")
-sys.stdout.write("|\n")
-writetableSeparator(colCount)
-pendP2Processed = printTableRow(stages, "P2")
-pendSTProcessed = printTableRow(stages, "ST")
-writetableSeparator(colCount)
-
-logger.info("")
-try: logger.infoPair("Estimated time for P2s", "%.1f hours" % (pendP2Processed / rateP2)) 
-except: pass
-try: logger.infoPair("Estimated time for STs", "%.1f hours" % (pendSTProcessed / rateST)) 
-except: pass
+    logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
+    logger.info("|Type| batches per hour | last 24 hours | per day this week | total detections | last published |")
+    logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
+    rateP2 = printStats("P2")
+    rateST = printStats("ST")
+    logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
+
+    logger.info("")
+
+    stages = ippToPspsDb.getStages()
+    colCount = len(stages)
+    writetableSeparator(colCount)
+    sys.stdout.write("|Type|  DVO  ")
+
+    for stage in stages: sys.stdout.write("|%19s" % stage)
+    sys.stdout.write("|\n")
+    sys.stdout.write("|    |       ")
+    for stage in stages: sys.stdout.write("| Pend  Succ  Fail  ")
+    sys.stdout.write("|\n")
+    writetableSeparator(colCount)
+    pendP2Processed = printTableRow(stages, "P2")
+    pendSTProcessed = printTableRow(stages, "ST")
+    writetableSeparator(colCount)
+
+    logger.info("")
+    try: logger.infoPair("Estimated time for P2s", "%.1f hours" % (pendP2Processed / rateP2)) 
+    except: pass
+    try: logger.infoPair("Estimated time for STs", "%.1f hours" % (pendSTProcessed / rateST)) 
+    except: pass
+
+    if SECONDS:
+        logger.infoPair("Waiting for", "%f hours" % HOURS)
+        time.sleep(SECONDS)
+    else: break
+
+
