IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32089 for trunk/ippToPsps


Ignore:
Timestamp:
Aug 12, 2011, 4:04:46 PM (15 years ago)
Author:
rhenders
Message:

new getter methods for the various columns in the batch table; new method to update the ODM columns (used by pollODM program); removed getFailedBatches() method

File:
1 edited

Legend:

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

    r32002 r32089  
    5757
    5858    '''
    59     TODO
    60     '''
    61     def getProcessedIDsForThisStage(self, batchType, epoch, dvoGpc1Label):
     59    Returns a list of processed batch IDs that are not yet merged for this epoch and dvo label
     60    '''
     61    def getProcessedButUnmergedBatchIDs(self, epoch, dvoGpc1Label):
     62
     63        sql = "SELECT DISTINCT batch_id \
     64               FROM batch \
     65               WHERE timestamp > '" + epoch + "' \
     66               AND dvo_db = '" + dvoGpc1Label + "' \
     67               AND loaded_to_datastore \
     68               AND !merged"
     69
     70        ids = []
     71        try:
     72            rs = self.executeQuery(sql)
     73            while (rs.next()):
     74                ids.append(rs.getInt(1))
     75        except:
     76            self.logger.exception("Can't query for processed batch ids in ipptopsps Db")
     77
     78        rs.close()
     79
     80        self.logger.debug("Found %d processed and un-merged items" % len(ids))
     81
     82        return ids
     83
     84    '''
     85    Returns a list of IDs for this batch type, epoch and dvo label (i.e. either
     86            cam_ids or stack_ids) for which the spefified column is true (=1)
     87    '''
     88    def getStageIDs(self, batchType, epoch, dvoGpc1Label, column):
    6289
    6390        sql = "SELECT DISTINCT stage_id \
     
    6693               AND timestamp > '" + epoch + "' \
    6794               AND dvo_db = '" + dvoGpc1Label + "' \
    68                AND loaded_to_datastore"
     95               AND " + column + " = 1"
    6996
    7097        ids = []
     
    74101                ids.append(rs.getInt(1))
    75102        except:
    76             self.logger.exception("Can't query for processed ids in ipptopsps Db")
     103            self.logger.exception("Can't query for ids with " + column + " = 1 in ipptopsps Db")
    77104
    78105        rs.close()
    79106
    80         self.logger.debug("Found %d processed and published items for batchType='%s'" % (len(ids), batchType))
     107        self.logger.debug("Found %d batches with %s = 1 for batch type='%s'" % (len(ids), column, batchType))
    81108
    82109        return ids
    83110
    84111    '''
    85     TODO
    86     '''
    87     def getLastBatchPublished(self, batchType):
    88 
    89         sql = "SELECT TIMESTAMPDIFF(MINUTE, timestamp, now())/60.0 \
     112    Series of getter methods that utilise getStageIDs() method above
     113    '''
     114    def getProcessedIDs(self, batchType, epoch, dvoGpc1Label):
     115        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "processed")
     116    def getloadedToDatastoreIDs(self, batchType, epoch, dvoGpc1Label):
     117        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "loaded_to_datastore")
     118    def getLoadedToODMIDs(self, batchType, epoch, dvoGpc1Label):
     119        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "loaded_to_ODM")
     120    def getMergeWothyIDs(self, batchType, epoch, dvoGpc1Label):
     121        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "merge_worthy")
     122    def getMergedIDs(self, batchType, epoch, dvoGpc1Label):
     123        return self.getStageIDs(batchType, epoch, dvoGpc1Label, "merged")
     124
     125    '''
     126    Returns the time (as a string) that the last batch was published to the datastore for
     127    this epoch, dvo label and batch type
     128    '''
     129    def getTimeOfLastBatchPublished(self, batchType, epoch, dvoGpc1Label):
     130
     131        minutes = None
     132
     133        sql = "SELECT TIMESTAMPDIFF(MINUTE, timestamp, now()) \
    90134               FROM batch \
    91135               WHERE batch_type = '" + batchType + "' \
    92136               AND loaded_to_datastore \
     137               AND timestamp > '" + epoch + "' \
     138               AND dvo_db = '" + dvoGpc1Label + "' \
    93139               ORDER BY timestamp DESC LIMIT 1"
    94140
    95141        try:
    96142            rs = self.executeQuery(sql)
    97             rs.first()
    98             hours = rs.getFloat(1)
     143            if rs.first(): minutes = rs.getFloat(1)
    99144        except:
    100145            self.logger.exception("Unable to get last batch published")
    101146
    102         return hours
     147        if not minutes: return "Never"
     148
     149        hours = minutes/60.0
     150        days = float(hours)/24.0
     151        weeks = float(days)/7.0
     152
     153        if minutes < 60: return "%.1f minutes ago" % minutes
     154        elif hours < 48: return "%.1f hours ago" % hours
     155        elif days < 7: return "%.1f days ago" % days
     156        return "%.1f weeks ago" % weeks
    103157
    104158    '''
     
    153207
    154208        return bpm
    155 
    156 
    157     '''
    158     TODO
    159     '''
    160     def getFailedBatches(self, batchType, epoch, dvoGpc1Label):
    161 
    162         sql = "SELECT DISTINCT stage_id \
    163                FROM batch \
    164                WHERE timestamp > '" + epoch + "' \
    165                AND batch_type = '" + batchType + "' \
    166                AND dvo_db = '" + dvoGpc1Label + "' \
    167                AND !processed"
    168 
    169         ids = []
    170         try:
    171             rs = self.executeQuery(sql)
    172             while (rs.next()):
    173                 ids.append(rs.getInt(1))
    174         except:
    175             self.logger.exception("Can't query for failed ids in ipptopsps Db")
    176 
    177         rs.close()
    178 
    179         self.logger.debug("Found %d failed items for batchType='%s'" % (len(ids), batchType))
    180 
    181         return ids
    182209
    183210    '''
     
    200227        sql = "UPDATE batch \
    201228               SET processed = " + str(processed) + " \
     229               WHERE batch_id = " + str(batchID)
     230
     231        self.execute(sql)
     232
     233    '''
     234    Updates ODM status for this batch
     235    '''
     236    def updateOdmStatus(self, batchID, odmStatus):
     237
     238        sql = "UPDATE batch \
     239               SET loaded_to_ODM = " + str(odmStatus['LOADEDTOODM']) + ", \
     240               merge_worthy = " + str(odmStatus['MERGEWORTHY']) + ", \
     241               merged = " + str(odmStatus['MERGED']) + " \
    202242               WHERE batch_id = " + str(batchID)
    203243
Note: See TracChangeset for help on using the changeset viewer.