Index: trunk/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- trunk/ippToPsps/jython/ipptopspsdb.py	(revision 32292)
+++ trunk/ippToPsps/jython/ipptopspsdb.py	(revision 32353)
@@ -245,16 +245,53 @@
 
     '''
+    TODO remove these
     Series of getter methods that utilise getStageIDs() method above
     '''
     def getProcessedIDs(self, batchType, epoch, dvoGpc1Label):
         return self.getStageIDs(batchType, epoch, dvoGpc1Label, "processed", 1)
-    def getloadedToDatastoreIDs(self, batchType, epoch, dvoGpc1Label):
+    def getFailedProcessedIDs(self, batchType, epoch, dvoGpc1Label):
+        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "processed", -1)
+    def getLoadedToDatastoreIDs(self, batchType, epoch, dvoGpc1Label):
         return self.getStageIDs(batchType, epoch, dvoGpc1Label, "loaded_to_datastore", 1)
+    def getFailedLoadedToDatastoreIDs(self, batchType, epoch, dvoGpc1Label):
+        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "loaded_to_datastore", -1)
     def getLoadedToODMIDs(self, batchType, epoch, dvoGpc1Label):
         return self.getStageIDs(batchType, epoch, dvoGpc1Label, "loaded_to_ODM", 1)
+    def getFailedLoadedToODMIDs(self, batchType, epoch, dvoGpc1Label):
+        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "loaded_to_ODM", -1)
     def getMergeWorthyIDs(self, batchType, epoch, dvoGpc1Label):
         return self.getStageIDs(batchType, epoch, dvoGpc1Label, "merge_worthy", 1)
+    def getFailedMergeWorthyIDs(self, batchType, epoch, dvoGpc1Label):
+        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "merge_worthy", -1)
     def getMergedIDs(self, batchType, epoch, dvoGpc1Label):
         return self.getStageIDs(batchType, epoch, dvoGpc1Label, "merged", 1)
+    def getFailedMergedIDs(self, batchType, epoch, dvoGpc1Label):
+        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "merged", -1)
+
+    '''
+    Returns a list of stages
+    '''
+    def getStages(self):
+        return ['processed', 'loaded_to_datastore', 'loaded_to_ODM', 'merge_worthy', 'merged', 'deleted_local', 'deleted_datastore', 'deleted_dxlayer']
+
+    '''
+    Returns batches per hour
+    '''
+    def getBatchesPerHour(self, batchType, epoch, dvoGpc1Label, hours):
+
+        sql = "SELECT COUNT(batch_id)/ " + str(hours) + " \
+               FROM batch \
+               WHERE batch_type = '" + batchType + "' \
+               AND processed = 1 \
+               AND timestamp > '" + epoch + "' \
+               AND dvo_db = '" + dvoGpc1Label + "' \
+               AND timestamp > (now() - INTERVAL " +  str(hours) + " HOUR)"
+
+        try:
+            rs = self.executeQuery(sql)
+            if rs.first(): return rs.getFloat(1)
+        except:
+            self.logger.exception("Unable to get batches per hour")
+            return 0.0
 
     '''
@@ -286,60 +323,8 @@
         weeks = days/7.0
 
-        if minutes < 60: return "%.1f minutes ago" % minutes
+        if minutes < 60: return "%.1f mins ago" % minutes
         elif hours < 48: return "%.1f hours ago" % hours
         elif days < 7: return "%.1f days ago" % days
         return "%.1f weeks ago" % weeks
-
-    '''
-    TODO
-    '''
-    def getBatchesPerDay(self, batchType, startTime, endTime=""):
-
-        bph = self.getBatchesPerHour(batchType, startTime, endTime)
-        return bph * 24
-
-    '''
-    TODO
-    '''
-    def getBatchesPerHour(self, batchType, startTime, endTime=""):
-
-        bpm = self.getBatchesPerMinute(batchType, startTime, endTime)
-        return bpm * 60
-
-    '''
-    TODO
-    '''
-    def getAverageTimePerBatch(self, batchType, startTime, endTime=""):
-
-        sql = "SELECT (TIMESTAMPDIFF(MINUTE, min(timestamp), max(timestamp)) / COUNT(*)) \
-               FROM batch \
-               WHERE timestamp > '" + startTime + "' and batch_type = '" + batchType + "'"
-
-        try:
-            rs = self.executeQuery(sql)
-            rs.first()
-            time = rs.getDouble(1)
-        except:
-            self.logger.exception("Unable to get batches per minute")
-
-        return time
-
-    '''
-    TODO
-    '''
-    def getBatchesPerMinute(self, batchType, startTime, endTime=""):
-
-        sql = "SELECT (count(*) / TIMESTAMPDIFF(MINUTE, min(timestamp), max(timestamp)) ) \
-               FROM batch \
-               WHERE timestamp > '" + startTime + "' and batch_type = '" + batchType + "'"
-
-        try:
-            rs = self.executeQuery(sql)
-            rs.first()
-            bpm = rs.getDouble(1)
-        except:
-            self.logger.exception("Unable to get batches per minute")
-
-        return bpm
 
     '''
