def test_should_return_whole_dict():
    Rxy = SpearframeRelationship(Variable(), Variable())
    Rwz = SpearframeRelationship(Variable(), Variable())
    Am = AssociationMatrix()
    Am.add_relationship(Rxy)
    Am.add_relationship(Rwz)
    key1 = frozenset((Rxy.sensor_x.get_uuid(), Rxy.sensor_y.get_uuid()))
    key2 = frozenset((Rwz.sensor_x.get_uuid(), Rwz.sensor_y.get_uuid()))
    a = Am.get_value_matrix()
    assert a == {key1: 0.0, key2: 0.0}
def test_should_delete_db():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    if os.path.exists("spearframe.db"):
        rel.clean_up()

    assert not os.path.exists("spearframe.db")
def test_should_return_float():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(50):
        var1.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)
        var2.on_data(math.cos(math.radians(degree * 10)), degree, degree + 1)

    assert isinstance(rel.get_correlation_coefficient(), float)
def test_should_show_perfect_association():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(180):
        var1.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)
        var2.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)

    assert rel.get_correlation_coefficient() == 1
def test_should_not_return_nan():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(180):
        var1.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)
        var2.on_data(math.sin(math.radians(degree * 100)), degree, degree + 1)

    assert not math.isnan(rel.get_correlation_coefficient())
def test_should_return_float_from_frame_db():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(180):
        var1.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)
        var2.on_data(math.cos(math.radians(degree * 10)), degree, degree + 1)

    assert isinstance(rel.get_value_between_times(0, 63), float)
def test_should_create_db():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")

    var1 = Variable()
    var2 = Variable()
    SpearframeRelationship(var1, var2)

    assert os.path.exists("spearframe.db")
Пример #8
0
    def add_sensor(self, sensor):
        """
        This function adds a new sensor to the snapper module and generates
        a corresponding variable object with mappings.

        :return:
        """
        self.sensors.append(sensor)
        self.snapper.add_sensor(sensor)
        newVariable = Variable()

        for var in self.variables:
            relationship = SpearframeRelationship(newVariable, var)
            self.matrix.add_relationship(relationship)

        self.variables.append(newVariable)
        self.route_map[sensor.uuid] = newVariable
        self.reverse_route_map[str(newVariable.uuid)] = sensor.uuid
def test_should_cause_frame_skip():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(20):
        if degree > 15 and rel.current_iteration[rel.sensor_x.get_uuid()]:
            var1.on_data(None, degree, degree + 1)
            var2.on_data(math.cos(math.radians(degree * 10)), degree,
                         degree + 1)
            break
        else:
            var1.on_data(math.sin(math.radians(degree * 10)), degree,
                         degree + 1)
            var2.on_data(math.cos(math.radians(degree * 10)), degree,
                         degree + 1)

    assert not rel.current_iteration[rel.sensor_x.get_uuid()]
Пример #10
0
    def remove_sensor(self, sensor):
        """
        This function removes a new sensor to the snapper module, removes
        variable from manager, and removes the corresponding relationships
        from the matrix.

        :return:
        """
        variable = self.route_map[sensor.uuid]
        self.route_map.pop(sensor.uuid)
        self.reverse_route_map.pop(str(variable.uuid))

        for var in self.variables:
            if var == variable:
                pass
            else:
                relationship = SpearframeRelationship(variable, var)
                self.matrix.remove_relationship(relationship)

        self.snapper.remove_sensor(sensor)
        self.sensors.remove(sensor)
        self.variables.remove(variable)
def test_should_raise_error_when_unknown_publisher_emits():
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)
    with pytest.raises(ValueError):
        rel.on_new_value(1, 4, 0, 1)