def get_data(self):
"""
Retrieve the data objects sorted by increasing popularity, namely in increasing receive_count, then send_count
and finally the last time they were sent by the current aDTN node.
:return: data objects sorted by increasing popularity.
"""
with self.lock:
Stats = Query()
stats = self.stats.search(Stats.deleted == False)
res = sorted(stats, key=lambda x: (x['receive_count'], x['send_count'], x['last_sent']))[:10]
now = int(time.time())
objects = []
for r in res:
idx = r['idx']
Objects = Query()
obj = self.data.search(Objects.idx == idx)[0]['content']
objects.append(obj)
self.stats.update({'last_sent': now}, Objects.idx == idx)
self.stats.update(increment('send_count'), Objects.idx == idx)
return objects
评论列表
文章目录