def to_oef_constraint_type( cls, constraint_type: ConstraintType ) -> OEFConstraintType: """From our constraint type to OEF constraint type.""" value = constraint_type.value if constraint_type.type == ConstraintTypes.EQUAL: return Eq(value) elif constraint_type.type == ConstraintTypes.NOT_EQUAL: return NotEq(value) elif constraint_type.type == ConstraintTypes.LESS_THAN: return Lt(value) elif constraint_type.type == ConstraintTypes.LESS_THAN_EQ: return LtEq(value) elif constraint_type.type == ConstraintTypes.GREATER_THAN: return Gt(value) elif constraint_type.type == ConstraintTypes.GREATER_THAN_EQ: return GtEq(value) elif constraint_type.type == ConstraintTypes.WITHIN: return Range(value) elif constraint_type.type == ConstraintTypes.IN: return In(value) elif constraint_type.type == ConstraintTypes.NOT_IN: return NotIn(value) else: raise ValueError("Constraint type not recognized.")
def test_serialization(self, range_: Range): """Test that serialization and deserialization of ``Range`` objects work correctly.""" expected_range = range_ range_pb = expected_range.to_pb() # type: query_pb2.Query.Relation actual_range = Range.from_pb(range_pb) assert expected_range == actual_range
def on_search_result(self, search_id: int, agents: List[str]): """For every agent returned in the service search, send a CFP to obtain resources from them.""" if len(agents) == 0: print("[{}]: No agent found. Stopping...".format(self.public_key)) self.stop() return print("[{0}]: Agent found: {1}".format(self.public_key, agents)) for agent in agents: print("[{0}]: Sending to agent {1}".format(self.public_key, agent)) # we send a 'None' query, meaning "give me all the resources you can propose." query = Query([Constraint("Date", Range( ("20/3/2019","21/3/2019") ))]) self.pending_cfp += 1 self.send_cfp(1, 0, agent, 0, query)
def test_not_equal_when_compared_with_different_type(self): a_range = Range(("foo", "bar")) not_a_range = tuple() assert a_range != not_a_range
def ranges(draw, type_: Type[ATTRIBUTE_TYPES] = None): if type_: type_strategy = strategies_by_type[type_] return Range(draw(tuples(type_strategy, type_strategy))) else: return Range(draw(range_values))