예제 #1
0
    def transferData(self,deploymentName,startDate=None,endDate=None):
        """Transfer Data between the file and the main database
        """
        log = self.log

        transaction.begin()
        self.createNodes(deploymentName)
        self.parseHeader()
        #session = meta.DBSession()
        
        self.parseData()

        #Then Save everything
        session = meta.DBSession()
        log.debug("Deleting Existing Data")
        for item in self.sensorList[1:]:
            theQry = session.query(models.sample.Sample).filter_by(sensorId = item.Id).delete()

        session.flush()
        log.debug("Adding New Data")
        session.add_all(self.outData)
        session.flush()
        log.debug("Summarising")
        summarise(self.theDeployment.Id)            

        log.debug("Done")
        transaction.commit()
예제 #2
0
    def transferData(self,deploymentName,startDate=None,endDate=None):
        """
        Transfer databetween the local database and the main database.
        As there is a heckofalot of data, we make use of a SI like protocol to
        reduce the amount of info that has to be stored,  Basically, only store
        a sample if it differs from the previous by +/- some threshold
        (CHANGE_THRESHOLD).

        We also log data every 5 mins to keep some kind of parity with the data
        sensed by arch rock

        @param deploymentName: Name of deployment to add this data to
        """
        log = self.log
        session = meta.DBSession()

        self.createDBObjects(deploymentName)

        #Load the file itself and cast all data objects into
        #CCData objects
        data = []
        reader = self.reader
        #for x in range(5):
        #    line = reader.next()

        testDate = {}
        for line in reader:

            dateArray = line[0].split()
            dt = [int(x) for x in dateArray[0].split("/")] #Date Portion
            tm = [int(x) for x in dateArray[1].split(":")] #Time Portion
            theTime = datetime.datetime(dt[2],dt[1],dt[0],tm[0],tm[1],tm[2])

            exists = testDate.get(theTime,None)
            if exists:
                #log.debug("Duplicate Valures {0} {1}".format(theTime,line))
                pass
            else:
                testDate[theTime] = True
                #And the Reading
                current = int(line[1])
                kwhReading = float(line[2])
                #print line

                #@TODO: Fix the start and stop dates
                #if startDate and theTime > startDate:
                #    if endDate and theTime < endDate:
                ccObj = CCData()
                ccObj.DateTime = theTime
                ccObj.Watts = current
                ccObj.kWh = kwhReading
                data.append(ccObj)

        log.debug("Storing {0} Objects".format(len(data)))
        self.storeData(data)
        log.debug("Summarising")
        summarise(self.theDeployment.Id)
        log.debug("Upload Complete")