IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31842


Ignore:
Timestamp:
Jul 8, 2011, 2:50:57 PM (15 years ago)
Author:
rhenders
Message:

added numerous methods to provide numbers for new metrics code; method tp join across ipptopsps and gpc1 Dbs in order to ascertian all unprocessed IDs

File:
1 edited

Legend:

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

    r31808 r31842  
    1717    Constructor
    1818    '''
    19     def __init__(self, logger):
    20         super(IppToPspsDb, self).__init__(logger,"ipptopspsdatabase")
     19    def __init__(self, logger, doc):
     20        super(IppToPspsDb, self).__init__(logger, doc, "ipptopspsdatabase")
    2121
    2222    '''
     
    5252            self.logger.exception("Unable to get batch ID")
    5353
    54         self.logger.info("Created new batch in ippToPsps database with batchID = %d" % batchID)
     54        self.logger.debug("Created new batch in ippToPsps database with batchID = %d" % batchID)
    5555
    5656        return batchID;
     57
     58    '''
     59    TODO
     60    '''
     61    def getUnprocessedIDsForThisStage(self, dvoDb, batchType, startDate):
     62
     63        if batchType == "P2": # TODO define these someplace
     64
     65            stage = "cam"
     66            sql = "SELECT DISTINCT stage_id \
     67                   FROM gpc1.addRun \
     68                   WHERE stage = '" + stage + "' \
     69                   AND dvodb = '" + dvoDb + "' \
     70                   AND stage_id NOT IN "
     71
     72        elif batchType == "ST":
     73
     74            stage = "staticsky"
     75            sql = "SELECT DISTINCT stack_id \
     76                   FROM gpc1.staticskyInput \
     77                   JOIN gpc1.addRun ON(gpc1.staticskyInput.sky_id = gpc1.addRun.stage_id) \
     78                   WHERE stage = '" + stage + "' \
     79                   AND dvodb = '" + dvoDb + "' \
     80                   AND stack_id NOT IN "
     81
     82        sql = sql + "(SELECT stage_id \
     83              FROM batch \
     84              WHERE batch_type = '" + batchType + "' \
     85              AND timestamp > '" + startDate + "' \
     86              AND loaded_to_datastore)"
     87
     88        ids = []
     89        try:
     90            rs = self.executeQuery(sql)
     91            while (rs.next()):
     92                ids.append(rs.getInt(1))
     93        except:
     94            self.logger.exception("Can't query for ids in DVO")
     95
     96        rs.close()
     97
     98        self.logger.debug("Found %d unprocessed items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage))
     99
     100        return ids
     101
     102    '''
     103    TODO
     104    '''
     105    def getLastBatchPublished(self, batchType):
     106
     107        sql = "SELECT TIMESTAMPDIFF(MINUTE, timestamp, now())/60.0 \
     108               FROM batch \
     109               WHERE batch_type = '" + batchType + "' \
     110               AND loaded_to_datastore \
     111               ORDER BY timestamp DESC LIMIT 1"
     112
     113        try:
     114            rs = self.executeQuery(sql)
     115            rs.first()
     116            hours = rs.getFloat(1)
     117        except:
     118            self.logger.exception("Unable to get last batch published")
     119
     120        return hours
     121
     122    '''
     123    TODO
     124    '''
     125    def getBatchesPerDay(self, batchType, startTime, endTime=""):
     126
     127        bph = self.getBatchesPerHour(batchType, startTime, endTime)
     128        return bph * 24
     129
     130    '''
     131    TODO
     132    '''
     133    def getBatchesPerHour(self, batchType, startTime, endTime=""):
     134
     135        bpm = self.getBatchesPerMinute(batchType, startTime, endTime)
     136        return bpm * 60
     137
     138    '''
     139    TODO
     140    '''
     141    def getAverageTimePerBatch(self, batchType, startTime, endTime=""):
     142
     143        sql = "SELECT (TIMESTAMPDIFF(MINUTE, min(timestamp), max(timestamp)) / COUNT(*)) \
     144               FROM batch \
     145               WHERE timestamp > '" + startTime + "' and batch_type = '" + batchType + "'"
     146
     147        try:
     148            rs = self.executeQuery(sql)
     149            rs.first()
     150            time = rs.getDouble(1)
     151        except:
     152            self.logger.exception("Unable to get batches per minute")
     153
     154        return time
     155
     156    '''
     157    TODO
     158    '''
     159    def getBatchesPerMinute(self, batchType, startTime, endTime=""):
     160
     161        sql = "SELECT (count(*) / TIMESTAMPDIFF(MINUTE, min(timestamp), max(timestamp)) ) \
     162               FROM batch \
     163               WHERE timestamp > '" + startTime + "' and batch_type = '" + batchType + "'"
     164
     165        try:
     166            rs = self.executeQuery(sql)
     167            rs.first()
     168            bpm = rs.getDouble(1)
     169        except:
     170            self.logger.exception("Unable to get batches per minute")
     171
     172        return bpm
     173
     174
     175    '''
     176    TODO
     177    '''
     178    def getTotalFailedBatches(self, batchType, startTime, endTime=""):
     179
     180        sql = "SELECT COUNT(DISTINCT stage_id) \
     181               FROM batch \
     182               WHERE timestamp > '" + startTime + "' \
     183               AND batch_type = '" + batchType + "' \
     184               AND !processed \
     185               AND stage_id NOT IN \
     186               (SELECT DISTINCT stage_id \
     187                FROM batch \
     188                WHERE timestamp > '" + startTime + "'  \
     189                AND batch_type = '" + batchType + "' \
     190                AND loaded_to_datastore)"
     191
     192        try:
     193            rs = self.executeQuery(sql)
     194            rs.first()
     195            total = rs.getInt(1)
     196        except:
     197            self.logger.exception("Unable to count failed batches")
     198
     199        return total
     200    '''
     201    TODO
     202    '''
     203    def getTotalBatchesPublished(self, batchType, startTime, endTime=""):
     204
     205        sql = "SELECT COUNT(*) \
     206               FROM batch \
     207               WHERE timestamp > '" + startTime + "' \
     208               AND batch_type = '" + batchType + "' \
     209               AND loaded_to_datastore"
     210
     211        try:
     212            rs = self.executeQuery(sql)
     213            rs.first()
     214            total = rs.getInt(1)
     215        except:
     216            self.logger.exception("Unable to count batches")
     217
     218        return total
    57219
    58220    '''
     
    134296    Inserts some stack metadata for this batch ID
    135297    '''
    136     def insertStackMeta(self, batchID, stackID, filter, stackType):
     298    def insertStackMeta(self, batchID, filter, stackType):
    137299
    138300        sql = "INSERT INTO stack ( \
    139301               batch_id \
    140                ,stack_id \
    141302               ,filter \
    142303               ,stack_type \
    143304               ) VALUES ( \
    144305               " + str(batchID) + " \
    145                ," + str(stackID) + " \
    146306               ,'" + filter + "' \
    147                ,'" + stackType + "' \
    148                )"
     307               ,'" + stackType + "')"
    149308
    150309        self.execute(sql)
Note: See TracChangeset for help on using the changeset viewer.