本文整理汇总了Python中market.Market类的典型用法代码示例。如果您正苦于以下问题:Python Market类的具体用法?Python Market怎么用?Python Market使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Market类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
def test():
player = Player(1, Team("Na'Vi", Sides.CT), .5, .2)
Market.loadout_player(player, True)
print player.loadout
player.money += 4400
Market.loadout_player(player, False)
print player.loadout
示例2: MarketApplication
class MarketApplication(tornado.web.Application):
def __init__(self, market_ip, market_port, market_id=1,
bm_user=None, bm_pass=None, bm_port=None, seed_mode=0, dev_mode=False):
self.transport = CryptoTransportLayer(market_ip,
market_port,
market_id,
bm_user,
bm_pass,
bm_port,
seed_mode,
dev_mode)
if seed_mode == 0:
self.transport.join_network(dev_mode=dev_mode)
self.market = Market(self.transport)
self.market.republish_contracts()
handlers = [
(r"/", MainHandler),
(r"/main", MainHandler),
(r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
(r"/ws", WebSocketHandler,
dict(transport=self.transport, market=self.market))
]
# TODO: Move debug settings to configuration location
settings = dict(debug=True)
tornado.web.Application.__init__(self, handlers, **settings)
def get_transport(self):
return self.transport
示例3: respawn_players
def respawn_players(self, env, pistol):
for player in self.players:
if (pistol):
player.reset_money()
player.respawn(env, pistol)
Market.loadout_player(player, pistol)
示例4: deadw
def deadw(m):
"Computes deadweight loss for market m."
# == Create analogous market with no tax == #
m_no_tax = Market(m.ad, m.bd, m.az, m.bz, 0)
# == Compare surplus, return difference == #
surp1 = m_no_tax.consumer_surp() + m_no_tax.producer_surp()
surp2 = m.consumer_surp() + m.producer_surp() + m.taxrev()
return surp1 - surp2
示例5: FxSystem
class FxSystem(object):
def __init__(self, pair, period, data_file):
self.market = Market(pair, period)
self.market.load_data(data_file)
self.account = Account(self.market)
def __repr__(self):
out = "Fx System Trading {0} {1}.".format(self.market, self.account)
return out
示例6: hist_test
def hist_test(rounds=1):
agent_types = ['miner', 'farmer', 'refiner', 'woodcutter', 'blacksmith']
agents = [Agent(random.choice(agent_types)) for i in range(100)] # 100 random angets
agents = {agent.id: agent for agent in agents}
market = Market()
market.agents = agents
for i in range(rounds): #10 rounds of market simulation
market.simulate()
return market.history.export()
示例7: build_market
def build_market(num_agents):
""" This returns a market with the number of agents from the parameter
right now, 100,000 agents is about the most it can handle. I was able to create a market with 500,000
but one round of market.simulate() took over a minute. 1,000,000 agents couldn't even be created."""
agent_types = ['miner', 'farmer', 'refiner', 'woodcutter', 'blacksmith']
agents = [Agent(random.choice(agent_types)) for i in range(num_agents)] # 100 random angets
agents = {agent.id: agent for agent in agents}
market = Market()
market.agents = agents
return market
示例8: MarketApplication
class MarketApplication(tornado.web.Application):
def __init__(self, market_ip, market_port, market_id=1,
bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
seed_mode=0, dev_mode=False, db_path='db/ob.db'):
db = Obdb(db_path)
self.transport = CryptoTransportLayer(market_ip,
market_port,
market_id,
db,
bm_user,
bm_pass,
bm_port,
seed_mode,
dev_mode)
self.market = Market(self.transport, db)
def post_joined():
self.transport._dht._refreshNode()
self.market.republish_contracts()
if seed_mode == 0:
self.transport.join_network(seed_peers, post_joined)
ioloop.PeriodicCallback(self.transport.join_network, 60000)
else:
self.transport.join_network([], post_joined)
ioloop.PeriodicCallback(self.transport.join_network, 60000)
Thread(target=reactor.run, args=(False,)).start()
handlers = [
(r"/", MainHandler),
(r"/main", MainHandler),
(r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
(r"/ws", WebSocketHandler,
dict(transport=self.transport, market=self.market, db=db))
]
# TODO: Move debug settings to configuration location
settings = dict(debug=True)
tornado.web.Application.__init__(self, handlers, **settings)
def get_transport(self):
return self.transport
示例9: __init__
def __init__(self, market_ip, market_port, market_id=1,
bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
seed_mode=0, dev_mode=False, db_path='db/ob.db'):
db = Obdb(db_path)
self.transport = CryptoTransportLayer(market_ip,
market_port,
market_id,
db,
bm_user,
bm_pass,
bm_port,
seed_mode,
dev_mode)
if seed_mode == 0:
self.transport.join_network(seed_peers)
self.market = Market(self.transport, db)
self.market.republish_contracts()
handlers = [
(r"/", MainHandler),
(r"/main", MainHandler),
(r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
(r"/ws", WebSocketHandler,
dict(transport=self.transport, market=self.market, db=db))
]
# TODO: Move debug settings to configuration location
settings = dict(debug=True)
tornado.web.Application.__init__(self, handlers, **settings)
示例10: __init__
def __init__(self):
# Gui.__init__(self)
# gui
self.root = Tk()
# compositions
self.travian = Travian(self.root)
self.market = Market(self.root, self.travian)
self.raiding = Raiding(self.root, self.travian)
self.info = Info(self.root, self.travian)
# self.mail = Mail()
# frames
self.exit_frame = Frame(self.root, bd=5, relief=GROOVE)
# items
self.intvars = self.create_intvars()
self.msg_var = StringVar()
self.msg_var.set('Messages')
self.old_news = self.create_news()
self.news = self.create_news()
# widgets
self.buttons = self.create_buttons()
self.checkboxes = self.create_checkboxes()
self.messages = self.create_messages()
# configure gui
self.config_root()
self.make_market_frame()
self.make_raid_frame()
self.make_info_frame()
self.make_exit_frame()
示例11: main
def main():
clear()
print('Initializing Test...')
print('Creating Agents...')
agent_types = ['miner', 'farmer', 'refiner', 'woodcutter', 'blacksmith']
agents = [Agent(random.choice(agent_types)) for i in range(100)] # 100 random angets
agents = {agent.id: agent for agent in agents}
# Debug Printing
#print('Sample Agents...')
#for agent in agents[:10]:
# print(agent)
input('Hit any key to continue...')
print('Creating Market...')
market = Market()
market.agents = agents #This needs to be part of the api for Market class
for i in range(50): #10 rounds of market simulation
clear()
market.simulate()
report = market.market_report()
print(report)
report = market.agent_report()
print(report)
input('Hit any key to continue...')
示例12: test_market
def test_market(n, m, t, partial, writer):
market = Market(n, m, t, partial)
serialDictatorship.serial_dictatorship(market)
serial_happy = evaluation.happy(market)
serial_percent_served = evaluation.percent_served(market)
serial_avg_time = evaluation.average_time(market)
market.reset()
serialDictatorship.modified_serial_dictatorship(market)
mod_happy = evaluation.happy(market)
mod_percent_served = evaluation.percent_served(market)
mod_avg_time = evaluation.average_time(market)
market.reset()
minLocations.minimize_locations(market)
min_loc_happy = evaluation.happy(market)
min_loc_percent_served = evaluation.percent_served(market)
min_loc_avg_time = evaluation.average_time(market)
row = [n, m, t, partial, serial_happy, serial_percent_served,
serial_avg_time, mod_happy, mod_percent_served, mod_avg_time,
min_loc_happy, min_loc_percent_served, min_loc_avg_time]
writer.writerow(row)
示例13: __init__
def __init__(self, market_ip, market_port, market_id=1,
bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
seed_mode=0, dev_mode=False, db_path='db/ob.db'):
db = Obdb(db_path)
self.transport = CryptoTransportLayer(market_ip,
market_port,
market_id,
db,
bm_user,
bm_pass,
bm_port,
seed_mode,
dev_mode)
self.market = Market(self.transport, db)
def post_joined():
self.transport.dht._refreshNode()
self.market.republish_contracts()
peers = seed_peers if seed_mode == 0 else []
self.transport.join_network(peers)
Thread(target=reactor.run, args=(False,)).start()
handlers = [
(r"/", MainHandler),
(r"/main", MainHandler),
(r"/html/(.*)", OpenBazaarStaticHandler, {'path': './html'}),
(r"/ws", WebSocketHandler,
dict(transport=self.transport, market_application=self, db=db))
]
# TODO: Move debug settings to configuration location
settings = dict(debug=True)
tornado.web.Application.__init__(self, handlers, **settings)
示例14: MarketApplication
class MarketApplication(tornado.web.Application):
def __init__(self, market_ip, market_port, market_id=1,
bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
seed_mode=0, dev_mode=False, db_path='db/ob.db'):
db = Obdb(db_path)
self.transport = CryptoTransportLayer(market_ip,
market_port,
market_id,
db,
bm_user,
bm_pass,
bm_port,
seed_mode,
dev_mode)
self.market = Market(self.transport, db)
def post_joined():
self.transport.dht._refreshNode()
self.market.republish_contracts()
peers = seed_peers if seed_mode == 0 else []
self.transport.join_network(peers)
Thread(target=reactor.run, args=(False,)).start()
handlers = [
(r"/", MainHandler),
(r"/main", MainHandler),
(r"/html/(.*)", OpenBazaarStaticHandler, {'path': './html'}),
(r"/ws", WebSocketHandler,
dict(transport=self.transport, market_application=self, db=db))
]
# TODO: Move debug settings to configuration location
settings = dict(debug=True)
tornado.web.Application.__init__(self, handlers, **settings)
def get_transport(self):
return self.transport
def setup_upnp_port_mappings(self, http_port, p2p_port):
upnp.PortMapper.DEBUG = False
print "Setting up UPnP Port Map Entry..."
# TODO: Add some setting whether or not to use UPnP
# if Settings.get(Settings.USE_UPNP_PORT_MAPPINGS):
self.upnp_mapper = upnp.PortMapper()
# TODO: Add some setting whether or not to clean all previous port
# mappings left behind by us
# if Settings.get(Settings.CLEAN_UPNP_PORT_MAPPINGS_ON_START):
# upnp_mapper.cleanMyMappings()
# for now let's always clean mappings every time.
self.upnp_mapper.clean_my_mappings()
# result_http_port_mapping = self.upnp_mapper.add_port_mapping(http_port,
# http_port)
# print ("UPnP HTTP Port Map configuration done (%s -> %s) => %s" %
# (str(http_port), str(http_port), str(result_http_port_mapping)))
result_tcp_p2p_mapping = self.upnp_mapper.add_port_mapping(p2p_port,
p2p_port)
print ("UPnP TCP P2P Port Map configuration done (%s -> %s) => %s" %
(str(p2p_port), str(p2p_port), str(result_tcp_p2p_mapping)))
result_udp_p2p_mapping = self.upnp_mapper.add_port_mapping(p2p_port,
p2p_port,
'UDP')
print ("UPnP UDP P2P Port Map configuration done (%s -> %s) => %s" %
(str(p2p_port), str(p2p_port), str(result_udp_p2p_mapping)))
result = result_tcp_p2p_mapping and result_udp_p2p_mapping
if not result:
print("Warning: UPnP was not setup correctly. Try doing a port forward on %s and start the node again with -j" % p2p_port)
return result
def cleanup_upnp_port_mapping(self):
try:
if self.upnp_mapper is not None:
print "Cleaning UPnP Port Mapping -> ", \
self.upnp_mapper.clean_my_mappings()
except AttributeError:
print "[openbazaar] MarketApplication.clean_upnp_port_mapping() failed!"
pass
def shutdown(self, x=None, y=None):
print "MarketApplication.shutdown!"
locallogger = logging.getLogger('[%s] %s' % (self.market.market_id, 'root'))
locallogger.info("Received TERMINATE, exiting...")
# application.get_transport().broadcast_goodbye()
self.cleanup_upnp_port_mapping()
tornado.ioloop.IOLoop.instance().stop()
self.transport.shutdown()
os._exit(0)
示例15: __init__
def __init__(self, pair, period, data_file):
self.market = Market(pair, period)
self.market.load_data(data_file)
self.account = Account(self.market)