Exemplo n.º 1
0
 def __init__(self,localURL):
     log = logging.getLogger("Cleaner")
     engine = sqlalchemy.create_engine(localURL)
     models.initialise_sql(engine)
     localSession = sqlalchemy.orm.sessionmaker(bind=engine)
     self.localSession = localSession
     log.info("Database Connection to {0} OK".format(localURL))
     self.log = log
Exemplo n.º 2
0
    def __init__(self, bif=None, dbfile=DBFILE):
        """ create a new BaseLogger and connect it to the sensor
        source (bif) and the database (dbfile).
        """
        self.engine = create_engine(dbfile, echo=False)
        #init_model(self.engine)
        models.initialise_sql(self.engine)
        #self.metadata = Base.metadata

        if bif is None: 
            self.bif = BaseIF("sf@localhost:9002")
        else:
            self.bif = bif

        self.log = logging.getLogger("baselogger")
        self.running = True
Exemplo n.º 3
0
    def __init__(self, sampleRate=60, usbPort=None):
        """Initialise plogg collection object

        :var sampleRate: Sample Rate in Seconds
        :var usbPort: Serial port to connect to
        """
        self.log = logging.getLogger("PloggCollector")
        log = self.log

        #And Format the Log output a little nicer
        ch = logging.StreamHandler()

        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        ch.setFormatter(formatter)

        log.addHandler(ch)

        log.debug("initialising Plogg Data Gatherer")

        log.debug("SampleRate")
        self.sampleRate = sampleRate

        self.nodeMap = {}

        #Attempt to connect to the Dongle
        self.connect(usbPort)

        #Then we can sort out the database
        engine = sqlalchemy.create_engine(DB_STRING)
        #Create Models and Populate any Missing Base Data
        models.initialise_sql(engine)
        populateData.init_data()

        #Scan for Ploggs
        #ploggList = self.ploggScan()
        #self.ploggList = ploggList
        self.ploggList = []
Exemplo n.º 4
0
    def __init__(self,sampleRate = 60,usbPort = None):
        """Initialise plogg collection object

        :var sampleRate: Sample Rate in Seconds
        :var usbPort: Serial port to connect to
        """
        self.log = logging.getLogger("PloggCollector")
        log = self.log

        #And Format the Log output a little nicer
        ch = logging.StreamHandler()
        
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        ch.setFormatter(formatter)

        log.addHandler(ch)

        log.debug("initialising Plogg Data Gatherer")

        log.debug("SampleRate")
        self.sampleRate = sampleRate

        self.nodeMap = {}

        #Attempt to connect to the Dongle
        self.connect(usbPort)
        
        #Then we can sort out the database
        engine = sqlalchemy.create_engine(DB_STRING)
        #Create Models and Populate any Missing Base Data
        models.initialise_sql(engine)
        populateData.init_data()      

        #Scan for Ploggs
        #ploggList = self.ploggScan()
        #self.ploggList = ploggList
        self.ploggList = []
Exemplo n.º 5
0
    def __init__(self):
        log.debug("Initialising Push Script")
        engine = sqlalchemy.create_engine(LOCAL_URL)

        #Intialise the databse
        models.initialise_sql(engine)
        models.populate_data()

        #Get relevant models etc
        session = meta.Session()

        #Check if our data exists
        theDeployment = session.query(
            models.Deployment).filter_by(name="PushTest").first()
        if theDeployment is None:
            log.debug("--> Create New Deployment")
            #Create a new Deployment
            theDeployment = models.Deployment(name="PushTest")
            session.add(theDeployment)
            session.flush()
        log.debug("Deployment is {0}".format(theDeployment))

        theHouse = session.query(
            models.House).filter_by(address="Push Address").first()
        if theHouse is None:
            log.debug("--> Create new House")
            theHouse = models.House(address="Push Address",
                                    deploymentId=theDeployment.id)
            session.add(theHouse)
            session.flush()

        log.debug("House is {0}".format(theHouse))
        #Two Rooms

        roomType = session.query(
            models.RoomType).filter_by(name="Bedroom").first()

        masterBed = session.query(
            models.Room).filter_by(name="Master Bedroom").first()
        if masterBed is None:
            masterBed = models.Room(name="Master Bedroom",
                                    roomTypeId=roomType.id)
            session.add(masterBed)

        secondBed = session.query(
            models.Room).filter_by(name="Second Bedroom").first()
        if secondBed is None:
            secondBed = models.Room(name="Second Bedroom",
                                    roomTypeId=roomType.id)
            session.add(secondBed)
        session.flush()

        #Locations
        masterLoc = session.query(models.Location).filter_by(
            houseId=theHouse.id, roomId=masterBed.id).first()

        if masterLoc is None:
            log.debug("Create New Master Location")
            masterLoc = models.Location(houseId=theHouse.id,
                                        roomId=masterBed.id)
            session.add(masterLoc)

        secondLoc = session.query(models.Location).filter_by(
            houseId=theHouse.id, roomId=secondBed.id).first()
        if secondLoc is None:
            log.debug("Create New Second Location")
            secondLoc = models.Location(houseId=theHouse.id,
                                        roomId=secondBed.id)
            session.add(secondLoc)

        session.flush()
        log.debug("Master Location {0}".format(masterLoc))
        log.debug("Second Location {0}".format(secondLoc))

        #Add Nodes to each Location
        node37 = session.query(models.Node).filter_by(id=37).first()
        if not node37:
            node37 = models.Node(id=37)
            session.add(node37)

        node38 = session.query(models.Node).filter_by(id=38).first()
        if node38 is None:
            node38 = models.Node(id=38)
            session.add(node38)

        node37.location = masterLoc
        node38.location = secondLoc
        session.flush()

        #All Our Data adding script needs to worry about is the Nodes
        self.node37 = node37
        self.node38 = node38

        #Finally add an Upload URL if required
        # theUrl = session.query(models.UploadURL).filter_by(url="[email protected]").first()
        # if not theUrl:
        #     theUrl = models.UploadURL(url="[email protected]",
        #                               dburl="mysql://*****:*****@localhost:3307/pushTest")
        #     session.add(theUrl)

        # theUrl = session.query(models.UploadURL).filter_by(url="*****@*****.**").first()
        # if not theUrl:
        #     theUrl = models.UploadURL(url="*****@*****.**",
        #                               dburl="mysql://*****:*****@localhost:3307/chtest")
        #     session.add(theUrl)

        session.commit()
Exemplo n.º 6
0
"""
Utility Function to remove all data from a given DB
"""

#DBURL = ['mysql://*****:*****@localhost/pushTest',
#         'mysql://*****:*****@localhost/pushSource']

DBURL = ['mysql://*****:*****@127.0.0.1:3307/chtest']

#DBURL = ['mysql://*****:*****@localhost/pushTest']

import sqlalchemy
import cogent.base.model as models
import cogent.base.model.meta as meta

for url in DBURL:
    engine = sqlalchemy.create_engine(url)

    models.initialise_sql(engine, True)
    models.populate_data()
Exemplo n.º 7
0
    def __init__(self):
        log.debug("Initialising Push Script")
        engine = sqlalchemy.create_engine(LOCAL_URL)
    
        #Intialise the databse
        models.initialise_sql(engine)
        models.populate_data()

        #Get relevant models etc
        session = meta.Session()
        
        #Check if our data exists
        theDeployment = session.query(models.Deployment).filter_by(name="PushTest").first()
        if theDeployment is None:
            log.debug("--> Create New Deployment")
            #Create a new Deployment
            theDeployment = models.Deployment(name="PushTest")
            session.add(theDeployment)
            session.flush()
        log.debug("Deployment is {0}".format(theDeployment))
            
        theHouse = session.query(models.House).filter_by(address="Push Address").first()
        if theHouse is None:
            log.debug("--> Create new House")
            theHouse = models.House(address="Push Address",deploymentId=theDeployment.id)
            session.add(theHouse)
            session.flush()

        log.debug("House is {0}".format(theHouse))
        #Two Rooms
        
        roomType = session.query(models.RoomType).filter_by(name="Bedroom").first()

        masterBed = session.query(models.Room).filter_by(name="Master Bedroom").first()
        if masterBed is None:
            masterBed = models.Room(name="Master Bedroom",roomTypeId=roomType.id)
            session.add(masterBed)
            
        secondBed = session.query(models.Room).filter_by(name="Second Bedroom").first()
        if secondBed is None:
            secondBed = models.Room(name="Second Bedroom",roomTypeId=roomType.id)
            session.add(secondBed)
        session.flush()
            

        #Locations
        masterLoc = session.query(models.Location).filter_by(houseId = theHouse.id,roomId=masterBed.id).first()
        
        if masterLoc is None:
            log.debug("Create New Master Location")
            masterLoc = models.Location(houseId=theHouse.id,
                                        roomId = masterBed.id)
            session.add(masterLoc)
        
        secondLoc = session.query(models.Location).filter_by(houseId=theHouse.id,
                                                             roomId=secondBed.id).first()
        if secondLoc is None:
            log.debug("Create New Second Location")
            secondLoc = models.Location(houseId = theHouse.id,
                                        roomId = secondBed.id)
            session.add(secondLoc)
        
        session.flush()
        log.debug("Master Location {0}".format(masterLoc))
        log.debug("Second Location {0}".format(secondLoc))

        #Add Nodes to each Location
        node37 = session.query(models.Node).filter_by(id=37).first()
        if not node37:
            node37 = models.Node(id=37)
            session.add(node37)

        node38 = session.query(models.Node).filter_by(id=38).first()
        if node38 is None:
            node38 = models.Node(id=38)
            session.add(node38)
                  
        node37.location = masterLoc
        node38.location = secondLoc
        session.flush()

        #All Our Data adding script needs to worry about is the Nodes
        self.node37 = node37
        self.node38 = node38

        #Finally add an Upload URL if required
        # theUrl = session.query(models.UploadURL).filter_by(url="[email protected]").first()
        # if not theUrl:
        #     theUrl = models.UploadURL(url="[email protected]",
        #                               dburl="mysql://*****:*****@localhost:3307/pushTest")
        #     session.add(theUrl)
        
        # theUrl = session.query(models.UploadURL).filter_by(url="*****@*****.**").first()
        # if not theUrl:
        #     theUrl = models.UploadURL(url="*****@*****.**",
        #                               dburl="mysql://*****:*****@localhost:3307/chtest")
        #     session.add(theUrl)

        session.commit()
Exemplo n.º 8
0
"""
Utility Function to remove all data from a given DB
"""

#DBURL = ['mysql://*****:*****@localhost/pushTest',
#         'mysql://*****:*****@localhost/pushSource']

DBURL = ['mysql://*****:*****@127.0.0.1:3307/chtest']

#DBURL = ['mysql://*****:*****@localhost/pushTest']


import sqlalchemy
import cogent.base.model as models
import cogent.base.model.meta as meta

for url in DBURL:
    engine = sqlalchemy.create_engine(url)

    models.initialise_sql(engine,True)
    models.populate_data()