本文整理汇总了Python中history.History.pretty方法的典型用法代码示例。如果您正苦于以下问题:Python History.pretty方法的具体用法?Python History.pretty怎么用?Python History.pretty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类history.History
的用法示例。
在下文中一共展示了History.pretty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_sim_once
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import pretty [as 别名]
#.........这里部分代码省略.........
if blocks > old:
new_blocks_per_piece[piece_id] = (blocks, peer_id)
else:
new_blocks_per_piece[piece_id] = (blocks, peer_id)
# Group the requests by peer that is being asked
get_peer_id = lambda r: r.peer_id
rs = sorted(requests[requester_id], key=get_peer_id)
for peer_id, rs_for_peer in itertools.groupby(rs, get_peer_id):
bw = upload_rate(uploads, peer_id, requester_id)
if bw == 0:
continue
# This bandwidth gets applied in order to each piece requested
for r in rs_for_peer:
needed_blocks = conf.blocks_per_piece - r.start
alloced_bw = min(bw, needed_blocks)
update_count(r.piece_id, alloced_bw, peer_id)
bw -= alloced_bw
if bw == 0:
break
for piece_id in new_blocks_per_piece:
(blocks, peer_id) = new_blocks_per_piece[piece_id]
new_pp[requester_id][piece_id] += blocks
if new_pp[requester_id][piece_id] == conf.blocks_per_piece:
available[requester_id].add(piece_id)
d = Download(peer_id, requester_id, piece_id, blocks)
downloads[requester_id].append(d)
return (new_pp, downloads)
def completed_pieces(peer_id, available):
return len(available[peer_id])
def log_peer_info(peer_pieces, available):
for p_id in self.peer_ids:
pieces = peer_pieces[p_id]
logging.debug("pieces for %s: %s" % (str(p_id), str(pieces)))
log = ", ".join("%s:%s" % (p_id, completed_pieces(p_id, available))
for p_id in self.peer_ids)
logging.info("Pieces completed: " + log)
logging.debug("Starting simulation with config: %s" % str(conf))
peers, peer_pieces = create_peers()
self.peer_ids = [p.id for p in peers]
self.peers_by_id = dict((p.id, p) for p in peers)
upload_rates = dict((id, self.up_bw(id)) for id in self.peer_ids)
history = History(self.peer_ids, upload_rates)
# dict : pid -> set(finished / available pieces)
available = dict((pid, set(available_pieces(pid, peer_pieces)))
for pid in self.peer_ids)
# Begin the event loop
while True:
logging.info("======= Round %d ========" % round)
peer_info = [PeerInfo(p.id, available[p.id])
for p in peers]
requests = dict() # peer_id -> list of Requests
uploads = dict() # peer_id -> list of Uploads
h = dict()
for p in peers:
h[p.id] = history.peer_history(p.id)
requests[p.id] = get_peer_requests(p, peer_info, h[p.id], peer_pieces,
available)
for p in peers:
uploads[p.id] = get_peer_uploads(requests, p, peer_info, h[p.id])
(peer_pieces, downloads) = update_peer_pieces(
peer_pieces, requests, uploads, available)
history.update(downloads, uploads)
logging.debug(history.pretty_for_round(round))
log_peer_info(peer_pieces, available)
if all_done(peer_pieces):
logging.info("All done!")
break
round += 1
if round > conf.max_round:
logging.info("Out of time. Stopping.")
break
logging.info("Game history:\n%s" % history.pretty())
logging.info("======== STATS ========")
logging.info("Uploaded blocks:\n%s" %
Stats.uploaded_blocks_str(self.peer_ids, history))
logging.info("Completion rounds:\n%s" %
Stats.completion_rounds_str(self.peer_ids, history))
logging.info("All done round: %s" %
Stats.all_done_round(self.peer_ids, history))
return history