text
stringlengths 0
828
|
|---|
),
|
extra=dict(kmsg=kmsg.dump())
|
)
|
return cls.onmessage(kmsg)"
|
4588,"def register(cls, name, entrypoint):
|
"""""" Register a new entrypoint
|
:param str name: Key used by messages
|
:param kser.entry.Entrypoint entrypoint: class to load
|
:raises ValidationError: Invalid entry
|
""""""
|
if not issubclass(entrypoint, Entrypoint):
|
raise ValidationError(
|
""Invalid type for entry '{}', MUST implement ""
|
""kser.entry.Entrypoint"".format(name),
|
extra=dict(entrypoint=name)
|
)
|
cls.ENTRYPOINTS[name] = entrypoint
|
logger.debug(""{}.Registered: {}"".format(cls.__name__, name))"
|
4589,"def run(cls, raw_data):
|
""""""description of run""""""
|
logger.debug(""{}.ReceivedFromKafka: {}"".format(
|
cls.__name__, raw_data
|
))
|
try:
|
kmsg = cls._onmessage(cls.TRANSPORT.loads(raw_data))
|
except Exception as exc:
|
logger.error(
|
""{}.ImportError: Failed to load data from kafka: {}"".format(
|
cls.__name__, exc
|
),
|
extra=dict(kafka_raw_data=raw_data)
|
)
|
return Result.from_exception(exc)
|
try:
|
cls.start_processing(kmsg)
|
if kmsg.entrypoint not in cls.ENTRYPOINTS:
|
raise ValidationError(
|
""Entrypoint '{}' not registred"".format(kmsg.entrypoint),
|
extra=dict(
|
uuid=kmsg.uuid, entrypoint=kmsg.entrypoint,
|
allowed=list(cls.ENTRYPOINTS.keys())
|
)
|
)
|
result = cls.ENTRYPOINTS[kmsg.entrypoint].from_Message(
|
kmsg
|
).execute()
|
except Exception as exc:
|
result = Result.from_exception(exc, kmsg.uuid)
|
finally:
|
cls.stop_processing()
|
# noinspection PyUnboundLocalVariable
|
if result and result.retcode < 300:
|
return cls._onsuccess(kmsg=kmsg, result=result)
|
else:
|
return cls._onerror(kmsg=kmsg, result=result)"
|
4590,"def interval_condition(value, inf, sup, dist):
|
""""""Checks if value belongs to the interval [inf - dist, sup + dist].
|
""""""
|
return (value > inf - dist and value < sup + dist)"
|
4591,"def nearest_point(query, root_id, get_properties, dist_fun=euclidean_dist):
|
""""""Find the point in the tree that minimizes the distance to the query.
|
This method implements the nearest_point query for any structure
|
implementing a kd-tree. The only requirement is a function capable to
|
extract the relevant properties from a node representation of the
|
particular implementation.
|
Args:
|
query (:obj:`tuple` of float or int): Stores the position of the
|
node.
|
root_id (:obj): The identifier of the root in the kd-tree
|
implementation.
|
get_properties (:obj:`function`): The function to extract the
|
relevant properties from a node, namely its point, region,
|
axis, left child identifier, right child identifier and
|
if it is active. If the implementation does not uses
|
the active attribute the function should return always True.
|
dist_fun (:obj:`function`, optional): The distance function,
|
euclidean distance by default.
|
Returns:
|
:obj:`tuple`: Tuple of length 2, where the first element is the
|
identifier of the nearest node, the second is the distance
|
to the query.
|
""""""
|
k = len(query)
|
dist = math.inf
|
nearest_node_id = None
|
# stack_node: stack of identifiers to nodes within a region that
|
# contains the query.
|
# stack_look: stack of identifiers to nodes within a region that
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.