IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31345


Ignore:
Timestamp:
Apr 22, 2011, 1:15:51 PM (15 years ago)
Author:
rhenders
Message:

Now subclass of MySql base class

Location:
trunk/ippToPsps/jython
Files:
2 edited

Legend:

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

    r31323 r31345  
    77import logging
    88
     9from mysql import MySql
    910from java.sql import *
    10 from xml.etree.ElementTree import ElementTree
    1111
    1212
     
    1414Class for GPC1 database connectivity
    1515'''
    16 class Gpc1Db(object):
    17 
    18     driverName="com.mysql.jdbc.Driver"
     16class Gpc1Db(MySql):
    1917
    2018    '''
    2119    Constructor
    22 
    2320    '''
    2421    def __init__(self, logger):
    25 
    26         # setup logging
    27         self.logger = logger
    28         self.logger.debug("Gpc1Db constructor")
    29 
    30         # open config
    31         doc = ElementTree(file="config.xml")
    32 
    33         # set up JDBC connection
    34         dbName = doc.find("gpc1database/name").text
    35         dbHost = doc.find("gpc1database/host").text
    36         dbUser = doc.find("gpc1database/user").text
    37         dbPass = doc.find("gpc1database/password").text
    38         self.url = "jdbc:mysql://"+dbHost+"/"+dbName+"?user="+dbUser+"&password="+dbPass
    39         self.con = DriverManager.getConnection(self.url)
    40         self.stmt = self.con.createStatement()
     22        super(Gpc1Db, self).__init__(logger,"gpc1database")
    4123
    4224    '''
     
    4628
    4729        self.logger.debug("Gpc1Db destructor")
    48         self.stmt.close()
    49         self.con.close()
    50 
    5130
    5231    '''
    53     Gets a list of sky_ids in this DVO database
     32    Gets a list of ids in this DVO database for this stage, could be cam or staticsky (so far)
    5433    '''
    55     def getSkyIDsInThisDVODb(self, dvoDb):
     34    def getIDsInThisDVODbForThisStage(self, dvoDb, stage):
    5635
    5736        self.logger.debug("Querying GPC1 for sky_ids in this DVO database: " + dvoDb)
     
    5938        sql = "SELECT DISTINCT stage_id \
    6039               FROM addRun \
    61                WHERE stage = 'staticsky' \
     40               WHERE stage = '" + stage + "' \
    6241               AND dvodb = '" + dvoDb + "'"
    63 
    64         print sql
    6542
    6643        try:
     
    6946            self.logger.exception("Can't query for sky_ids")
    7047
    71         skyIDs = []
     48        ids = []
    7249        while (rs.next()):
    73             skyIDs.append(rs.getInt(1))
     50            ids.append(rs.getInt(1))
    7451
    7552        rs.close()
    7653
    77         return skyIDs
     54        return ids
    7855
    7956    '''
     
    10683
    10784        return imageIDs
     85
     86    '''
     87    Gets some camera-stage meta data for this cam_id
     88    '''
     89    def getCameraStageMeta(self, camID):
     90
     91        self.logger.debug("Querying GPC1 for camera meta data")
     92
     93        meta = []
     94        sql = "SELECT exp_id, exp_name, camRun.dist_group \
     95               FROM camRun \
     96               JOIN chipRun USING(chip_id) \
     97               JOIN rawExp USING(exp_id) WHERE camRun.cam_id = %d" % camID
     98
     99        try:
     100            rs = self.stmt.executeQuery(sql)
     101            rs.first()
     102        except:
     103            self.logger.exception("Can't query for camera meta")
     104        finally:
     105            meta.append(rs.getInt(1))
     106            meta.append(rs.getString(2))
     107            meta.append(rs.getString(3))
     108
     109        return meta
     110
     111    '''
     112    Gets a camera-stage smf for this cam_id
     113    '''
     114    def getCameraStageSmf(self, camID):
     115
     116        self.logger.debug("Querying GPC1 for camera smf files")
     117
     118        sql = "SELECT path_base \
     119               FROM camProcessedExp \
     120               JOIN camRun USING(cam_id) \
     121               WHERE camRun.cam_id = %d" % camID
     122
     123        try:
     124            rs = self.stmt.executeQuery(sql)
     125            rs.first()
     126        except:
     127            self.logger.exception("Can't query for camera smfs")
     128
     129        # get path to base dir of cmf files
     130        path = rs.getString(1)
     131        path = path[0:path.rfind("/")]
     132       
     133        # list all cmf files if a neb path
     134        files = []
     135        if path.startswith("neb"):
     136
     137            f=os.popen("neb-ls -p "+path+"/%smf")
     138            print "neb-ls -p "+path+"/%smf"
     139            for i in f.readlines():
     140                files.append(i.rstrip())
     141
     142        # or not a neb path
     143        else:
     144            files = glob.glob(path + "/*.cmf")
     145
     146        return files[0] # TODO just returning first file - check
    108147
    109148
  • trunk/ippToPsps/jython/ipptopspsdb.py

    r31225 r31345  
    66import logging
    77
     8from mysql import MySql
    89from java.sql import *
    9 from xml.etree.ElementTree import ElementTree
    1010
    1111'''
    1212Class for ippToPsps database connectivity
    1313'''
    14 class IppToPspsDb(object):
    15 
    16     driverName="com.mysql.jdbc.Driver"
     14class IppToPspsDb(MySql):
    1715
    1816    '''
    1917    Constructor
    20 
    2118    '''
    2219    def __init__(self, logger):
    23 
    24         # setup logging
    25         self.logger = logger
    26         self.logger.debug("IppToPspsDb Constructor")
    27         # open config
    28         doc = ElementTree(file="config.xml")
    29 
    30         # set up JDBC connection
    31         dbName = doc.find("ipptopspsdatabase/name").text
    32         dbHost = doc.find("ipptopspsdatabase/host").text
    33         dbUser = doc.find("ipptopspsdatabase/user").text
    34         dbPass = doc.find("ipptopspsdatabase/password").text
    35         self.url = "jdbc:mysql://"+dbHost+"/"+dbName+"?user="+dbUser+"&password="+dbPass
    36         self.con = DriverManager.getConnection(self.url)
    37         self.stmt = self.con.createStatement()
     20        super(IppToPspsDb, self).__init__(logger,"ipptopspsdatabase")
    3821
    3922    '''
    4023    Creates a new batch
    4124    '''
    42     def createNewBatch(self, expID, surveyType, batchType, dvoDb, datastoreProduct):
     25    def createNewBatch(self, batchType, survey, dvoDb, datastoreProduct):
    4326
    44         sql = "SELECT batch_id FROM batches ORDER BY batch_id DESC LIMIT 1"
     27        sql = "INSERT INTO batch ( \
     28               batch_type, \
     29               survey, \
     30               dvo_db, \
     31               datastore_product \
     32               ) VALUES ( \
     33               '" + batchType + "', \
     34               '" + survey + "', \
     35               '" + dvoDb + "', \
     36               '" + datastoreProduct + "' \
     37               )"
     38
     39        self.stmt.execute(sql)
     40
     41        sql = "SELECT MAX(batch_id) FROM batch"
    4542
    4643        batchID = -1;
     
    5350            self.logger.exception("Unable to get batch ID")
    5451
    55         if batchID > 0:
    56             batchID = batchID + 1
    57 
    58             sql = "INSERT INTO batches \
    59                    (batch_id, \
    60                     exp_id, \
    61                     survey_id, \
    62                     batch_type, \
    63                     dvo_db, \
    64                     datastore_product) \
    65                    VALUES \
    66                    ("+str(batchID)+", \
    67                     " + str(expID) + ", \
    68                     '"+surveyType+"', \
    69                     '"+batchType+"', \
    70                     '"+dvoDb+"', \
    71                     '"+datastoreProduct+"')"
    72 
    73             self.stmt.execute(sql)
    74 
    75         self.logger.info("Creating new batch in ippToPsps database with batchID = %d" % batchID)
     52        self.logger.info("Created new batch in ippToPsps database with batchID = %d" % batchID)
    7653
    7754        return batchID;
     55
     56    '''
     57    Updates min/max object ID on this table and batch
     58    '''
     59    def updateMinMaxObjID(self, batchID, minObjID, maxObjID):
     60
     61        sql = "UPDATE batch SET \
     62               min_obj_id = " + str(minObjID) + ", \
     63               max_obj_id = " + str(maxObjID) + " \
     64               WHERE batch_id = " + str(batchID)
     65
     66        self.stmt.execute(sql)
     67
     68    '''
     69    Updates batch processed field
     70    '''
     71    def updateProcessed(self, batchID, processed):
     72
     73        sql = "UPDATE batch \
     74               SET processed = " + str(processed) + " \
     75               WHERE batch_id = " + str(batchID)
     76
     77        self.stmt.execute(sql)
     78
     79    '''
     80    Updates batch loaded_to_datastore field
     81    '''
     82    def updateLoadedToDatastore(self, batchID, loadedToDatastore):
     83
     84        sql = "UPDATE batch \
     85               SET loaded_to_datastore = " + str(loadedToDatastore) + " \
     86               WHERE batch_id = " + str(batchID)
     87
     88        self.stmt.execute(sql)
     89
     90    '''
     91    Inserts some stack metadata for this batch ID
     92    '''
     93    def insertStackMeta(self, batchID, skyID, stackID, filter, stackType):
     94
     95        sql = "INSERT INTO stack ( \
     96               batch_id \
     97               ,sky_id \
     98               ,stack_id \
     99               ,filter \
     100               ,stack_type \
     101               ) VALUES ( \
     102               " + str(batchID) + " \
     103               ," + str(skyID) + " \
     104               ," + str(stackID) + " \
     105               ,'" + filter + "' \
     106               ,'" + stackType + "' \
     107               )"
     108
     109        self.stmt.execute(sql)
     110
    78111
    79112    '''
Note: See TracChangeset for help on using the changeset viewer.