本文整理汇总了Python中history.History.register方法的典型用法代码示例。如果您正苦于以下问题:Python History.register方法的具体用法?Python History.register怎么用?Python History.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类history.History
的用法示例。
在下文中一共展示了History.register方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Market
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import register [as 别名]
#.........这里部分代码省略.........
if bid.units == 0:
bids.pop(0)
if ask.units == 0:
asks.pop(0)
self.history.asks.add(good, num_asks)
self.history.bids.add(good, num_bids)
self.history.trades.add(good, units_traded)
if units_traded > 0:
average_price = money_traded / units_traded
else: # special case no goods traded this round, use last round's average price
average_price = self.history.prices.average(good, 1)
self.history.prices.add(good, average_price)
# TODO: might want to log rejected offers somewhere
# Reject all remaining offers
for bid in bids:
self.agents[bid.agent_id].update_price_model(self, "buy", good, False)
for ask in asks:
self.agents[ask.agent_id].update_price_model(self, "sell", good, False)
# Clear trade books
self.bid_book[good] = []
self.ask_book[good] = []
# TODO: This is from the load data method, change name and rethink
def new_history(self):
for good in self.good_types:
self.history.register(good)
self.history.prices.add(good, 1.0) # start bidding at 1
self.history.asks.add(good, 1.0) # start history with one fake buy/sell
self.history.bids.add(good, 1.0)
self.history.trades.add(good, 1.0)
for agent_type in self.agent_types:
self.history.profits.register(agent_type)
def transfer_good(self):
pass
def transfer_money(self):
pass
def replace_agent(self, agent):
"""This should replace an agent with the most successful agent type"""
del self.agents[agent.id]
agent = Agent(random.choice(self.agent_types)) # for now it just is random
self.agents[agent.id] = agent
# TODO: market reports should just return data not format it
# TODO: market report should run on market history, not just rejected offers
def market_report(self): # this could be a __str__ function or return actual values for plotting
# NOTE: now that orders are resolved, this only reflects rejected offers
report = "Market Report:".center(62, "=") + "\n"
report += "Bids".center(62) + "\n"
for good, offers in self.bid_book.items():
total_offers = len(offers)
sum_price = sum(offer.unit_price for offer in offers)
total_units = sum(offer.units for offer in offers)
if total_offers > 0: