Changeset 5459


Ignore:
Timestamp:
03/07/09 12:01:13 (10 years ago)
Author:
sdonegan
Message:

Updated to allow updates to main discovery database for ordering ny linked popularity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MSI/Discovery/trunk/DI01-LoggingFramework/urlRedirection/trunk/ndgredirect/lib/urlRedirectDB.py

    r5427 r5459  
    1010    """ 
    1111 
    12     def __init__(self,datasetURL_IP,datasetID_IP,datasetTitle_IP,originatingIp_IP,configFileName_IP): 
     12    def __init__(self,datasetURL_IP,datasetID_IP,datasetTitle_IP,originatingIp_IP,configFileNameSrch_IP,configFileNameDisc_IP): 
    1313        """One instance of Globals is created during application 
    1414        initialization and is available during requests via the 'g' 
     
    1616        """ 
    1717         
    18         logging.info("Initialised urlRedirecDB: " + datasetURL_IP + " " + datasetID_IP+ " " +datasetTitle_IP+ " " +originatingIp_IP + " " +configFileName_IP) 
     18        logging.info("Initialised urlRedirecDB: " + datasetURL_IP + " " + datasetID_IP+ " " +datasetTitle_IP+ " " +originatingIp_IP + " " + configFileNameSrch_IP + " " + configFileNameDisc_IP) 
    1919         
    2020        #set up vars 
     
    2323        self.datasetTitle = datasetTitle_IP 
    2424        self.originatingIp = originatingIp_IP 
    25         self.configFileName = configFileName_IP 
     25        self.configFileNameSrch = configFileNameSrch_IP 
     26        self.configFileNameDisc = configFileNameDisc_IP 
    2627         
    27         #set up db connection 
    28         self.pgc = pgc(configFile = self.configFileName) 
     28        #update the db        
     29        try:      
     30            self.updateURLtrackingDB() 
     31            logging.info("Successfully updated url redirection LOGGING database") 
     32             
     33        except:             
     34            logging.warn("Failed at updating url redirection database") 
     35             
     36         #now update database    
     37        try:      
     38            self.updateDiscoveryTable() 
     39            logging.info("Successfully updated Discovery database linked count") 
     40             
     41        except: 
     42            logging.warn("Failed at updating Discovery database (link counter)") 
    2943         
    30         #update the db 
    31         self.updateURLtrackingDB() 
    3244 
    33     def runCommand(self,pgc, command): 
     45    def runCommand(self,thispgc, command): 
    3446     
    3547        try: 
    36             resultSet = pgc.runSQLCommand(command) 
     48            logging.info("Hit runCommand: " + command) 
     49             
     50            resultSet = thispgc.runSQLCommand(command) 
     51             
    3752            #id = getResultSetSingleVal(resultSet) 
    3853        except: 
     
    5772 
    5873     
     74        #set up db connection 
     75        self.pgc = pgc(configFile = self.configFileNameSrch) 
     76     
    5977        command = "select url_instance_id from urlTracking where url = '" + self.datasetURL +"' and dataset_id ='" + self.datasetID + "';" 
    6078 
     
    7593            command = "update urlTracking set hits = '" + str(hits) + "' where url = '" + self.datasetURL +"' and dataset_id = '" + self.datasetID + "';"  
    7694            input = self.runCommand(self.pgc,command) 
     95             
     96             
     97    def updateDiscoveryTable (self): 
     98        ''' 
     99        Method to update the relevant dataset hits column in the primary discovery database to aid sorting by datasetlinked popularity 
     100        ''' 
     101         
     102        #select access_count from original_document where discovery_id = 'nnn'; 
     103         
     104        #set up db connection         
     105        self.discoveryPgc = pgc(configFile = self.configFileNameDisc) 
     106             
     107        #get current number of access count for dataset 
     108        command = "select access_count from original_document where discovery_id ='" + self.datasetID + "';" 
     109         
     110        results = self.runCommand(self.discoveryPgc, command) 
     111         
     112        numHits = self.getResultSetSingleVal(results) 
     113         
     114        if numHits < 1: 
     115            command = "update original_document set access_count = '1' where discovery_id = '" + self.datasetID + "';" 
     116        else: 
     117            command = "update original_document set access_count = '" + str(numHits + 1) + "' where discovery_id = '" + self.datasetID + "';" 
     118                         
     119        logging.info("Update discovery table with hits command " + command) 
     120     
     121        input = self.runCommand(self.discoveryPgc,command) 
     122     
Note: See TracChangeset for help on using the changeset viewer.