Index: trunk/ippToPsps/jython/metrics.py
===================================================================
--- trunk/ippToPsps/jython/metrics.py	(revision 33351)
+++ trunk/ippToPsps/jython/metrics.py	(revision 33494)
@@ -10,4 +10,5 @@
 from czardb import CzarDb
 from gpc1db import Gpc1Db
+from plot import Plot
 
 '''
@@ -27,4 +28,5 @@
         self.czarDb = CzarDb(self.logger, self.config)
         self.gpc1Db = Gpc1Db(self.logger, self.config)
+        self.plot = Plot(self.logger, self.config, self.ippToPspsDb)
    
     '''
@@ -43,5 +45,5 @@
         
             self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
-            self.logger.info("|Type| batches per hour | last 24 hours | per day this week | total detections | last published |")
+            self.logger.info("|Type| batches per hour | last 24 hours | per day this week | detections/batch | last published |")
             self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
             rateP2 = self.printStats("P2")
@@ -73,4 +75,9 @@
        
             self.checkClientStatus()
+
+            # create a density plot of pending stuff for czartool
+            self.plot.createDensityPlot("P2", True)
+            self.plot.createDensityPlot("ST", True)
+
             if not self.waitForPollTime(): break
 
@@ -89,6 +96,19 @@
     
         # get a master list of IDs in DVO for this batch type
-        #allIDs = self.gpc1Db.getIDsInThisDVODbForThisStage(self.config.dvoLabel, batchType, self.config.minRa, self.config.maxRa, self.config.minDec, self.config.maxDec)
-        allIDs = self.gpc1Db.getIDsInThisDVODbForThisStage(self.config.dvoLabel, batchType)
+        rows = self.gpc1Db.getItemsInThisDVODbForThisStage(self.config.dvoLabel,
+                batchType, 
+                self.config.minRa, 
+                self.config.maxRa, 
+                self.config.minDec, 
+                self.config.maxDec)
+
+        # we only want to IDs
+        allIDs = []
+        for row in rows:
+            try: allIDs.append(row[0])
+            except: pass
+
+        #allIDs = self.ippToPspsDb.getPendingIdsForThisConfig(self.config.name)
+
         prevList = allIDs
         numEverything = len(allIDs)
@@ -97,6 +117,4 @@
     
         tempFilename = batchType + '.dat'
-        DATFILE = open(tempFilename,'w')
-        print >> DATFILE, "DVO", numEverything, 0, 0
         for stage in stages:
     
@@ -114,9 +132,11 @@
            #    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  " % (self.getIntAsString(numPending), self.getIntAsString(numSuccess), self.getIntAsString(numFail))
+           str = "\033[1;34m%5s\033[1;m \033[1;32m%5s\033[1;m \033[1;31m%5s\033[1;m  " % (
+                   self.getIntAsString(numPending), 
+                   self.getIntAsString(numSuccess), 
+                   self.getIntAsString(numFail))
            sys.stdout.write("|%-19s" % str)
     
            prevList = success
-           print >> DATFILE, stage, numSuccess, numFail, numPending
     
            self.czarDb.insertStats(stage, self.config.dvoLabel, batchType, numPending, numSuccess, numFail)
@@ -125,5 +145,4 @@
     
         sys.stdout.write("|\n")
-        DATFILE.close()
     
         return numPendingProcessed
@@ -137,5 +156,12 @@
         for i in range(0, colCount): sys.stdout.write("+-------------------")
         sys.stdout.write("+\n")
-    
+   
+    '''
+    Safe divide function
+    '''
+    def divide(self, num, denom):
+        if denom == 0: return 0
+        else: return num / denom
+
     '''
     Prints various timing stats for this batch type
@@ -143,12 +169,16 @@
     def printStats(self, batchType):
     
-        rate = self.ippToPspsDb.countBatchesInLastPeriod(batchType, self.config.epoch, self.config.dvoLabel, "1 HOUR") / 1.0 
-    
+        rate = self.ippToPspsDb.countBatches(batchType, self.config.epoch, self.config.dvoLabel, "1 HOUR") / 1.0 
+   
+
+        batchesInLast24Hours = self.ippToPspsDb.countBatches(batchType, self.config.epoch, self.config.dvoLabel, "24 HOUR")
+        detectionsInLast24Hours = self.ippToPspsDb.getTotalDetectionsPublished(batchType, self.config.epoch, self.config.dvoLabel, "24 HOUR")
+
         self.logger.info("| %2s | %16.1f | %13d | %17.1f | %16d | %14s |" % 
                 (batchType,
                  rate,
-                 self.ippToPspsDb.countBatchesInLastPeriod(batchType, self.config.epoch, self.config.dvoLabel, "24 HOUR"),
-                 self.ippToPspsDb.countBatchesInLastPeriod(batchType, self.config.epoch, self.config.dvoLabel, "1 WEEK") / 7.0, 
-                 self.ippToPspsDb.getTotalDetectionsPublished(batchType, self.config.epoch, self.config.dvoLabel),
+                 batchesInLast24Hours,
+                 self.ippToPspsDb.countBatches(batchType, self.config.epoch, self.config.dvoLabel, "1 WEEK") / 7.0, 
+                 self.divide(detectionsInLast24Hours, batchesInLast24Hours),
                  self.ippToPspsDb.getTimeOfLastBatchPublished(batchType, self.config.epoch, self.config.dvoLabel)))
     
@@ -160,6 +190,5 @@
     '''
     def printUsage(self):
-        super(Metrics, self).printUsage()
-        print " [hours]"
+        super(Metrics, self).printUsage("[<hours>]")
 
 
