예제 #1
0
    def test_stop(self):
        engine = ModelEngine()
        analyzer = TestDataAnalyzerPlugin()
        engine.add_analyzer(analyzer)

        engine.start()

        self.assertEqual(analyzer.num, 0)

        engine.stop()

        self.assertEqual(analyzer.num, -1)
예제 #2
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['DEBUG'] = False
     global_model_engine = ModelEngine()
     self.app = app.test_client()
예제 #3
0
from flask import Flask
import logging
from app.model_engine import ModelEngine

global_model_engine = ModelEngine()
logging.basicConfig(format='[%(levelname)s] %(asctime)s (%(module)s): %(message)s')

from app.plugins.distance_plugin import DistanceAnalyzerPlugin
from app.plugins.graph_plugin import GraphPlugin
from app.plugins.status_plugin import StatusPlugin

app = Flask(__name__)

DATA_ANALYZER_PLUGINS = \
[
    # Put data analyzer plugin instances here
    DistanceAnalyzerPlugin(),
    GraphPlugin(),
    StatusPlugin()
]


for data_analyzer_plugin in DATA_ANALYZER_PLUGINS:
    global_model_engine.add_analyzer(data_analyzer_plugin)

global_model_engine.start()

from app import routes
예제 #4
0
    def test_update_data(self):
        engine = ModelEngine()
        analyzer = TestDataAnalyzerPlugin()
        analyzer2 = TestDataAnalyzerPlugin2()

        engine.add_analyzer(analyzer)
        engine.add_analyzer(analyzer2)

        engine.start()

        self.assertEqual(analyzer.num, 0)
        self.assertIsNone(analyzer.max)

        self.assertEqual(analyzer2.num, 0)
        self.assertSetEqual(analyzer2.nodes, set())
        self.assertIsNone(analyzer2.maxsize)

        data_payload = {'increment': 5}

        engine.update_data(data_payload)

        self.assertEqual(analyzer.num, 5)
        self.assertIsNone(analyzer.max)

        self.assertEqual(analyzer2.num, 0)
        self.assertSetEqual(analyzer2.nodes, set())
        self.assertIsNone(analyzer2.maxsize)

        data_payload = {'node_id': 2}

        engine.update_data(data_payload)

        self.assertEqual(analyzer.num, 5)
        self.assertIsNone(analyzer.max)

        self.assertEqual(analyzer2.num, 0)
        self.assertSetEqual(analyzer2.nodes, set((2, )))
        self.assertIsNone(analyzer2.maxsize)

        data_payload = {'node_id': 5, 'extra': 1, 'increment': 4}

        engine.update_data(data_payload)

        self.assertEqual(analyzer.num, 9)
        self.assertIsNone(analyzer.max)

        self.assertEqual(analyzer2.num, 1)
        self.assertSetEqual(analyzer2.nodes, set((2, 5)))
        self.assertIsNone(analyzer2.maxsize)

        engine.stop()

        self.assertEqual(analyzer.num, -1)
        self.assertIsNone(analyzer.max)

        self.assertEqual(analyzer2.num, 1)
        self.assertSetEqual(analyzer2.nodes, set())
        self.assertIsNone(analyzer2.maxsize)
예제 #5
0
    def test_collect(self):
        engine = ModelEngine()
        analyzer = TestDataAnalyzerPlugin()
        analyzer2 = TestDataAnalyzerPlugin2()

        engine.add_analyzer(analyzer)
        engine.add_analyzer(analyzer2)

        engine.start()

        self.assertEqual(analyzer.num, 0)
        self.assertIsNone(analyzer.max)

        self.assertEqual(analyzer2.num, 0)
        self.assertSetEqual(analyzer2.nodes, set())
        self.assertIsNone(analyzer2.maxsize)

        data_payload = {'increment': 5}

        engine.update_data(data_payload)

        self.assertEqual(analyzer.num, 5)
        self.assertIsNone(analyzer.max)

        self.assertEqual(analyzer2.num, 0)
        self.assertSetEqual(analyzer2.nodes, set())
        self.assertIsNone(analyzer2.maxsize)

        data_payload = {'node_id': 2}

        engine.update_data(data_payload)

        self.assertEqual(analyzer.num, 5)
        self.assertIsNone(analyzer.max)

        self.assertEqual(analyzer2.num, 0)
        self.assertSetEqual(analyzer2.nodes, set((2, )))
        self.assertIsNone(analyzer2.maxsize)

        data_payload = {'node_id': 5, 'extra': 1, 'increment': 4}
        constraint_payload = {'max': 8, 'maxsize': 1}

        engine.update_constraint(constraint_payload)
        engine.update_data(data_payload)

        self.assertEqual(analyzer.num, 8)
        self.assertEqual(analyzer.max, 8)

        self.assertEqual(analyzer2.num, 0)
        self.assertSetEqual(analyzer2.nodes, set((2, )))
        self.assertEqual(analyzer2.maxsize, 1)

        self.assertDictEqual(engine.collect(), {'nodes': [2], 'num': 8})

        engine.stop()

        self.assertEqual(analyzer.num, -1)
        self.assertEqual(analyzer.max, 8)

        self.assertEqual(analyzer2.num, 0)
        self.assertSetEqual(analyzer2.nodes, set())
        self.assertEqual(analyzer2.maxsize, 1)
예제 #6
0
    def test_add_analyzer(self):
        engine = ModelEngine()
        analyzer = TestDataAnalyzerPlugin()
        engine.add_analyzer(analyzer)

        self.assertListEqual(engine.analyzers, [analyzer])
예제 #7
0
    def test_constructor(self):
        engine = ModelEngine()

        self.assertListEqual(engine.analyzers, [])