本文整理汇总了Python中mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser.get_records方法的典型用法代码示例。如果您正苦于以下问题:Python AdcpsJlnStcParser.get_records方法的具体用法?Python AdcpsJlnStcParser.get_records怎么用?Python AdcpsJlnStcParser.get_records使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser
的用法示例。
在下文中一共展示了AdcpsJlnStcParser.get_records方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple
# 需要导入模块: from mi.dataset.parser.adcps_jln_stc import AdcpsJlnStcParser [as 别名]
# 或者: from mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser import get_records [as 别名]
def test_simple(self):
"""
Read test data and pull out multiple data particles at one time.
Assert that the results are those we expected.
"""
with open(os.path.join(RESOURCE_PATH, 'adcpt_20130929_091817.DAT')) as file_handle:
parser = AdcpsJlnStcParser(self._telem_config,
None,
file_handle,
lambda state, ingested: None,
lambda data: None,
self.exception_callback)
result = parser.get_records(6)
self.assert_particles(result, 'adcpt_20130929_091817.telem.yml', RESOURCE_PATH)
self.assertEquals(len(self.exception_callback_value), 0)
with open(os.path.join(RESOURCE_PATH, 'adcpt_20130929_091817.DAT')) as file_handle:
parser = AdcpsJlnStcParser(self._recov_config,
None,
file_handle,
lambda state, ingested: None,
lambda data: None,
self.exception_callback)
result = parser.get_records(6)
self.assert_particles(result, 'adcpt_20130929_091817.recov.yml', RESOURCE_PATH)
self.assertEquals(len(self.exception_callback_value), 0)
示例2: test_real_file
# 需要导入模块: from mi.dataset.parser.adcps_jln_stc import AdcpsJlnStcParser [as 别名]
# 或者: from mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser import get_records [as 别名]
def test_real_file(self):
with open(os.path.join(RESOURCE_PATH, 'adcpt_20140504_015742.DAT'), 'r') as file_handle:
parser = AdcpsJlnStcParser(self._telem_config,
None, file_handle,
lambda state, ingested: None,
lambda data: None,
self.exception_callback)
result = parser.get_records(1000)
self.assert_particles(result, 'adcpt_20140504_015742.telem.yml', RESOURCE_PATH)
self.assertEquals(len(self.exception_callback_value), 0)
with open(os.path.join(RESOURCE_PATH, 'adcpt_20140504_015742.DAT'), 'r') as file_handle:
parser = AdcpsJlnStcParser(self._recov_config,
None, file_handle,
lambda state, ingested: None,
lambda data: None,
self.exception_callback)
result = parser.get_records(1000)
self.assert_particles(result, 'adcpt_20140504_015742.recov.yml', RESOURCE_PATH)
self.assertEquals(len(self.exception_callback_value), 0)
示例3: test_bad_data_telem
# 需要导入模块: from mi.dataset.parser.adcps_jln_stc import AdcpsJlnStcParser [as 别名]
# 或者: from mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser import get_records [as 别名]
def test_bad_data_telem(self):
"""
Ensure that bad data is skipped when it exists.
"""
# Bad checksum
# If checksum is bad, skip the record and continue parsing.
with open(os.path.join(RESOURCE_PATH, 'adcps_jln_stc.bad_checksum.DAT'), 'rb') as file_handle:
parser = AdcpsJlnStcParser(self._telem_config,
file_handle,
self.exception_callback)
result = parser.get_records(10)
self.assert_particles(result, 'adcps_jln_stc.bad_checksum.telem.yml', RESOURCE_PATH)
self.assertEquals(len(self.exception_callback_value), 1)
self.assert_(isinstance(self.exception_callback_value[0], SampleException))
self.exception_callback_value.pop()
# Incorrect number of bytes
# If numbytes is incorrect, skip the record and continue parsing.
with open(os.path.join(RESOURCE_PATH, 'adcps_jln_stc.bad_num_bytes.DAT'), 'rb') as file_handle:
parser = AdcpsJlnStcParser(self._telem_config,
file_handle,
self.exception_callback)
result = parser.get_records(10)
self.assert_particles(result, 'adcps_jln_stc.bad_num_bytes.telem.yml', RESOURCE_PATH)
self.assertEquals(len(self.exception_callback_value), 1)
self.assert_(isinstance(self.exception_callback_value[0], SampleException))
示例4: test_receive_fail_recov
# 需要导入模块: from mi.dataset.parser.adcps_jln_stc import AdcpsJlnStcParser [as 别名]
# 或者: from mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser import get_records [as 别名]
def test_receive_fail_recov(self):
# ReceiveFailure
# If record marked with 'ReceiveFailure', skip the record and continue parsing.
with open(os.path.join(RESOURCE_PATH, 'adcps_jln_stc.bad_rx_failure.DAT'), 'rb') as file_handle:
parser = AdcpsJlnStcParser(self._recov_config,
file_handle,
self.exception_callback)
result = parser.get_records(10)
self.assert_particles(result, 'adcps_jln_stc.bad_rx_failure.recov.yml', RESOURCE_PATH)
self.assertEquals(len(self.exception_callback_value), 0)
示例5: test_bug_2979_2
# 需要导入模块: from mi.dataset.parser.adcps_jln_stc import AdcpsJlnStcParser [as 别名]
# 或者: from mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser import get_records [as 别名]
def test_bug_2979_2(self):
"""
Read test data and pull out multiple data particles at one time.
Assert that the results are those we expected.
"""
with open(os.path.join(RESOURCE_PATH, 'adcpt_20140707_200310.DAT'), 'rb') as file_handle:
parser = AdcpsJlnStcParser(self._telem_config,
file_handle,
self.exception_callback)
result = parser.get_records(100)
self.assertEquals(len(result), 0)
self.assertEquals(len(self.exception_callback_value), 0)
示例6: test_bug_2979_1
# 需要导入模块: from mi.dataset.parser.adcps_jln_stc import AdcpsJlnStcParser [as 别名]
# 或者: from mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser import get_records [as 别名]
def test_bug_2979_1(self):
"""
Read test data and pull out multiple data particles at one time.
Assert that the results are those we expected.
"""
with open(os.path.join(RESOURCE_PATH, 'adcpt_20140613_105345.DAT')) as file_handle:
parser = AdcpsJlnStcParser(self._telem_config,
None,
file_handle,
lambda state, ingested: None,
lambda data: None,
self.exception_callback)
result = parser.get_records(100)
self.assertEquals(len(result), 13)
self.assertEquals(len(self.exception_callback_value), 0)
示例7: AdcpsJlnStcParserUnitTestCase
# 需要导入模块: from mi.dataset.parser.adcps_jln_stc import AdcpsJlnStcParser [as 别名]
# 或者: from mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser import get_records [as 别名]
#.........这里部分代码省略.........
fid.write('header:\n')
fid.write(" particle_object: 'MULTIPLE'\n")
fid.write(" particle_type: 'MULTIPLE'\n")
fid.write('data:\n')
for i in range(0, len(particles)):
particle_dict = particles[i].generate_dict()
fid.write(' - _index: %d\n' % (i+1))
fid.write(' particle_object: %s\n' % particles[i].__class__.__name__)
fid.write(' particle_type: %s\n' % particle_dict.get('stream_name'))
fid.write(' internal_timestamp: %f\n' % particle_dict.get('internal_timestamp'))
for val in particle_dict.get('values'):
if isinstance(val.get('value'), float):
fid.write(' %s: %16.16f\n' % (val.get('value_id'), val.get('value')))
else:
fid.write(' %s: %s\n' % (val.get('value_id'), val.get('value')))
fid.close()
def create_yml(self):
"""
This utility creates a yml file
"""
#ADCP_data_20130702.PD0 has one record in it
fid = open(os.path.join(RESOURCE_PATH, 'adcpt_20140504_015742.DAT'), 'rb')
self.stream_handle = fid
self.parser = AdcpsJlnStcParser(self.config, self.start_state, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
particles = self.parser.get_records(20)
self.particles_to_yml(particles, 'adcpt_20140504_015742.yml')
fid.close()
def assert_result(self, result, particle, position):
self.assertEqual(result, [particle])
# Check parser state
self.assertEqual(self.parser._state[StateKey.POSITION], position)
self.assertEqual(self.state_callback_value[StateKey.POSITION], position)
self.assert_(isinstance(self.publish_callback_value, list))
self.assertEqual(self.publish_callback_value[0], particle)
def test_simple(self):
"""
Read test data 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, 'adcpt_20130929_091817.DAT'))
self.parser = AdcpsJlnStcParser(self.config, self.start_state, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
result = self.parser.get_records(1)
self.assert_result(result, self.particle_header_footer, 138)
result = self.parser.get_records(1)
self.assert_result(result, self.particle_a, 509)
result = self.parser.get_records(1)
self.assert_result(result, self.particle_b, 880)
result = self.parser.get_records(1)
self.assert_result(result, self.particle_c, 1251)
result = self.parser.get_records(1)