Changeset 32089 for trunk/ippToPsps
- Timestamp:
- Aug 12, 2011, 4:04:46 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/ipptopspsdb.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/ipptopspsdb.py
r32002 r32089 57 57 58 58 ''' 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): 62 89 63 90 sql = "SELECT DISTINCT stage_id \ … … 66 93 AND timestamp > '" + epoch + "' \ 67 94 AND dvo_db = '" + dvoGpc1Label + "' \ 68 AND loaded_to_datastore"95 AND " + column + " = 1" 69 96 70 97 ids = [] … … 74 101 ids.append(rs.getInt(1)) 75 102 except: 76 self.logger.exception("Can't query for processed idsin ipptopsps Db")103 self.logger.exception("Can't query for ids with " + column + " = 1 in ipptopsps Db") 77 104 78 105 rs.close() 79 106 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)) 81 108 82 109 return ids 83 110 84 111 ''' 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()) \ 90 134 FROM batch \ 91 135 WHERE batch_type = '" + batchType + "' \ 92 136 AND loaded_to_datastore \ 137 AND timestamp > '" + epoch + "' \ 138 AND dvo_db = '" + dvoGpc1Label + "' \ 93 139 ORDER BY timestamp DESC LIMIT 1" 94 140 95 141 try: 96 142 rs = self.executeQuery(sql) 97 rs.first() 98 hours = rs.getFloat(1) 143 if rs.first(): minutes = rs.getFloat(1) 99 144 except: 100 145 self.logger.exception("Unable to get last batch published") 101 146 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 103 157 104 158 ''' … … 153 207 154 208 return bpm 155 156 157 '''158 TODO159 '''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 ids182 209 183 210 ''' … … 200 227 sql = "UPDATE batch \ 201 228 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']) + " \ 202 242 WHERE batch_id = " + str(batchID) 203 243
Note:
See TracChangeset
for help on using the changeset viewer.
