Changeset 33175
- Timestamp:
- Jan 27, 2012, 3:46:15 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/scratchdb.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/scratchdb.py
r33164 r33175 207 207 Updates dvoDone table with this DVO table 208 208 ''' 209 def setImportedThisDvoTable(self, path ):209 def setImportedThisDvoTable(self, path, region="null"): 210 210 211 211 fileStat = os.stat(path) … … 216 216 217 217 # now insert new version with up-to-date size and date 218 sql = "INSERT INTO " + self.dvoDoneTable + " ( path, modifiedDate, size) VALUES ('" + path + "', " + str(str(fileStat.st_mtime)) + ", " + str(str(fileStat.st_size)) + ")"218 sql = "INSERT INTO " + self.dvoDoneTable + " (region, path, modifiedDate, size) VALUES ('" + region + "', '" + path + "', " + str(str(fileStat.st_mtime)) + ", " + str(str(fileStat.st_size)) + ")" 219 219 self.execute(sql) 220 220 221 222 ''' 223 Gets the id for the cpm file for the provided region 224 ''' 225 def getDvoCpmFileIdForRegion(self, region): 226 227 id = -1 228 sql = "SELECT id FROM " + self.dvoDoneTable + " WHERE region = '" + region + "' AND path LIKE '%.cpm'"; 229 try: 230 rs = self.executeQuery(sql) 231 rs.first() 232 id = rs.getInt(1) 233 except: 234 self.logger.errorPair("Could not get file id from " + self.dvoDoneTable, "for region: " + region) 235 236 return id 237 238 239 ''' 240 Gets the id for the provided file 241 ''' 242 def getDvoFileId(self, path): 243 244 id = -1 245 sql = "SELECT id FROM " + self.dvoDoneTable + " WHERE path = '" + path + "'" 246 try: 247 rs = self.executeQuery(sql) 248 rs.first() 249 id = rs.getInt(1) 250 except: 251 self.logger.errprPair("Could not get file id from " + self.dvoDoneTable + "for", path) 252 253 return id 254 255 ''' 256 Returns a list of DVO regions currently ingested 257 ''' 258 def getIngestedDvoRegions(self): 259 260 regions = [] 261 262 sql = "SELECT DISTINCT region FROM dvoDone WHERE region != 'null'" 263 try: 264 rs = self.executeQuery(sql) 265 while (rs.next()): 266 regions.append(rs.getString(1)) 267 rs.close() 268 except: 269 self.logger.errorPai("Can't query for ingested regions", sql) 270 271 return regions 272 273 221 274 ''' 222 275 Gets total size of DVO files imported to this database … … 225 278 def getTotalSizeOfIngestedDvoFiles(self): 226 279 280 size = 0 227 281 sql = "SELECT SUM(size) FROM " + self.dvoDoneTable + " WHERE path LIKE '%cpm' OR path LIKE '%cpt'" 228 282 try: … … 248 302 249 303 if head == path: 250 self.logger. infoPair("Already ingested stuff from DVO at", path)304 self.logger.debugPair("Already ingested stuff from DVO at", path) 251 305 return True 252 306 else: … … 347 401 348 402 ''' 403 Removes the provided DVO FITS files from from dvoDone and dvoDetection tables 404 Returns a count of the number of detections deleted 405 ''' 406 def purgeTheseDvoRegions(self, regions): 407 408 detectionCount = self.getRowCount(self.dvoDetectionTable) 409 for region in regions: 410 411 fileId = self.getDvoCpmFileIdForRegion(region) 412 413 if fileId < 0: 414 self.logger.errorPair("Unable to get file ID to delete " + region + " from", self.dvoDoneTable) 415 continue 416 417 sql = "DELETE FROM " + self.dvoDetectionTable + " WHERE fileID = " + str(fileId) 418 try: self.execute(sql) 419 except: 420 self.logger.errorPair("Unable to delete from " + self.dvoDetectionTable, "for file ID: %d" % fileId) 421 return False 422 423 sql = "DELETE FROM " + self.dvoDoneTable + " WHERE region = '" + region + "'" 424 try: self.execute(sql) 425 except: 426 self.logger.errorPair("Unable to delete " + region + " from", self.dvoDoneTable) 427 428 429 return detectionCount - self.getRowCount(self.dvoDetectionTable) 430 431 432 ''' 349 433 Drops and recreates tables necessary for dvoToMySQL program. Be very careful before using this... 350 434 ''' … … 368 452 except: self.logger.errorPair("Unable to create table", self.dvoDetectionTable) 369 453 454 # TODO 455 sql = "ALTER TABLE " + self.dvoDetectionTable + " ADD fileID INT NOT NULL" 456 try: self.execute(sql) 457 except: self.logger.errorPair("Unable to add fileID column to ", self.dvoDetectionTable) 458 370 459 self.logger.infoPair("Creating table", self.dvoDoneTable ) 371 sql = "CREATE TABLE " + self.dvoDoneTable + " ( path VARCHAR(1000), modifiedDate BIGINT, size BIGINT)"460 sql = "CREATE TABLE " + self.dvoDoneTable + " (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, region VARCHAR(100), path VARCHAR(1000), modifiedDate BIGINT, size BIGINT)" 372 461 try: self.execute(sql) 373 462 except: self.logger.errorPair("Unable to create table", self.dvoDoneTable) … … 377 466 Gets a list of PSPS image IDs for this stack ID 378 467 ''' 379 def getDvo FilesCoveringThisRegion(self, minRa, maxRa, minDec, maxDec):468 def getDvoRegionsForThisBox(self, minRa, maxRa, minDec, maxDec): 380 469 381 470 self.logger.debug("Querying DVO SkyTable for FITS files in this region")
Note:
See TracChangeset
for help on using the changeset viewer.
