本文整理汇总了Python中sortedcontainers.SortedDict方法的典型用法代码示例。如果您正苦于以下问题:Python sortedcontainers.SortedDict方法的具体用法?Python sortedcontainers.SortedDict怎么用?Python sortedcontainers.SortedDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers
的用法示例。
在下文中一共展示了sortedcontainers.SortedDict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def __init__(self,
url="wss://ws-feed.pro.coinbase.com",
product_id='BTC-USD',
api_key="",
api_secret="",
api_passphrase="",
channels=None,
log_to=None):
super(OrderBook, self).__init__(url=url, products=product_id,
api_key=api_key, api_secret=api_secret,
api_passphrase=api_passphrase, channels=channels)
self._asks = SortedDict()
self._bids = SortedDict()
self._client = PublicClient()
self._sequence = -1
self._log_to = log_to
if self._log_to:
assert hasattr(self._log_to, 'write')
self._current_ticker = None
示例2: reset_book
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def reset_book(self):
self._asks = SortedDict()
self._bids = SortedDict()
res = self._client.get_product_order_book(product_id=self.product_id, level=3)
for bid in res['bids']:
self.add({
'id': bid[2],
'side': 'buy',
'price': Decimal(bid[0]),
'size': Decimal(bid[1])
})
for ask in res['asks']:
self.add({
'id': ask[2],
'side': 'sell',
'price': Decimal(ask[0]),
'size': Decimal(ask[1])
})
self._sequence = res['sequence']
示例3: state_actions_table
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def state_actions_table(self):
# Make sure table is sorted by state for deterministic output (needed for testing)
sorted_state_actions = sortedcontainers.SortedDict()
for state in self.state_actions:
(entry_actions, exit_actions) = self.state_actions[state]
entry_action_names = list(map(_action_to_name, entry_actions))
if entry_action_names == []:
entry_action_names = "-"
exit_action_names = list(map(_action_to_name, exit_actions))
if exit_action_names == []:
exit_action_names = "-"
sorted_state_actions[state.name] = (entry_action_names, exit_action_names)
tab = table.Table()
tab.add_row(["State", "Entry Actions", "Exit Actions"])
for state_name in sorted_state_actions:
(entry_action_names, exit_action_names) = sorted_state_actions[state_name]
tab.add_row([state_name, entry_action_names, exit_action_names])
return tab
示例4: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def __init__(self, is_stack):
"""
Constructor
:param is_stack: Whether this is a region map for stack frames or not. Different strategies apply for stack
regions.
"""
self.is_stack = is_stack
# A sorted list, which maps stack addresses to region IDs
self._address_to_region_id = SortedDict()
# A dict, which maps region IDs to memory address ranges
self._region_id_to_address = { }
#
# Properties
#
示例5: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def __init__(self, intervals=None):
"""
Set up a tree. If intervals is provided, add all the intervals
to the tree.
Completes in O(n*log n) time.
"""
intervals = set(intervals) if intervals is not None else set()
for iv in intervals:
if iv.is_null():
raise ValueError(
"IntervalTree: Null Interval objects not allowed in IntervalTree:"
" {0}".format(iv)
)
self.all_intervals = intervals
self.top_node = Node.from_intervals(self.all_intervals)
self.boundary_table = SortedDict()
for iv in self.all_intervals:
self._add_boundaries(iv)
示例6: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def __init__(self, ctx: mgl.Context):
self.buffer = None
self.ctx = ctx
# Allocation id to sort key
self.id_lookup: Dict[int, Tuple[Any, int]] = {}
# Sorted list of sort keys to index arrays
self.allocations: Mapping[Tuple[Any, int], np.ndarray] = SortedDict()
# Track whether we have updates
self.dirty: bool = True
# We allocate identifiers for each allocation. These are sequential
# and form part of the sort key; this ensures that insertion order
# can be preserved.
self.next_id: int = 1 # start at 1 so we can test bool(id)
示例7: default
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def default(self, obj):
if isinstance(obj, np.ndarray) and obj.ndim == 1:
return obj.tolist()
elif isinstance(obj, Quaternion):
return obj.data.tolist()
elif isinstance(obj, sortedcontainers.SortedDict):
return dict(obj)
elif isinstance(obj, (
KeyFrame,
KeyFrameList,
TransformData,
spimagine.models.transform_model.TransformData)):
return obj.__dict__
elif isinstance(obj, np.generic):
return np.asscalar(obj)
return json.JSONEncoder.default(self, obj)
示例8: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def __init__(self, product_ids='ETH-USD', api_key=None, api_secret=None,
passphrase=None, use_heartbeat=False,
trade_log_file_path=None):
super().__init__(product_ids=product_ids,
api_key=api_key,
api_secret=api_secret,
passphrase=passphrase,
use_heartbeat=use_heartbeat,
trade_log_file_path=trade_log_file_path)
if not isinstance(product_ids, list):
product_ids = [product_ids]
self.traders = {product_id: gdax.trader.Trader(product_id=product_id)
for product_id in product_ids}
self._asks = {product_id: SortedDict() for product_id in product_ids}
self._bids = {product_id: SortedDict() for product_id in product_ids}
self._sequences = {product_id: None for product_id in product_ids}
示例9: test_lenient_split
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def test_lenient_split(self):
self.transcript.json_conf["pick"]["chimera_split"]["blast_check"] = True
self.transcript.json_conf["pick"][
"chimera_split"]["blast_params"]["leniency"] = "LENIENT"
cds_boundaries = SortedDict()
for orf in sorted(self.transcript.loaded_bed12,
key=operator.attrgetter("thick_start", "thick_end")):
cds_boundaries[(orf.thick_start, orf.thick_end)] = [orf]
self.assertEqual(1,
len(splitting.check_split_by_blast(self.transcript, cds_boundaries)))
sl = loci.Superlocus(self.transcript, json_conf=self.transcript.json_conf)
self.assertEqual(len(sl.transcripts), 1)
sl.load_all_transcript_data(data_dict=dict())
self.assertEqual(len(sl.transcripts), 1)
示例10: test_stringent_split
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def test_stringent_split(self):
self.transcript.json_conf["pick"]["chimera_split"]["blast_check"] = True
self.transcript.json_conf["pick"][
"chimera_split"]["blast_params"]["leniency"] = "STRINGENT"
cds_boundaries = SortedDict()
for orf in sorted(self.transcript.loaded_bed12,
key=operator.attrgetter("thick_start", "thick_end")):
cds_boundaries[(orf.thick_start, orf.thick_end)] = [orf]
self.assertEqual(1,
len(splitting.check_split_by_blast(self.transcript, cds_boundaries)))
sl = loci.Superlocus(self.transcript, json_conf=self.transcript.json_conf)
self.assertEqual(len(sl.transcripts), 1)
sl.load_all_transcript_data(data_dict=dict())
self.assertEqual(len(sl.transcripts), 1)
示例11: test_permissive_split
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def test_permissive_split(self):
self.transcript.logger = self.logger
self.transcript.json_conf["pick"]["chimera_split"]["blast_check"] = True
self.transcript.json_conf["pick"][
"chimera_split"]["blast_params"]["leniency"] = "PERMISSIVE"
cds_boundaries = SortedDict()
for orf in sorted(self.transcript.loaded_bed12,
key=operator.attrgetter("thick_start", "thick_end")):
cds_boundaries[(orf.thick_start, orf.thick_end)] = [orf]
self.assertEqual(2, len(splitting.check_split_by_blast(self.transcript, cds_boundaries)))
sl = loci.Superlocus(self.transcript, json_conf=self.transcript.json_conf)
self.assertEqual(len(sl.transcripts), 1)
sl.load_all_transcript_data(data_dict=dict())
self.assertEqual(len(sl.transcripts), 2)
示例12: load_settings
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def load_settings(self, directory):
if not 'config'in directory:
directory += 'config/'
with open(directory+self.env_file_name, 'r') as fp:
env = json.load(fp=fp, object_pairs_hook=SortedDict)
with open(directory+self.agent_file_name, 'r') as fp:
agent = json.load(fp=fp, object_pairs_hook=SortedDict)
with open(directory+self.network_file_name, 'r') as fp:
network = json.load(fp=fp)
return env, agent, network
示例13: load_agent_settings
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def load_agent_settings(self, directory):
with open(directory+self.agent_file_name, 'r') as fp:
agent = json.load(fp=fp, object_pairs_hook=SortedDict)
return agent
示例14: load_env_settings
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def load_env_settings(self, directory):
with open(directory+self.env_file_name, 'r') as fp:
env = json.load(fp=fp, object_pairs_hook=SortedDict)
return env
示例15: node_element_str
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedDict [as 别名]
def node_element_str(element):
lines = []
if element.name is not None:
lines.append("Name: " + str(element.name))
lines.append("Level: " + str(element.level))
if element.flags is not None:
lines.append("Flags:")
if element.flags.overload is not None:
lines.append(" Overload: " + str(element.flags.overload))
if element.capabilities is not None:
lines.append("Capabilities:")
if element.capabilities.flood_reduction is not None:
lines.append(" Flood reduction: " + str(element.capabilities.flood_reduction))
if element.capabilities.hierarchy_indications is not None:
lines.append(" Leaf indications: " +
hierarchy_indications_str(element.capabilities.hierarchy_indications))
sorted_neighbors = sortedcontainers.SortedDict(element.neighbors)
for system_id, neighbor in sorted_neighbors.items():
lines.append("Neighbor: " + utils.system_id_str(system_id))
lines.append(" Level: " + str(neighbor.level))
if neighbor.cost is not None:
lines.append(" Cost: " + str(neighbor.cost))
if neighbor.bandwidth is not None:
lines.append(" Bandwidth: " + bandwidth_str(neighbor.bandwidth))
if neighbor.link_ids is not None:
sorted_link_ids = sorted(neighbor.link_ids)
for link_id_pair in sorted_link_ids:
lines.append(" Link: " + link_id_pair_str(link_id_pair))
return lines