Beispiel #1
0
def test_get_value_matrix():
    manager = Manager()

    manager.matrix.get_value_matrix = MagicMock()

    manager.get_value_matrix()

    manager.matrix.get_value_matrix.assert_called_with()
Beispiel #2
0
def test_get_relationships_by_value_range():
    manager = Manager()

    manager.matrix.get_relationships_by_value_range = MagicMock()

    manager.get_relationships_by_value_range(0.5, 1)

    manager.matrix.get_relationships_by_value_range.assert_called_with(0.5, 1)
Beispiel #3
0
def test_get_all_relationship():
    manager = Manager()
    sensor1 = Sensor()
    sensor2 = Sensor()

    manager.add_sensor(sensor1)
    manager.add_sensor(sensor2)

    assert manager.get_all_relationships() is not None
Beispiel #4
0
def test_get_relationship_from_sensors():
    manager = Manager()
    sensor1 = Sensor()
    sensor2 = Sensor()

    manager.matrix.get_relationship_from_sensors = MagicMock()
    manager.get_relationship_from_sensors(sensor1, sensor2)

    manager.matrix.get_relationship_from_sensors.assert_called_with(sensor1,
                                                                    sensor2)
def get_manager_and_sensor_data_from_cvs(filename):
    # List of (datetime, value) but datetime is still a string
    sensors_data = []

    with open(filename, newline='') as csvfile:
        csvreader = csv.reader(csvfile)
        for row in csvreader:
            sensors_data.append(row)

    manager = Manager()
    for _ in range(len(sensors_data)):
        sensor = Sensor()
        manager.add_sensor(sensor)

    return manager, sensors_data
def test_integration():

    sensors = [Sine(), Cosine()]

    # Setup Engine
    ae = Manager()
    ae.add_sensor(sensors[0])
    ae.add_sensor(sensors[1])

    # Simulate a user's Program Loop
    for time in range(36):
        for sensor in sensors:
            sensor.tick(time / 10.0)

    # It didn't break
    assert True
Beispiel #7
0
def test_should_use_changed_time_window_for_snapshot_after_change():
    manager = Manager()
    manager.on_data = MagicMock()
    snapper = Snapper(manager)
    sensor1 = Sensor()
    snapper.add_sensor(sensor1)
    sensor1.publish(2, 1)

    # Change window size in middle of data transmission
    snapper.set_window_size(15.0)

    sensor2 = Sensor()
    snapper.add_sensor(sensor2)
    sensor2.publish(3, 1)
    # Force a snapshot publish by pushing value with time past original window
    sensor2.publish(3, 11)

    # Should finish original window and push the resulting snapshot before
    # transitioning
    manager.on_data.assert_called_with({
        'start': 1,
        'end': 10,
        sensor1.uuid: 2,
        sensor2.uuid: 3
    })

    # Push values within the new window
    sensor1.publish(3, 15)
    sensor2.publish(5, 16)

    # Force a snapshot push by publishing out of bounds data
    sensor1.publish(3, 26)

    manager.on_data.assert_called_with({
        'start': 10,
        'end': 24,
        sensor1.uuid: 3,
        sensor2.uuid: 4
    })
Beispiel #8
0
def test_should_forward_snapshot_once_data_complete():
    manager = Manager()
    manager.on_data = MagicMock()
    snapper = Snapper(manager)
    sensor1 = Sensor()
    snapper.add_sensor(sensor1)
    sensor1.publish(2, 1)
    sensor2 = Sensor()
    snapper.add_sensor(sensor2)
    sensor2.publish(3, 1)

    startTime = snapper.windowStart
    endTime = snapper.windowEnd

    # Force a snapshot publish by pushing value with time past window
    sensor2.publish(3, 11)

    manager.on_data.assert_called_with({
        "start": startTime,
        "end": endTime,
        sensor1.uuid: 2,
        sensor2.uuid: 3
    })
Beispiel #9
0
def test_should_call_set_window_size_on_snapper():
    manager = Manager()
    manager.snapper.set_window_size = MagicMock()

    manager.set_window_size(20.0)
    manager.snapper.set_window_size.assert_called_with(20.0)

    manager.set_window_size(30.0)
    manager.snapper.set_window_size.assert_called_with(30.0)
Beispiel #10
0
def test_add_and_remove_sensor_variable_pair():
    manager = Manager()
    sensor = Sensor()
    manager.add_sensor(sensor)

    assert manager.sensors == [sensor]
    assert isinstance(manager.variables[0], Variable)
    assert isinstance(manager.route_map[sensor.uuid], Variable)

    manager.remove_sensor(sensor)

    assert manager.sensors == []
    assert manager.variables == []
    assert manager.route_map == {}
Beispiel #11
0
def test_push_snapshot():
    manager = Manager()
    sensor1 = Sensor()
    sensor2 = Sensor()
    manager.add_sensor(sensor1)
    manager.add_sensor(sensor2)

    variable1 = manager.route_map[sensor1.uuid]
    variable2 = manager.route_map[sensor2.uuid]

    variable1.on_data = MagicMock()
    variable2.on_data = MagicMock()

    snapshot = {"start": 20, "end": 40, sensor1.uuid: 1, sensor2.uuid: 2}

    manager.on_data(snapshot)

    variable1.on_data.assert_called_with(1, 20, 40)
    variable2.on_data.assert_called_with(2, 20, 40)
Beispiel #12
0
def test_add_multiple_sensors():
    manager = Manager()
    sensor1 = Sensor()
    sensor2 = Sensor()
    manager.add_sensor(sensor1)
    manager.add_sensor(sensor2)

    assert manager.sensors == [sensor1, sensor2]
    assert isinstance(manager.variables[0], Variable)
    assert isinstance(manager.variables[1], Variable)
    assert isinstance(manager.route_map[sensor1.uuid], Variable)
    assert isinstance(manager.route_map[sensor2.uuid], Variable)

    manager.remove_sensor(sensor1)
    manager.remove_sensor(sensor2)

    assert manager.sensors == []
    assert manager.variables == []
    assert manager.route_map == {}
Beispiel #13
0
import datetime
import json
from threading import Thread
from time import sleep

from flask import Flask, send_file
from flask_socketio import SocketIO

from AssociationEngine.Examples.webpage.ReadFromCSV import formatted_csv_reader
from AssociationEngine.Examples.webpage.Subscriber import \
    RelationshipSubscriber
from AssociationEngine.Sensor.Sensor import Sensor
from AssociationEngine.Snapper.Manager import Manager

AEManager = Manager()
AEManager.set_window_size(20000)
app = Flask(__name__, static_folder='dist', static_url_path='')
app.debug = True
io = SocketIO(app, logger=True, debug=True, async_mode="eventlet")
ticker = None
subscribers = []


def subscribe_sensors():
    if subscribers == []:
        relationships = AEManager.get_all_relationships()
        print(relationships)
        for sensor_x, sensor_y in relationships:
            subscriber = RelationshipSubscriber(
                str(AEManager.reverse_route_map[str(sensor_x)]),
                str(AEManager.reverse_route_map[str(sensor_y)]),
Beispiel #14
0
def test_return_matrix():
    manager = Manager()
    matrix = manager.get_matrix()

    assert matrix == manager.matrix
Beispiel #15
0
def test_should_initialize_snapper_and_matrix():
    manager = Manager()
    assert isinstance(manager.snapper, Snapper)
    assert isinstance(manager.matrix, AssociationMatrix)