示例#1
0
 def getObjects(self,where="Devices.last IS NULL"):
     cur=self.db.cursor()
     cur.execute("""
     SELECT objectid, Devices.device,type,instance ,Objects.name,Objects.description
     FROM Objects 
     JOIN Devices USING (deviceID) 
     WHERE %s 
     """% where)
     objects=InstanceList()
     for r in cur:
         objectid,device,otype,oinstance,name,description=r
         o=Instance(device,otype,oinstance)
         o.name=name
         o.id=objectid
         if description != None or description != '':
             o.description=description
         objects.add(o)
         self.instance[(o.device,o.otype,o.oinstance)]=o
         self.objectid[objectid]=o
     cur.close()
     return objects
示例#2
0
    def run(self):
        print "Analysis.run>"
        
        ## main objects
        db=Database()
        graph=Graph()
        
        ## populate meta information
        #devices=data.getDevices()
        objects=db.getObjects()
        building=buildings.PughHall()
        building.tag(objects)
        #building.check(objects)
        
        ## Compute streams
        data=Data('data')
        vav={}
        ahu={}
        total={}
        plot=Plot("plot")
        
        ## Connections 
        source=Connection('source') # data connection
        dest={} ## VAV connections
        output=Connection("output")
        
        ## Connect
        source.addIn(data)

        ## Build network
        ahus=[1,3]
        for ah in ahus:
            zone=objects.getTag('zone',ah) ## All zone objects (VAV and AHU)
            data.addOut(zone)
            
            vavs=zone.getValues('vav')
            total[ah]=Total("total%d" % ah,vavs)
            dest[ah]=Connection("dest%d" % ah)
            dest[ah].addOut(total[ah]) ## zone totalizer

            a=AHU("ahu%d" % ah, ah,objects.getTag('ahu',ah))
            ahu[ah]=a
            source.addOut(a)

            for v in vavs:
                zv=VAV(('zone%d-VAV%s') % (ah,v), zone.getTag('vav',v), objects.getTag('ahu',ah)) ## Zone stream
                vav[v]=zv
                source.addOut(zv)
                dest[ah].addIn(zv)

            ## Per ahu plots
            output.addIn(total[ah])

        ## add trace points
        output.addIn(ahu[1])
        output.addIn(vav[114])

        ## connect plot (last)
        output.addOut(plot)

        if trace:
            print "Analysis.run>", repr(source)
            print "Analysis.run>", repr(dest)
            print "Analysis.run>", repr(total)
            print "Analysis.run>", repr(plot)

        ## Process DataStream
        #limit="WHERE time >= '2011-09-27 20:00' AND time <= '2011-09-27 23:00'"
        #limit="WHERE time >= '2011-09-27 20:00' AND time <= '2011-09-28 07:00'"
        #limit="WHERE time >= '2011-09-27' AND time <= '2011-09-29'"
        limit=None
        
        ## Debug
        monitor=InstanceList()
        
        #monitor.add(objects.getTags({'descriptor':'SAIR-TE'}))
        #monitor.add(objects.getTags({'descriptor':'RAIR-H'}))
        #monitor=monitor.getTag('ahu',1)

        #monitor.add(objects.getTags({'vav':114,'descriptor':'CTL TEMP'}))
        #monitor.add(objects.getTags({'vav':114,'descriptor':'FLOW'}))
        monitor.add(objects.getTags({'vav':114,'descriptor':'HTG LOOPOUT'}))
        #monitor.add(objects.getTags({'vav':114}))

        ## Stream compute
        i=0;
        for time,device,otype,oinstance,value in db.getData(limit):
            v=Value(db.getInstance(device,otype,oinstance),value,time,0) ## Build value
            data.send(v) ## input data
            
            ## Debug
            if v.var in monitor:
                print "DATA:", time, v
            if i%100000==0:
                print "TICK:", i,time
            i+=1
        
        ## Plot
        #limit=None
        #limit=['total1-qsum','total3-qsum']
        limit=['sat','sa']

        graph.add(plot,limit)
        graph.run()