Example #1
0
def main():
    backend = Backend()
    if False:  # If test mode
        test_harness = TestHarness()
        for test in TEST_CASES:
            test_harness.test_transaction(**test)

    else:
        backend.run()
Example #2
0
 def test_setup(self):
     """
     Setup method should return in this case the default setup json loaded previously
     """
     with mock.patch("usb.core.find"):
         b = Backend()
     setup_from_backend = b.setup()
     with open(setup_file.DEFAULT_CONFIG_FILE_NAME) as file:
         default_setup = json.load(file)
     assert setup_from_backend == default_setup
     b.stop()
Example #3
0
    def run(self, dispatcher, tracker, domain):
        #dispatcher.utter_message("QueryVeranstaltung started")
        vtype = tracker.get_slot('vtype')
        genre = tracker.get_slot('genre')
        time = tracker.get_slot('time')
        sql = "SELECT * FROM veranstaltung WHERE "
        if vtype is None:
            #dispatcher.utter_message("Vtype none")
            return
        sql += "vtype == '" + vtype + "' "
        if genre is not None:

            sql += " AND genre == '" + genre + "' "
        if time is not None:
            timesql = self.time_helper(time)
            print("time", time)
            print("timesql", timesql[19:29])
            sql += " AND date == '" + timesql[19:29] + "' "
        sql += " LIMIT 100;"
        # sql = "SELECT t.* From veranstaltung t WHERE date == slots['date'] AND genre == slots['genre'] AND vtype == slots['vtype'] LIMIT 100";
        be = Backend()
        res = be.eval(sql)
        if len(res) == 0:
            # dispatcher.utter_template("utter_")
            dispatcher.utter_template("utter_nothing_found")

        elif len(res) == 1:
            dispatcher.utter_template("utter_one_found")
            dispatcher.utter_message(str(res))
            result = res[0]
            dispatcher.utter_template("utter_result",
                                      filled_slots=None,
                                      name=result[0],
                                      vtype=result[1],
                                      time=result[3],
                                      genre=result[2])
        elif len(res) > 1 & len(res) < 100:
            dispatcher.utter_template("utter_more_found")
            for result in res:
                dispatcher.utter_template("utter_result",
                                          filled_slots=None,
                                          name=result[0],
                                          vtype=result[1],
                                          time=result[3],
                                          genre=result[2])
                print(res)
        ## else:
        tracker._reset()
        print('reset')
        pass
Example #4
0
    def test_run_backend(self):
        with mock.patch("usb.core.find"), mock.patch(
                "devices.kpro.kpro.Kpro.__init__") as m___init__:
            # mocking kpro device since for tests is not available
            m___init__.return_value = None

            assert type(Backend.get()) == Backend
Example #5
0
 def test_stop(self):
     """
     You should be able to run the backend twice without any problem calling stop() between them
     """
     with mock.patch("usb.core.find"):
         b = Backend()
         b.stop()
         b = Backend()
         b.stop()
Example #6
0
def init(config_file="backend/config.json"):
    config=json.load(open(config_file,"r"))
    global __bked__
    if "fake_backend" in config and config["fake_backend"]:
        import backend.fake_backend
        __bked__=backend.fake_backend
        __bked__.init(config)
    else:
        from backend.backend import Backend
        __bked__=Backend(config)
Example #7
0
    def test_update(self):
        expected_data = {
            "bat": 0.0,
            "gear": "N",
            "iat": 0,
            "tps": 0,
            "ect": 0,
            "rpm": 0,
            "vss": 0,
            "o2": 0,
            "cam": 0,
            "mil": False,
            "fan": False,
            "bksw": False,
            "flr": False,
            "eth": 0,
            "scs": False,
            "fmw": "0.00",
            "map": 0,
            "an0": 104,
            "an1": 205.7905145,
            "an2": 205.7905145,
            "an3": 205.7905145,
            "an4": 205.7905145,
            "an5": 205.7905145,
            "an6": 205.7905145,
            "an7": 205.7905145,
            "time": "00:00:00",
            "odo": 0,
            "style": "day",
            "ver": "2.4.0",
        }

        with mock.patch("usb.core.find"), mock.patch(
                "usb.util.find_descriptor"), mock.patch(
                    "backend.backend.Websocket.__init__"
                ) as m_ws___init__, mock.patch("threading.Thread.start"):
            # mocking websocket
            m_ws___init__.return_value = None
            backend = Backend()

        assert backend.update() == expected_data
Example #8
0
    def test_run_backend(self):
        with mock.patch("usb.core.find"), mock.patch(
                "threading.Thread.start"), mock.patch(
                    "backend.backend.Websocket.__init__"
                ) as m_ws___init__, mock.patch(
                    "devices.kpro.kpro.Kpro.__init__") as m___init__:
            # mocking kpro device since for tests is not available
            m___init__.return_value = None
            # mocking websocket
            m_ws___init__.return_value = None

            assert type(Backend()) == Backend
Example #9
0
 def test_save(self):
     """
     Save a new setup and retrieve it
     """
     with mock.patch("usb.core.find"):
         b = Backend()
     with open(setup_file.DEFAULT_CONFIG_FILE_NAME) as file:
         default_setup = json.load(file)
     default_setup["tps"]["label"] = "test"
     b.save(default_setup)
     assert b.setup() == default_setup
     b.stop()
Example #10
0
    def test_update(self):
        expected_data = {
            "bat": 0.0,
            "gear": "N",
            "iat": 0,
            "tps": 0,
            "ect": 0,
            "rpm": 0,
            "vss": 0,
            "o2": 0,
            "cam": 0,
            "mil": False,
            "fan": False,
            "bksw": False,
            "flr": False,
            "eth": 0,
            "scs": False,
            "fmw": "0.00",
            "map": 0,
            "an0": 104,
            "an1": 205.7905145,
            "an2": 205.7905145,
            "an3": 205.7905145,
            "an4": 205.7905145,
            "an5": 205.7905145,
            "an6": 205.7905145,
            "an7": 205.7905145,
            "time": "00:00:00",
            "odo": 0,
            "style": "day",
            "ver": "2.4.0",
        }

        with mock.patch("usb.core.find"), mock.patch(
                "usb.util.find_descriptor"), mock.patch(
                    "threading.Thread.start"), mock.patch(
                        "backend.backend.publish") as m_publish:
            backend = Backend.get()
            backend.update()
            m_publish.assert_called_with("data", expected_data)
 def __init__(self): 
     Backend.__init__(self, theflowname, dashboard=True);
Example #12
0
 def __init__(self):
     Backend.__init__(self, theflowname, dashboard=True)
 def __init__(self): 
     # Specify the workflow name:       
     Backend.__init__(self, theflowname)  
Example #14
0
import random
from time import sleep
from unittest import mock

from backend.backend import Backend

with mock.patch("usb.core.find"), mock.patch(
        "devices.kpro.kpro.Kpro.__init__") as m___init__:
    m___init__.return_value = None
    backend = Backend.get()
    backend.kpro.status = True
    backend.kpro.version = 4

    while True:
        backend.kpro.data0 = [random.randint(0, 255) for _ in range(38)]
        backend.kpro.data1 = [random.randint(0, 255) for _ in range(7)]
        backend.kpro.data3 = [random.randint(0, 255) for _ in range(100)]
        backend.kpro.data4 = [random.randint(0, 255) for _ in range(18)]
        backend.kpro.data5 = [random.randint(0, 255) for _ in range(20)]
        backend.update()
        sleep(0.1)  # TODO: not use sleep :(
Example #15
0
 def __init__(self, app_id):
     super(Application, self).__init__(application_id = app_id)
     self.backend = Backend()
Example #16
0
import random

from backend.backend import Backend

backend = Backend()
backend.kpro.status = True
backend.kpro.version = 4

while True:
    backend.kpro.data0 = [random.randint(0, 255) for _ in range(38)]
    backend.kpro.data1 = [random.randint(0, 255) for _ in range(7)]
    backend.kpro.data3 = [random.randint(0, 255) for _ in range(100)]
    backend.kpro.data4 = [random.randint(0, 255) for _ in range(18)]
    backend.kpro.data5 = [random.randint(0, 255) for _ in range(20)]
Example #17
0
if args.debug:
    import ptvsd
    ptvsd.enable_attach(address=('192.168.178.27', 1337), redirect_output=True)
    ptvsd.wait_for_attach()

config = configparser.ConfigParser()
config.read("config.ini")
# TODO: make dynamic
# TODO: validate
# TODO: make sensor ports configurable

print("Started kckr for location: %s" % (config["device"]["location"]))

sensors = Sensors()
backend = Backend(config)

try:
    num = 0
    occupied = None
    sensors.start()

    while True:
        print("Occupied     %s" % (sensors.occupation.isOccupied))
        if sensors.air.hasValues():
            print("Temperature  %.02f°C" % (sensors.air.temperature))
            print("Humidity     %.02f%%" % (sensors.air.humidity))
        num += 1

        if occupied != sensors.occupation.isOccupied:
            occupied = sensors.occupation.isOccupied
 def __init__(self):
     # Specify the workflow name:
     Backend.__init__(self, theflowname)
Example #19
0
import sys
from frontend.forms import IRForm, ResForm
sys.path.append("..")
from backend.backend import Backend

back = Backend('tf-idf', 1000000)


def query(form, result, lim=50):
    key = form.keywords.data
    attr = form.attributes.data
    l = form.length.data
    merge = form.merge.data

    if not merge and attr == '':
        attr = 'all'

    if l == None:
        l = -1
    if l <= 0:
        l = -1

    res = back.query(key, attr, l)
    result.data = []
    for i, d in enumerate(res):
        if i > lim:
            break
        result.data.append({
            'index': i,
            'name': d[0],
            'attr': d[1],