本文整理汇总了Python中history.History.peer_history方法的典型用法代码示例。如果您正苦于以下问题:Python History.peer_history方法的具体用法?Python History.peer_history怎么用?Python History.peer_history使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类history.History
的用法示例。
在下文中一共展示了History.peer_history方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_sim_once
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import peer_history [as 别名]
#.........这里部分代码省略.........
counts = dict()
def index(name):
if name in counts:
a = counts[name]
counts[name] += 1
else:
a = 0
counts[name] = 1
return a
n = len(conf.agent_class_names)
ids = map(lambda n: "%s%d" % (n,index(n)), conf.agent_class_names)
is_seed = lambda id: id.startswith("Seed")
def get_pieces(id):
if id.startswith("Seed"):
return [conf.blocks_per_piece]*conf.num_pieces
else:
return [0]*conf.num_pieces
peer_pieces = dict() # id -> list (blocks / piece)
peer_pieces = dict((id, get_pieces(id)) for id in ids)
pieces = [get_pieces(id) for id in ids]
r = itertools.repeat
up_bws = [self.up_bw(id) for id in ids]
params = zip(r(conf), ids, pieces, up_bws)
peers = map(load, conf.agent_class_names, params)
#logging.debug("Peers: \n" + "\n".join(str(p) for p in peers))
return peers, peer_pieces
def get_peer_requests(p, peer_info, peer_history, peer_pieces, available):
def remove_me(info):
# TODO: Do we need this linear pass?
return filter(lambda peer: peer.id != p.id, peer_info)
pieces = copy.copy(peer_pieces[p.id])
# Made copy of pieces and the peer info this peer needs to make it's
# decision, so that it can't change the simulation's copies.
p.update_pieces(pieces)
rs = p.requests(remove_me(peer_info), peer_history)
check_requests(p, rs, peer_pieces, available)
return rs
def get_peer_uploads(all_requests, p, peer_info, peer_history):
def remove_me(info):
# TODO: remove this pass? Use a set?
return filter(lambda peer: peer.id != p.id, peer_info)
def requests_to(id):
f = lambda r: r.peer_id == id
ans = []
for rs in all_requests.values():
ans.extend(filter(f, rs))
return ans
requests = requests_to(p.id)
us = p.uploads(requests, remove_me(peer_info), peer_history)
check_uploads(p, us)
return us
def upload_rate(uploads, uploader_id, requester_id):
"""