本文整理汇总了Python中mi.dataset.parser.ctdmo.CtdmoParser.get_records方法的典型用法代码示例。如果您正苦于以下问题:Python CtdmoParser.get_records方法的具体用法?Python CtdmoParser.get_records怎么用?Python CtdmoParser.get_records使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.dataset.parser.ctdmo.CtdmoParser
的用法示例。
在下文中一共展示了CtdmoParser.get_records方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CtdmoParserUnitTestCase
# 需要导入模块: from mi.dataset.parser.ctdmo import CtdmoParser [as 别名]
# 或者: from mi.dataset.parser.ctdmo.CtdmoParser import get_records [as 别名]
class CtdmoParserUnitTestCase(ParserUnitTestCase):
def state_callback(self, state):
""" Call back method to watch what comes in via the position callback """
self.state_callback_value = state
def pub_callback(self, pub):
""" Call back method to watch what comes in via the publish callback """
self.publish_callback_value = pub
def setUp(self):
ParserUnitTestCase.setUp(self)
self.config = {
DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.ctdmo',
DataSetDriverConfigKeys.PARTICLE_CLASS: 'CtdmoParserDataParticle'
}
# packets have the same timestamp, the first has 3 data samples [394-467]
self.timestamp1 = 3583612801.0
self.particle_a = CtdmoParserDataParticle(b'\x15\x38\x53\x66\x9e\x1a\xa2\x0c\x81\xd5\x81\x19\x0d',
internal_timestamp=self.timestamp1, new_sequence=True)
self.particle_b = CtdmoParserDataParticle(b'\x35\x3b\xa2\x10\xc3\x5a\xe7\x0a\x81\xd5\x81\x19\x0d',
internal_timestamp=self.timestamp1, new_sequence=False)
self.particle_c = CtdmoParserDataParticle(b'\x37\x39\x4c\xe0\xc3\x54\xe6\x0a\x81\xd5\x81\x19\x0d',
internal_timestamp=self.timestamp1, new_sequence=False)
# this is the start of packet 2 [5354:5544]
self.timestamp2 = 3583634401.0
self.particle_d = CtdmoParserDataParticle(b'\x40\x21\xbe\x25\x94\x9d\xa0\x1c\xe1\x29\x82\x19\x0d',
internal_timestamp=self.timestamp2, new_sequence=True)
self.particle_e = CtdmoParserDataParticle(b'\x41\x21\xc4\xd5\x94\x39\xe7\x1b\xe1\x29\x82\x19\x0d',
internal_timestamp=self.timestamp2, new_sequence=False)
# particle 14
self.particle_n = CtdmoParserDataParticle(b'58;v\x9d=%\x0b\xe1)\x82\x19\r',
internal_timestamp=self.timestamp2, new_sequence=False)
# particle 15
self.particle_o = CtdmoParserDataParticle(b'75\x8b\xe0\xc3T\xe5\n\xe1)\x82\x19\r',
internal_timestamp=self.timestamp2, new_sequence=False)
# start of packet 3 [6970-7160]
# particle 16
self.timestamp3 = 3583656001.0
self.particle_p = CtdmoParserDataParticle(b'@\x1e\x0b5\x8a]\x07iA~\x82\x19\r',
internal_timestamp=self.timestamp3, new_sequence=True)
self.particle_q = CtdmoParserDataParticle(b'A\x1f\x8a5\x92\x9d?IA~\x82\x19\r',
internal_timestamp=self.timestamp3, new_sequence=False)
# packet 4 [7547-7737]
self.timestamp4 = 3583663201.0
self.particle_y = CtdmoParserDataParticle(b'@\x1e\x04\xf5\x8a\x12\xf6ha\x9a\x82\x19\r',
internal_timestamp=self.timestamp4, new_sequence=True)
self.particle_z = CtdmoParserDataParticle(b'A\x1fu\xa5\x91\xaf/Ia\x9a\x82\x19\r',
internal_timestamp=self.timestamp4, new_sequence=False)
self.state_callback_value = None
self.publish_callback_value = None
def assert_result(self, result, in_process_data, unprocessed_data, timestamp, particle):
self.assertEqual(result, [particle])
self.assert_state(in_process_data, unprocessed_data, timestamp)
self.assert_(isinstance(self.publish_callback_value, list))
self.assertEqual(self.publish_callback_value[0], particle)
def assert_state(self, in_process_data, unprocessed_data, timestamp):
self.assertEqual(self.parser._state[StateKey.IN_PROCESS_DATA], in_process_data)
self.assertEqual(self.parser._state[StateKey.UNPROCESSED_DATA], unprocessed_data)
self.assertEqual(self.state_callback_value[StateKey.IN_PROCESS_DATA], in_process_data)
self.assertEqual(self.state_callback_value[StateKey.UNPROCESSED_DATA], unprocessed_data)
self.assertEqual(self.state_callback_value[StateKey.TIMESTAMP], timestamp)
def test_simple(self):
"""
Read test data from the file and pull out data particles one at a time.
Assert that the results are those we expected.
"""
self.state = {StateKey.UNPROCESSED_DATA:[[0, 6000]],
StateKey.IN_PROCESS_DATA:[], StateKey.TIMESTAMP:0.0}
self.stream_handle = open(os.path.join(RESOURCE_PATH,
'node59p1_shorter.dat'))
self.parser = CtdmoParser(self.config, self.state, self.stream_handle,
self.state_callback, self.pub_callback)
result = self.parser.get_records(1)
self.stream_handle.close()
self.assert_result(result, [[394, 467, 3, 1, 1], [5354, 5544, 12, 0, 1]],
[[0, 12], [336, 2010], [5354, 6000]],
self.timestamp2, self.particle_a)
result = self.parser.get_records(1)
self.assert_result(result, [[394, 467, 3, 2, 1], [5354, 5544, 12, 0, 1]],
[[0, 12], [336, 2010], [5354, 6000]],
self.timestamp2, self.particle_b)
result = self.parser.get_records(1)
self.assert_result(result, [[5354, 5544, 12, 0, 1]],
[[0, 12], [336, 394], [467, 2010], [5354, 6000]],
self.timestamp2, self.particle_c)
result = self.parser.get_records(1)
self.assert_result(result, [[5354, 5544, 12, 1, 1]],
[[0, 12], [336, 394], [467, 2010], [5354, 6000]],
self.timestamp2, self.particle_d)
result = self.parser.get_records(1)
self.assert_result(result, [[5354, 5544, 12, 2, 1]],
[[0, 12], [336, 394], [467, 2010], [5354, 6000]],
#.........这里部分代码省略.........
示例2: CtdmoParserUnitTestCase
# 需要导入模块: from mi.dataset.parser.ctdmo import CtdmoParser [as 别名]
# 或者: from mi.dataset.parser.ctdmo.CtdmoParser import get_records [as 别名]
class CtdmoParserUnitTestCase(ParserUnitTestCase):
def state_callback(self, state):
""" Call back method to watch what comes in via the position callback """
self.state_callback_value = state
def pub_callback(self, pub):
""" Call back method to watch what comes in via the publish callback """
self.publish_callback_value = pub
def setUp(self):
ParserUnitTestCase.setUp(self)
self.config = {
DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.ctdmo',
DataSetDriverConfigKeys.PARTICLE_CLASS: 'CtdmoParserDataParticle',
'inductive_id': 55
}
# packets have the same timestamp, the first has 3 data samples [394-467]
self.timestamp1 = 3583612801.0
self.particle_a = CtdmoParserDataParticle(b'\x37\x39\x4c\xe0\xc3\x54\xe6\x0a\x81\xd5\x81\x19\x0d',
internal_timestamp=self.timestamp1)
# this is the start of packet 2 [5354:5544]
self.timestamp2 = 3583634401.0
self.particle_b = CtdmoParserDataParticle(b'\x37\x35\x8b\xe0\xc3T\xe5\n\xe1)\x82\x19\r',
internal_timestamp=self.timestamp2)
# start of packet 3 [6970-7160]
self.timestamp3 = 3583656001.0
self.particle_c = CtdmoParserDataParticle(b'\x37\x36\xe7\xe6\x89W9\x10A~\x82\x19\r',
internal_timestamp=self.timestamp3)
# packet 4 [7547-7737]
self.timestamp4 = 3583663201.0
self.particle_d = CtdmoParserDataParticle(b'\x37\x32\t6F\x0c\xd5\x0fa\x9a\x82\x19\r',
internal_timestamp=self.timestamp4)
self.timestamp_last = 3583692001.0
self.particle_z = CtdmoParserDataParticle(b'73\xcd\x86_\x92\x13\x10\xe1\n\x83\x19\r',
internal_timestamp=self.timestamp_last)
self.state_callback_value = None
self.publish_callback_value = None
def assert_result(self, result, in_process_data, unprocessed_data, timestamp, particle):
self.assertEqual(result, [particle])
self.assert_state(in_process_data, unprocessed_data, timestamp)
self.assert_(isinstance(self.publish_callback_value, list))
self.assertEqual(self.publish_callback_value[0], particle)
def assert_state(self, in_process_data, unprocessed_data, timestamp):
self.assertEqual(self.parser._state[StateKey.IN_PROCESS_DATA], in_process_data)
self.assertEqual(self.parser._state[StateKey.UNPROCESSED_DATA], unprocessed_data)
self.assertEqual(self.state_callback_value[StateKey.IN_PROCESS_DATA], in_process_data)
self.assertEqual(self.state_callback_value[StateKey.UNPROCESSED_DATA], unprocessed_data)
self.assertEqual(self.state_callback_value[StateKey.TIMESTAMP], timestamp)
def test_simple(self):
"""
Read test data from the file and pull out data particles one at a time.
Assert that the results are those we expected.
"""
self.state = {StateKey.UNPROCESSED_DATA:[[0, 8000]],
StateKey.IN_PROCESS_DATA:[], StateKey.TIMESTAMP:0.0}
self.stream_handle = open(os.path.join(RESOURCE_PATH,
'node59p1_shorter.dat'))
self.parser = CtdmoParser(self.config, self.state, self.stream_handle,
self.state_callback, self.pub_callback)
result = self.parser.get_records(1)
self.assert_result(result, [[5354, 5544, 1, 0, 1], [6970,7160,1,0,1], [7547,7737,1,0,1]],
[[0, 12], [336, 394], [467, 2010], [5354, 8000]],
self.timestamp4, self.particle_a)
result = self.parser.get_records(1)
self.assert_result(result, [[6970,7160,1,0,1], [7547,7737,1,0,1]],
[[0, 12], [336, 394], [467, 2010], [5544, 8000]],
self.timestamp4, self.particle_b)
result = self.parser.get_records(1)
self.assert_result(result, [[7547,7737,1,0,1]],
[[0, 12], [336, 394], [467, 2010], [5544, 6970], [7160, 8000]],
self.timestamp4, self.particle_c)
result = self.parser.get_records(1)
self.assert_result(result, [],
[[0, 12], [336, 394], [467, 2010], [5544, 6970], [7160, 7547],[7737, 8000]],
self.timestamp4, self.particle_d)
self.stream_handle.close()
def test_missing_inductive_id_config(self):
"""
Make sure that the driver complains about a missing inductive ID in the config
"""
self.state = {StateKey.UNPROCESSED_DATA:[[0, 8000]],
StateKey.IN_PROCESS_DATA:[], StateKey.TIMESTAMP:0.0}
self.stream_handle = open(os.path.join(RESOURCE_PATH,
'node59p1_shorter.dat'))
bad_config = {
DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.ctdmo',
DataSetDriverConfigKeys.PARTICLE_CLASS: 'CtdmoParserDataParticle',
}
with self.assertRaises(DatasetParserException):
self.parser = CtdmoParser(bad_config, self.state, self.stream_handle,
self.state_callback, self.pub_callback)
#.........这里部分代码省略.........
示例3: CtdmoParserUnitTestCase
# 需要导入模块: from mi.dataset.parser.ctdmo import CtdmoParser [as 别名]
# 或者: from mi.dataset.parser.ctdmo.CtdmoParser import get_records [as 别名]
#.........这里部分代码省略.........
)
self.state_callback_value = None
self.publish_callback_value = None
def assert_result(self, result, in_process_data, unprocessed_data, timestamp, particle):
log.debug("Comparing result %s to particle %s", result, particle)
self.assertEqual(result, [particle])
self.assert_state(in_process_data, unprocessed_data, timestamp)
self.assert_(isinstance(self.publish_callback_value, list))
self.assertEqual(self.publish_callback_value[0], particle)
def assert_state(self, in_process_data, unprocessed_data, timestamp):
self.assertEqual(self.parser._state[StateKey.IN_PROCESS_DATA], in_process_data)
self.assertEqual(self.parser._state[StateKey.UNPROCESSED_DATA], unprocessed_data)
self.assertEqual(self.state_callback_value[StateKey.IN_PROCESS_DATA], in_process_data)
self.assertEqual(self.state_callback_value[StateKey.UNPROCESSED_DATA], unprocessed_data)
self.assertEqual(self.state_callback_value[StateKey.TIMESTAMP], timestamp)
@unittest.skip("Skip for now")
def test_simple(self):
"""
Read test data from the file and pull out data particles one at a time.
Assert that the results are those we expected.
"""
self.state = {
StateKey.UNPROCESSED_DATA: [[0, len(CtdmoParserUnitTestCase.TEST_DATA)]],
StateKey.IN_PROCESS_DATA: [],
StateKey.TIMESTAMP: 0.0,
}
self.stream_handle = StringIO(CtdmoParserUnitTestCase.TEST_DATA)
self.parser = CtdmoParser(self.config, self.state, self.stream_handle, self.state_callback, self.pub_callback)
result = self.parser.get_records(1)
self.stream_handle.close()
self.assert_result(
result,
[[432, 505, 3, 1], [892, 1083, 12, 0], [1470, 1661, 12, 0], [2295, 2485, 12, 0]],
[[0, 50], [374, 505], [892, 1083], [1197, 1661], [2295, 2485]],
self.timestamp4,
self.particle_a,
)
result = self.parser.get_records(1)
self.assert_result(
result,
[[432, 505, 3, 2], [892, 1083, 12, 0], [1470, 1661, 12, 0], [2295, 2485, 12, 0]],
[[0, 50], [374, 505], [892, 1083], [1197, 1661], [2295, 2485]],
self.timestamp4,
self.particle_b,
)
result = self.parser.get_records(1)
self.assert_result(
result,
[[892, 1083, 12, 0], [1470, 1661, 12, 0], [2295, 2485, 12, 0]],
[[0, 50], [374, 432], [892, 1083], [1197, 1661], [2295, 2485]],
self.timestamp4,
self.particle_c,
)
result = self.parser.get_records(1)
self.assert_result(
result,
[[892, 1083, 12, 1], [1470, 1661, 12, 0], [2295, 2485, 12, 0]],
[[0, 50], [374, 432], [892, 1083], [1197, 1661], [2295, 2485]],
self.timestamp4,
self.particle_d,
)
示例4: CtdmoParserUnitTestCase
# 需要导入模块: from mi.dataset.parser.ctdmo import CtdmoParser [as 别名]
# 或者: from mi.dataset.parser.ctdmo.CtdmoParser import get_records [as 别名]
class CtdmoParserUnitTestCase(ParserUnitTestCase):
def state_callback(self, state):
""" Call back method to watch what comes in via the position callback """
self.state_callback_value = state
def pub_callback(self, pub):
""" Call back method to watch what comes in via the publish callback """
self.publish_callback_value = pub
def exception_callback(self, exception):
""" Call back method to watch what comes in via the exception callback """
self.exception_callback_value = exception
def setUp(self):
ParserUnitTestCase.setUp(self)
self.config = {
DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.ctdmo',
DataSetDriverConfigKeys.PARTICLE_CLASS: ['CtdmoParserDataParticle',
'CtdmoOffsetParserDataParticle'],
'inductive_id': 55
}
# all indices give in the comments are in actual file position, not escape sequence replace indices
# packets have the same timestamp, the first has 3 data samples [394-467]
self.particle_a = CtdmoParserDataParticle(b'51EF36D6\x37\x39\x4c\xe0\xc3\x54\xe6\x0a\x81\xd5\x81\x19\x0d')
# this is the start of packet 2 [855:1045]
self.particle_b = CtdmoParserDataParticle(b'51EF52F677\xf0\x00\xc3T\xe5\n\xa1\xf1\x81\x19\r')
# this is the start of packet 3 [1433:1623]
self.particle_c = CtdmoParserDataParticle(b'51EF6F1676$p\xc3T\xe4\n\xc1\r\x82\x19\r')
# this is the start of packet 4 [5354:5544]
self.particle_d = CtdmoParserDataParticle(b'51EF8B36\x37\x35\x8b\xe0\xc3T\xe5\n\xe1)\x82\x19\r')
# this is the start of packet 5 [6321:6511]
self.particle_e = CtdmoParserDataParticle(b'51EFC37677\x17\xd6\x8eI;\x10!b\x82\x19\r')
# start of packet 6 [6970-7160]
self.particle_f = CtdmoParserDataParticle(b'51EFDF96\x37\x36\xe7\xe6\x89W9\x10A~\x82\x19\r')
# packet 7 [7547-7737]
self.particle_g = CtdmoParserDataParticle(b'51EFFBB6\x37\x32\t6F\x0c\xd5\x0fa\x9a\x82\x19\r')
# first offset at 9543
self.particle_a_offset = CtdmoOffsetDataParticle(b'51F050167\x00\x00\x00\x00\x13')
# in long file, starts at 13453
self.particle_z = CtdmoParserDataParticle(b'51F0A47673\xb9\xa6]\x93\xf2\x0f!C\x83\x19\r')
# in longest file second offset at 19047
self.particle_b_offset = CtdmoOffsetDataParticle(b'51F1A1967\x00\x00\x00\x00\x13')
# third offset at 30596
self.particle_c_offset = CtdmoOffsetDataParticle(b'51F2F3167\x00\x00\x00\x00\x13')
self.state_callback_value = None
self.publish_callback_value = None
self.exception_callback_value = None
def assert_result(self, result, in_process_data, unprocessed_data, particle):
self.assertEqual(result, [particle])
self.assert_state(in_process_data, unprocessed_data)
self.assert_(isinstance(self.publish_callback_value, list))
self.assertEqual(self.publish_callback_value[0], particle)
def assert_state(self, in_process_data, unprocessed_data):
self.assertEqual(self.parser._state[StateKey.IN_PROCESS_DATA], in_process_data)
self.assertEqual(self.parser._state[StateKey.UNPROCESSED_DATA], unprocessed_data)
self.assertEqual(self.state_callback_value[StateKey.IN_PROCESS_DATA], in_process_data)
self.assertEqual(self.state_callback_value[StateKey.UNPROCESSED_DATA], unprocessed_data)
def test_simple(self):
"""
Read test data from the file and pull out data particles one at a time.
Assert that the results are those we expected.
"""
self.stream_handle = open(os.path.join(RESOURCE_PATH,
'node59p1_shorter.dat'))
self.parser = CtdmoParser(self.config, None, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
result = self.parser.get_records(1)
self.assert_result(result, [[853,1043,1,0], [1429,1619,1,0], [5349,5539,1,0], [6313,6503,1,0], [6958,7148,1,0], [7534,7724,1,0]],
[[0, 12], [336, 394], [853,1043], [1429,1619], [5349,5539], [5924,5927], [6313,6503], [6889,7148], [7534,7985]],
self.particle_a)
result = self.parser.get_records(1)
self.assert_result(result, [[1429,1619,1,0], [5349,5539,1,0], [6313,6503,1,0], [6958,7148,1,0], [7534,7724,1,0]],
[[0, 12], [336, 394], [1429,1619], [5349,5539], [5924,5927], [6313,6503], [6889,7148], [7534,7985]],
self.particle_b)
result = self.parser.get_records(1)
self.assert_result(result, [[5349,5539,1,0], [6313,6503,1,0], [6958,7148,1,0], [7534,7724,1,0]],
[[0, 12], [336, 394], [5349,5539], [5924,5927], [6313,6503], [6889,7148], [7534,7985]],
self.particle_c)
result = self.parser.get_records(1)
self.assert_result(result, [[6313,6503,1,0], [6958,7148,1,0], [7534,7724,1,0]],
[[0, 12], [336, 394], [5924,5927], [6313,6503], [6889,7148], [7534,7985]],
self.particle_d)
self.stream_handle.close()
self.assertEqual(self.exception_callback_value, None)
def test_missing_inductive_id_config(self):
"""
Make sure that the driver complains about a missing inductive ID in the config
"""
self.state = {StateKey.UNPROCESSED_DATA:[[0, 8000]],
#.........这里部分代码省略.........