Esempio n. 1
0
 def setup(self):  # Run independently for every testcast
     self.cep = EsperEngine("TestCountSounds")
     self.cep.define_event(
         'SoundGroup', {
             'timestamp': java.lang.String,
             'mac': java.lang.String,
             'soundlevel': java.lang.String
         })
     self.cep.define_event('CountSounds', {
         'mac': java.lang.String,
         'nsg': java.lang.Long
     })
     self.mocklisten = Mock()
     self.qman = QueryManager(self.cep)
     qa = queries.QueryCountSounds(self.TWIN)
     self.qman.addQuery(qa.getQueries(), self.mocklisten)
Esempio n. 2
0
 def setup(self):  # Run independently for every testcast
     self.cep = EsperEngine("TestAvgFacecount")
     self.cep.define_event(
         'Facecount',
         {
             'timestamp': java.lang.String,  # ISO 8601
             'mac': java.lang.String,
             'facecount': java.lang.Float
         })
     self.cep.define_event('AvgFacecount', {
         'facecount': java.lang.Float,
         'avgfacecount': java.lang.Double
     })
     self.mocklisten = Mock()
     self.qman = QueryManager(self.cep)
     qa = queries.QueryFacecount(4)
     self.qman.addQuery(qa.getQueries(), self.mocklisten)
Esempio n. 3
0
 def setup(self):  # Run independently for every testcast
     self.cep = EsperEngine("TestAnomalous")
     self.cep.define_event(
         'Anomalous_Sound', {
             'timestamp': java.lang.String,
             'mac': java.lang.String,
             'soundlevel': java.lang.String
         })
     self.cep.define_event(
         'SoundGroup', {
             'timestamp': java.lang.String,
             'mac': java.lang.String,
             'soundlevel': java.lang.String
         })
     self.mocklisten = Mock()
     self.qman = QueryManager(self.cep)
     qa = queries.QueryAnomalousSound()
     self.qman.addQuery(qa.getQueries(), self.mocklisten)
Esempio n. 4
0
 def setup(self):  # Run independently for every testcase
     self.cep = EsperEngine("TestBusy")
     self.cep.define_event(
         'Busy', {
             'avgfacecount': java.lang.Double,
             'nsg1': java.lang.Long,
             'nsg2': java.lang.Long,
             'busylevel': java.lang.Double
         })
     self.cep.define_event('AvgFacecount', {
         'facecount': java.lang.Float,
         'avgfacecount': java.lang.Double
     })
     self.cep.define_event('CountSounds', {
         'mac': java.lang.String,
         'nsg': java.lang.Long
     })
     self.mocklisten = Mock()
     self.qman = QueryManager(self.cep)
     qa = queries.QueryBusy(100)
     self.qman.addQuery(qa.getQueries(), self.mocklisten)
Esempio n. 5
0
 def setup(self):   # Run independently for every testcast
     self.cep = EsperEngine("TestAvgFacecount")
     self.cep.define_event('Facecount', { 
         'timestamp': java.lang.String, # ISO 8601
         'mac': java.lang.String,
         'facecount': java.lang.Float }
         )
     self.cep.define_event('AvgFacecount', { 
         'facecount': java.lang.Float,
         'avgfacecount': java.lang.Double
         })
     self.mocklisten = Mock()
     self.qman = QueryManager(self.cep)
     qa = queries.QueryFacecount(4)
     self.qman.addQuery(qa.getQueries(), self.mocklisten)
Esempio n. 6
0
 def setup(self):   # Run independently for every testcast
     self.cep = EsperEngine("TestCountSounds")
     self.cep.define_event('SoundGroup', { 
         'timestamp': java.lang.String,
         'mac': java.lang.String,
         'soundlevel': java.lang.String }
         )
     self.cep.define_event('CountSounds', { 
         'mac': java.lang.String,
         'nsg': java.lang.Long }
         )
     self.mocklisten = Mock()
     self.qman = QueryManager(self.cep)
     qa = queries.QueryCountSounds(self.TWIN)
     self.qman.addQuery(qa.getQueries(), self.mocklisten)
Esempio n. 7
0
 def setup(self):   # Run independently for every testcast
     self.cep = EsperEngine("TestAnomalous")
     self.cep.define_event('Anomalous_Sound', {
         'timestamp': java.lang.String,
         'mac': java.lang.String,
         'soundlevel': java.lang.String }
         )
     self.cep.define_event('SoundGroup', { 
         'timestamp': java.lang.String,
         'mac': java.lang.String,
         'soundlevel': java.lang.String }
         )
     self.mocklisten = Mock()
     self.qman = QueryManager(self.cep)
     qa = queries.QueryAnomalousSound()
     self.qman.addQuery(qa.getQueries(), self.mocklisten)
Esempio n. 8
0
 def setup(self):   # Run independently for every testcase
     self.cep = EsperEngine("TestBusy")
     self.cep.define_event('Busy', { 
         'avgfacecount': java.lang.Double,
         'nsg1': java.lang.Long,
         'nsg2': java.lang.Long,
         'busylevel': java.lang.Double
         })
     self.cep.define_event('AvgFacecount', { 
         'facecount': java.lang.Float,
         'avgfacecount': java.lang.Double
         })
     self.cep.define_event('CountSounds', { 
         'mac': java.lang.String,
         'nsg': java.lang.Long 
         })
     self.mocklisten = Mock()
     self.qman = QueryManager(self.cep)
     qa = queries.QueryBusy(100)
     self.qman.addQuery(qa.getQueries(), self.mocklisten)
Esempio n. 9
0
class TestQueryAnomalous(object):

    def setup(self):   # Run independently for every testcast
        self.cep = EsperEngine("TestAnomalous")
        self.cep.define_event('Anomalous_Sound', {
            'timestamp': java.lang.String,
            'mac': java.lang.String,
            'soundlevel': java.lang.String }
            )
        self.cep.define_event('SoundGroup', { 
            'timestamp': java.lang.String,
            'mac': java.lang.String,
            'soundlevel': java.lang.String }
            )
        self.mocklisten = Mock()
        self.qman = QueryManager(self.cep)
        qa = queries.QueryAnomalousSound()
        self.qman.addQuery(qa.getQueries(), self.mocklisten)

            
    def testAnomalous(self):
    #Test SoundGroup (mac1 wel msg1,msg3, geen msg2, mac2 wel msg1, msg2)
        self.cep.send_event({
            'timestamp': 'msg1',
            'mac': 'mac1',
            'soundlevel': '0.5'}, 'Anomalous_Sound')
        self.cep.send_event({
            'timestamp': 'msg1',
            'mac': 'mac2',
            'soundlevel': '0.6'}, 'Anomalous_Sound')
        time.sleep(2.1)
        self.cep.send_event({
            'timestamp': 'msg2',
            'mac': 'mac2',
            'soundlevel': '0.7'}, 'Anomalous_Sound')
        self.cep.send_event({
            'timestamp': 'msg2',
            'mac': 'mac1',
            'soundlevel': '0.8'}, 'Anomalous_Sound')
        time.sleep(0.1)
        self.cep.send_event({
            'timestamp': 'msg3',
            'mac': 'mac1',
            'soundlevel': '0.9'}, 'Anomalous_Sound')
        time.sleep(2.1)
        print self.mocklisten.mock_calls
        results = re.findall("soundlevel': u'(.*?)'", 
                          str(self.mocklisten.mock_calls))
        assert results[0] == '0.5'
        assert results[1] == '0.6' 
        assert results[2] == '0.7' 
        assert results[3] == '0.9'
Esempio n. 10
0
class TestQueryFacecount(object):
    def setup(self):   # Run independently for every testcast
        self.cep = EsperEngine("TestAvgFacecount")
        self.cep.define_event('Facecount', { 
            'timestamp': java.lang.String, # ISO 8601
            'mac': java.lang.String,
            'facecount': java.lang.Float }
            )
        self.cep.define_event('AvgFacecount', { 
            'facecount': java.lang.Float,
            'avgfacecount': java.lang.Double
            })
        self.mocklisten = Mock()
        self.qman = QueryManager(self.cep)
        qa = queries.QueryFacecount(4)
        self.qman.addQuery(qa.getQueries(), self.mocklisten)

            
    def testFacecount1(self):
    #Test AvgFacecount (met 0, 1 en 3 berichten)
        self.cep.send_event({
            'timestamp': '2014-07-07T11:22:33',
            'mac': 'macf',
            'facecount': 10.}, 'Facecount')
        time.sleep(5)
        self.cep.send_event({
            'timestamp': '2014-07-07T11:22:33',
            'mac': 'macf',
            'facecount': 1}, 'Facecount')
        self.cep.send_event({
            'timestamp': '2014-07-07T11:22:33',
            'mac': 'macf',
            'facecount': 3}, 'Facecount')
        self.cep.send_event({
            'timestamp': '2014-07-07T11:22:33',
            'mac': 'macf',
            'facecount': 8}, 'Facecount')
        time.sleep(4)
        print self.mocklisten.mock_calls
        # Possibly simpler with json.loads
        results = re.findall("avgfacecount': (.*?)}", 
                          str(self.mocklisten.mock_calls))
        assert results[0] == '10.0'
        assert results[2] == '4.0'
Esempio n. 11
0
class testQueryBusy(object):
    
    def setup(self):   # Run independently for every testcase
        self.cep = EsperEngine("TestBusy")
        self.cep.define_event('Busy', { 
            'avgfacecount': java.lang.Double,
            'nsg1': java.lang.Long,
            'nsg2': java.lang.Long,
            'busylevel': java.lang.Double
            })
        self.cep.define_event('AvgFacecount', { 
            'facecount': java.lang.Float,
            'avgfacecount': java.lang.Double
            })
        self.cep.define_event('CountSounds', { 
            'mac': java.lang.String,
            'nsg': java.lang.Long 
            })
        self.mocklisten = Mock()
        self.qman = QueryManager(self.cep)
        qa = queries.QueryBusy(100)
        self.qman.addQuery(qa.getQueries(), self.mocklisten)

    def testBusy(self):
        #Test Busy (met 1,1,1 en 3,49,99)
        self.cep.send_event({
            'facecount': 4.,
            'avgfacecount': 1.}, 'AvgFacecount')
        self.cep.send_event({
            'mac': 'mac1',
            'nsg': 1}, 'CountSounds')
        self.cep.send_event({
            'mac': 'mac2',
            'nsg': 1}, 'CountSounds')
        time.sleep(4.5)
        self.cep.send_event({
            'facecount': 4.,
            'avgfacecount': 3.}, 'AvgFacecount')
        self.cep.send_event({
            'mac': 'mac1',
            'nsg': 49}, 'CountSounds')
        self.cep.send_event({
            'mac': 'mac2',
            'nsg': 99}, 'CountSounds')
        time.sleep(0.5)
        print self.mocklisten.mock_calls
        results = re.findall("busylevel': (.*?)}", 
                          str(self.mocklisten.mock_calls))
        assert results[0] == '50000.0'
Esempio n. 12
0
class TestQueryAnomalous(object):
    def setup(self):  # Run independently for every testcast
        self.cep = EsperEngine("TestAnomalous")
        self.cep.define_event(
            'Anomalous_Sound', {
                'timestamp': java.lang.String,
                'mac': java.lang.String,
                'soundlevel': java.lang.String
            })
        self.cep.define_event(
            'SoundGroup', {
                'timestamp': java.lang.String,
                'mac': java.lang.String,
                'soundlevel': java.lang.String
            })
        self.mocklisten = Mock()
        self.qman = QueryManager(self.cep)
        qa = queries.QueryAnomalousSound()
        self.qman.addQuery(qa.getQueries(), self.mocklisten)

    def testAnomalous(self):
        #Test SoundGroup (mac1 wel msg1,msg3, geen msg2, mac2 wel msg1, msg2)
        self.cep.send_event(
            {
                'timestamp': 'msg1',
                'mac': 'mac1',
                'soundlevel': '0.5'
            }, 'Anomalous_Sound')
        self.cep.send_event(
            {
                'timestamp': 'msg1',
                'mac': 'mac2',
                'soundlevel': '0.6'
            }, 'Anomalous_Sound')
        time.sleep(2.1)
        self.cep.send_event(
            {
                'timestamp': 'msg2',
                'mac': 'mac2',
                'soundlevel': '0.7'
            }, 'Anomalous_Sound')
        self.cep.send_event(
            {
                'timestamp': 'msg2',
                'mac': 'mac1',
                'soundlevel': '0.8'
            }, 'Anomalous_Sound')
        time.sleep(0.1)
        self.cep.send_event(
            {
                'timestamp': 'msg3',
                'mac': 'mac1',
                'soundlevel': '0.9'
            }, 'Anomalous_Sound')
        time.sleep(2.1)
        print self.mocklisten.mock_calls
        results = re.findall("soundlevel': u'(.*?)'",
                             str(self.mocklisten.mock_calls))
        assert results[0] == '0.5'
        assert results[1] == '0.6'
        assert results[2] == '0.7'
        assert results[3] == '0.9'
Esempio n. 13
0
class TestQueryFacecount(object):
    def setup(self):  # Run independently for every testcast
        self.cep = EsperEngine("TestAvgFacecount")
        self.cep.define_event(
            'Facecount',
            {
                'timestamp': java.lang.String,  # ISO 8601
                'mac': java.lang.String,
                'facecount': java.lang.Float
            })
        self.cep.define_event('AvgFacecount', {
            'facecount': java.lang.Float,
            'avgfacecount': java.lang.Double
        })
        self.mocklisten = Mock()
        self.qman = QueryManager(self.cep)
        qa = queries.QueryFacecount(4)
        self.qman.addQuery(qa.getQueries(), self.mocklisten)

    def testFacecount1(self):
        #Test AvgFacecount (met 0, 1 en 3 berichten)
        self.cep.send_event(
            {
                'timestamp': '2014-07-07T11:22:33',
                'mac': 'macf',
                'facecount': 10.
            }, 'Facecount')
        time.sleep(5)
        self.cep.send_event(
            {
                'timestamp': '2014-07-07T11:22:33',
                'mac': 'macf',
                'facecount': 1
            }, 'Facecount')
        self.cep.send_event(
            {
                'timestamp': '2014-07-07T11:22:33',
                'mac': 'macf',
                'facecount': 3
            }, 'Facecount')
        self.cep.send_event(
            {
                'timestamp': '2014-07-07T11:22:33',
                'mac': 'macf',
                'facecount': 8
            }, 'Facecount')
        time.sleep(4)
        print self.mocklisten.mock_calls
        # Possibly simpler with json.loads
        results = re.findall("avgfacecount': (.*?)}",
                             str(self.mocklisten.mock_calls))
        assert results[0] == '10.0'
        assert results[2] == '4.0'
Esempio n. 14
0
class testQueryBusy(object):
    def setup(self):  # Run independently for every testcase
        self.cep = EsperEngine("TestBusy")
        self.cep.define_event(
            'Busy', {
                'avgfacecount': java.lang.Double,
                'nsg1': java.lang.Long,
                'nsg2': java.lang.Long,
                'busylevel': java.lang.Double
            })
        self.cep.define_event('AvgFacecount', {
            'facecount': java.lang.Float,
            'avgfacecount': java.lang.Double
        })
        self.cep.define_event('CountSounds', {
            'mac': java.lang.String,
            'nsg': java.lang.Long
        })
        self.mocklisten = Mock()
        self.qman = QueryManager(self.cep)
        qa = queries.QueryBusy(100)
        self.qman.addQuery(qa.getQueries(), self.mocklisten)

    def testBusy(self):
        #Test Busy (met 1,1,1 en 3,49,99)
        self.cep.send_event({
            'facecount': 4.,
            'avgfacecount': 1.
        }, 'AvgFacecount')
        self.cep.send_event({'mac': 'mac1', 'nsg': 1}, 'CountSounds')
        self.cep.send_event({'mac': 'mac2', 'nsg': 1}, 'CountSounds')
        time.sleep(4.5)
        self.cep.send_event({
            'facecount': 4.,
            'avgfacecount': 3.
        }, 'AvgFacecount')
        self.cep.send_event({'mac': 'mac1', 'nsg': 49}, 'CountSounds')
        self.cep.send_event({'mac': 'mac2', 'nsg': 99}, 'CountSounds')
        time.sleep(0.5)
        print self.mocklisten.mock_calls
        results = re.findall("busylevel': (.*?)}",
                             str(self.mocklisten.mock_calls))
        assert results[0] == '50000.0'
Esempio n. 15
0
class testQueryCountSounds(object):

    TWIN = 4

    def setup(self):  # Run independently for every testcast
        self.cep = EsperEngine("TestCountSounds")
        self.cep.define_event(
            'SoundGroup', {
                'timestamp': java.lang.String,
                'mac': java.lang.String,
                'soundlevel': java.lang.String
            })
        self.cep.define_event('CountSounds', {
            'mac': java.lang.String,
            'nsg': java.lang.Long
        })
        self.mocklisten = Mock()
        self.qman = QueryManager(self.cep)
        qa = queries.QueryCountSounds(self.TWIN)
        self.qman.addQuery(qa.getQueries(), self.mocklisten)

    def testCountSounds(self):
        #Test Countsounds (met 0, 1 en 3 events)
        time.sleep(self.TWIN + 0.5)
        self.cep.send_event(
            {
                'timestamp': 'msg',
                'mac': 'mac1',
                'soundlevel': '0.5'
            }, 'SoundGroup')
        time.sleep(self.TWIN + 0.5)
        self.cep.send_event(
            {
                'timestamp': 'msg',
                'mac': 'mac2',
                'soundlevel': '0.5'
            }, 'SoundGroup')
        self.cep.send_event(
            {
                'timestamp': 'msg',
                'mac': 'mac1',
                'soundlevel': '0.5'
            }, 'SoundGroup')
        self.cep.send_event(
            {
                'timestamp': 'msg',
                'mac': 'mac1',
                'soundlevel': '0.5'
            }, 'SoundGroup')
        self.cep.send_event(
            {
                'timestamp': 'msg',
                'mac': 'mac1',
                'soundlevel': '0.5'
            }, 'SoundGroup')
        time.sleep(self.TWIN + 0.5)
        print self.mocklisten.mock_calls
        results = re.findall("nsg': (.*?)L", str(self.mocklisten.mock_calls))
        assert results[0] == '1'  # mac1 in second window
        assert results[1] == '0'  # mac1 out of first window

        assert results[2] == '1'  # mac2 in third window
        assert results[3] == '3'  # mac1 in third window
        assert results[4] == '0'  # mac2 out of second window
        assert results[5] == '1'  # mac1 out of second window
Esempio n. 16
0
class testQueryCountSounds(object):
    
    TWIN = 4
    
    def setup(self):   # Run independently for every testcast
        self.cep = EsperEngine("TestCountSounds")
        self.cep.define_event('SoundGroup', { 
            'timestamp': java.lang.String,
            'mac': java.lang.String,
            'soundlevel': java.lang.String }
            )
        self.cep.define_event('CountSounds', { 
            'mac': java.lang.String,
            'nsg': java.lang.Long }
            )
        self.mocklisten = Mock()
        self.qman = QueryManager(self.cep)
        qa = queries.QueryCountSounds(self.TWIN)
        self.qman.addQuery(qa.getQueries(), self.mocklisten)

    def testCountSounds(self):
    #Test Countsounds (met 0, 1 en 3 events)
        time.sleep(self.TWIN + 0.5)
        self.cep.send_event({
            'timestamp': 'msg',
            'mac': 'mac1',
            'soundlevel': '0.5'}, 'SoundGroup')
        time.sleep(self.TWIN + 0.5)
        self.cep.send_event({
            'timestamp': 'msg',
            'mac': 'mac2',
            'soundlevel': '0.5'}, 'SoundGroup')
        self.cep.send_event({
            'timestamp': 'msg',
            'mac': 'mac1',
            'soundlevel': '0.5'}, 'SoundGroup')
        self.cep.send_event({
            'timestamp': 'msg',
            'mac': 'mac1',
            'soundlevel': '0.5'}, 'SoundGroup')
        self.cep.send_event({
            'timestamp': 'msg',
            'mac': 'mac1',
            'soundlevel': '0.5'}, 'SoundGroup')
        time.sleep(self.TWIN + 0.5)
        print self.mocklisten.mock_calls
        results = re.findall("nsg': (.*?)L", 
                          str(self.mocklisten.mock_calls))
        assert results[0] == '1'  # mac1 in second window
        assert results[1] == '0'  # mac1 out of first window
        
        assert results[2] == '1'  # mac2 in third window
        assert results[3] == '3'  # mac1 in third window
        assert results[4] == '0'  # mac2 out of second window
        assert results[5] == '1'  # mac1 out of second window
Esempio n. 17
0
    sys.path.append('../jars/cglib-nodep-2.2.jar')
    sys.path.append('../jars/commons-logging-1.1.1.jar')
    sys.path.append('../jars/antlr-runtime-3.2.jar')
    
    #sys.path.append('../../py/bogusd')
    
    import random
    import java.util.Map as Map
    import java.lang.Double 
    from jython_utils import jfloat
    from jycep import EsperEngine
    from jycep import EsperStatement
    from jycep import EventListener
    #import bogusd

    cep = EsperEngine("TestEngine")
    
    cep.define_event("BogusEvent", {"P1": jfloat, 
                                    "P2": jfloat,
                                    "P3": jfloat, 
                                    "P4": jfloat})

    #datagen = bogusd.Generator()
    #datagen.append(bogusd.Point('P1'))
    #datagen.append(bogusd.Point('P2'))
    #datagen.append(bogusd.Point('P3'))
    #datagen.append(bogusd.Point('P4'))

    def callback(data_new, data_old):
        print("New Data:" + str(data_new))
        print("Old Data:" + str(data_old))
Esempio n. 18
0
from jycep import EsperStatement
from jycep import EventListener

config = {
    'host': HOSTNAME,
    'port': PORT,
    'db': DB,
    'password': PASSWORD 
    }

r = redis.StrictRedis(**config)

pubsub = r.pubsub()
pubsub.subscribe("Events")

cep = EsperEngine("CEPEngine")

cep.define_event("Events", {"eventlog_id": jint,
                            "Status": jstr,
                            "TargetUserName": jstr,
                            "syslog_message": jstr,
                            "syslog_hostname": jstr,
                            "syslog_program": jstr})

def callback(stmtname, data_new, data_old):
    print "#" * 30
    print "\n%s" % stmtname
    if data_old:
        print("Old Data:" + str(data_old))
    if data_new:
        print("New Data:" + str(data_new))