如何解决从多个Entity对象创建EntityIterable
我正在尝试使用Xodus实现“附近”过滤器,其代码如下:
atomicreference<EntityIterable> referencetoScope = ...;
PropertyNearbyCondition propertyNearbyCondition = (PropertyNearbyCondition) entityCondition;
String propertyName = propertyNearbyCondition.propertyName();
Double longitude = propertyNearbyCondition.longitude();
Double latitude = propertyNearbyCondition.latitude();
Double distance = propertyNearbyCondition.distance();
EntityIterable entities =
referencetoScope.get().intersect(txn.findWithProp(entityType,propertyName));
List<Entity> entityList = new ArrayList<>();
entities.forEach(entity -> {
GeoPoint reference = (GeoPoint) entity.getProperty(propertyName);
double instantaneousdistance =
MathHelper.distFrom(latitude,longitude,reference.getLatitude(),reference.getLatitude());
if (distance >= instantaneousdistance) {
entityList.add(entity);
}
});
EntityIterable scoped = referencetoScope.get().intersect(build(entityList));
EntityIterable build(List<Entity> entityList) {
// Todo: Build a new EntityIterable from the entityList
}
该算法可能不是最好的算法,但是,这里的主要问题是如何根据多个Entity对象构建新的EntityIterable
?有可能吗?
我基本上收集“附近”实体的解决方案是使用自定义GeoPoint
属性遍历所有实体,然后对找到的每个实体进行比较,比较其GeoPoint属性的距离,如果命中,则所有这些实体应该收集到一个EntityIterable.
如何从EntityIterable
个对象列表中构建一个Entity
?
更新:
逐步解释其工作原理:
下面的这段代码获取具有给定属性名称的所有实体,例如geoLocation
EntityIterable entities =
referencetoScope.get().intersect(txn.findWithProp(entityType,propertyName));
然后,对于具有此类geoLocation属性的所有实体,例如对其进行迭代以计算其是否满足距离目标:
List<Entity> entityList = new ArrayList<>();
entities.forEach(entity -> {
// compute the distance target
});
在达到目标的新List
中添加实体。
从这里开始,需要删除EntityIterable entities
中所有与entityList
中匹配的 entities 的ID不相等的实体,或者删除将这些匹配的实体与referencetoScope.get()
相交而不与EntityIterable entities
相交(为避免混淆,此entities
iterable 只是临时的)
解决方法
解决方法如下:
# import winsound
import os
import tkinter as tk
import time
def beep(e,time_limit=1,timer=[0]):
t0 = timer[0]
t1 = time.time()
delta_t = t1 - t0
if delta_t < time_limit:
return
# winsound.Beep(440,1000)
os.system('say "Beep"')
timer[0] = t1
root = tk.Tk()
frame = tk.Frame(root,width=100,height=100)
frame.bind("<space>",beep)
frame.pack()
frame.focus_set()
root.mainloop()
这将有效地删除所有未达到目标距离的实体。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。