当前位置: 首页>>代码示例>>Python>>正文


Python CtdmoParser.set_state方法代码示例

本文整理汇总了Python中mi.dataset.parser.ctdmo.CtdmoParser.set_state方法的典型用法代码示例。如果您正苦于以下问题:Python CtdmoParser.set_state方法的具体用法?Python CtdmoParser.set_state怎么用?Python CtdmoParser.set_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mi.dataset.parser.ctdmo.CtdmoParser的用法示例。


在下文中一共展示了CtdmoParser.set_state方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CtdmoParserUnitTestCase

# 需要导入模块: from mi.dataset.parser.ctdmo import CtdmoParser [as 别名]
# 或者: from mi.dataset.parser.ctdmo.CtdmoParser import set_state [as 别名]

#.........这里部分代码省略.........
        self.stream_handle = open(os.path.join(RESOURCE_PATH,
					       'node59p1_shorter.dat'))
        self.parser = CtdmoParser(self.config, new_state, self.stream_handle,
                                  self.state_callback, self.pub_callback) # last one is the link to the data source
        result = self.parser.get_records(1)
	self.stream_handle.close()
        self.assert_result(result, [[5354, 5544, 12, 1, 1]],
			   [[0, 12], [336, 394], [467, 2010], [5354, 6000]],
			   self.timestamp2, self.particle_d)

    def test_in_process_start(self):
	"""
	test starting a parser with a state in the middle of processing
	"""
        new_state = {StateKey.IN_PROCESS_DATA:[[5354, 5544, 12, 1, 1]],
	    StateKey.UNPROCESSED_DATA:[[0, 12], [336, 394], [467, 2010], [5354, 7160]],
	    StateKey.TIMESTAMP:self.timestamp2}
        self.stream_handle = open(os.path.join(RESOURCE_PATH,
					       'node59p1_shorter.dat'))
        self.parser = CtdmoParser(self.config, new_state, self.stream_handle,
                                  self.state_callback, self.pub_callback) # last one is the link to the data source
        result = self.parser.get_records(1)
        self.assert_result(result, [[5354, 5544, 12, 2, 1]],
			   [[0, 12], [336, 394], [467, 2010], [5354, 7160]],
			   self.timestamp2, self.particle_e)
	
	result = self.parser.get_records(11)
	self.assertEqual(result[-1], self.particle_p)
	self.assert_state([[6970, 7160, 12, 1, 1]],
			[[0, 12], [336, 394], [467, 2010], [5544, 7160]],
			   self.timestamp3)
	self.assertEqual(self.publish_callback_value[-1], self.particle_p)

    def test_set_state(self):
	"""
	test changing the state after initializing
	"""
	self.state = {StateKey.UNPROCESSED_DATA:[[0, 500]], StateKey.IN_PROCESS_DATA:[],
	    StateKey.TIMESTAMP:0.0}
        new_state = {StateKey.UNPROCESSED_DATA:[[0, 12], [336, 394], [467, 2010], [5354, 6000]],
	    StateKey.IN_PROCESS_DATA:[],
	    StateKey.TIMESTAMP:self.timestamp1}

        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) # last one is the link to the data source
	# there should only be 3 records, make sure we stop there
        result = self.parser.get_records(3)
	result = self.parser.get_records(1)
	self.assertEqual(result, [])

        self.parser.set_state(new_state)
        result = self.parser.get_records(1)
	self.stream_handle.close()
        self.assert_result(result, [[5354, 5544, 12, 1, 1]],
			   [[0, 12], [336, 394], [467, 2010], [5354, 6000]],
			   self.timestamp2, self.particle_d)

    def test_update(self):
	"""
	Test a file which has had a section of data replaced by 0s, as if a block of data has not been received yet,
	then using the returned state make a new parser with the test data that has the 0s filled in
	"""
	self.state = {StateKey.UNPROCESSED_DATA:[[0, 7160]],
	    StateKey.IN_PROCESS_DATA:[], StateKey.TIMESTAMP:0.0}
开发者ID:gxtchen,项目名称:marine-integrations,代码行数:70,代码来源:test_ctdmo.py

示例2: CtdmoParserUnitTestCase

# 需要导入模块: from mi.dataset.parser.ctdmo import CtdmoParser [as 别名]
# 或者: from mi.dataset.parser.ctdmo.CtdmoParser import set_state [as 别名]

#.........这里部分代码省略.........
        new_state = {StateKey.IN_PROCESS_DATA:[],
	    StateKey.UNPROCESSED_DATA:[[0, 12], [336, 394], [467, 2010], [5544, 7500]],
	    StateKey.TIMESTAMP:self.timestamp1}
        self.stream_handle = open(os.path.join(RESOURCE_PATH,
					       'node59p1_shorter.dat'))
        self.parser = CtdmoParser(self.config, new_state, self.stream_handle,
                                  self.state_callback, self.pub_callback) # last one is the link to the data source
        result = self.parser.get_records(1)
	self.stream_handle.close()
        self.assert_result(result, [],
			   [[0, 12], [336, 394], [467, 2010], [5544, 6970], [7160, 7500]],
			   self.timestamp3, self.particle_c)

    def test_in_process_start(self):
	"""
	test starting a parser with a state in the middle of processing
	"""
        new_state = {StateKey.IN_PROCESS_DATA:[[6970,7160,1,0,1], [7547,7737,1,0,1]],
	    StateKey.UNPROCESSED_DATA:[[0, 12], [336, 394], [467, 2010], [5544, 8000]],
	    StateKey.TIMESTAMP:self.timestamp2}
        self.stream_handle = open(os.path.join(RESOURCE_PATH,
					       'node59p1_shorter.dat'))
        self.parser = CtdmoParser(self.config, new_state, self.stream_handle,
                                  self.state_callback, self.pub_callback) # last one is the link to the data source

	result = self.parser.get_records(2)
	self.assertEqual(result[0], self.particle_c)
	self.assertEqual(result[-1], self.particle_d)
	self.assert_state([],
			[[0, 12], [336, 394], [467, 2010], [5544, 6970], [7160, 7547],[7737, 8000]],
			   self.timestamp4)
	self.assertEqual(self.publish_callback_value[-1], self.particle_d)

    def test_set_state(self):
	"""
	test changing the state after initializing
	"""
	self.state = {StateKey.UNPROCESSED_DATA:[[0, 500]], StateKey.IN_PROCESS_DATA:[],
	    StateKey.TIMESTAMP:0.0}
        new_state = {StateKey.UNPROCESSED_DATA:[[0, 12], [336, 394], [467, 2010], [5544, 7500]],
	    StateKey.IN_PROCESS_DATA:[],
	    StateKey.TIMESTAMP:self.timestamp1}

        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) # last one is the link to the data source
	# there should only be 1 records, make sure we stop there
        result = self.parser.get_records(1)
	self.assertEqual(result[0], self.particle_a)
	result = self.parser.get_records(1)
	self.assertEqual(result, [])

        self.parser.set_state(new_state)
        result = self.parser.get_records(1)
	self.stream_handle.close()
        self.assert_result(result, [],
			   [[0, 12], [336, 394], [467, 2010], [5544, 6970], [7160, 7500]],
			   self.timestamp3, self.particle_c)

    def test_update(self):
	"""
	Test a file which has had a section of data replaced by 0s, as if a block of data has not been received yet,
	then using the returned state make a new parser with the test data that has the 0s filled in
	"""
	self.state = {StateKey.UNPROCESSED_DATA:[[0, 8000]],
开发者ID:cwingard,项目名称:marine-integrations,代码行数:70,代码来源:test_ctdmo.py

示例3: CtdmoParserUnitTestCase

# 需要导入模块: from mi.dataset.parser.ctdmo import CtdmoParser [as 别名]
# 或者: from mi.dataset.parser.ctdmo.CtdmoParser import set_state [as 别名]

#.........这里部分代码省略.........
    @unittest.skip("Skip for now")
    def test_in_process_start(self):
        """
	test starting a parser with a state in the middle of processing
	"""
        new_state = {
            StateKey.IN_PROCESS_DATA: [[1470, 1661, 12, 1], [2295, 2485, 12, 0]],
            StateKey.UNPROCESSED_DATA: [[0, 50], [374, 432], [1197, 2485]],
            StateKey.TIMESTAMP: self.timestamp1,
        }
        self.stream_handle = StringIO(CtdmoParserUnitTestCase.TEST_DATA)
        self.parser = CtdmoParser(
            self.config, new_state, self.stream_handle, self.state_callback, self.pub_callback
        )  # last one is the link to the data source
        result = self.parser.get_records(1)

        # note about timestamp3: this is because when in process state is filled in,
        # only enough data is processed to return the requested number of samples
        # since only 1 is requested, it only reads [1470-1661], which has timestamp3
        self.assert_result(
            result,
            [[1470, 1661, 12, 2], [2295, 2485, 12, 0]],
            [[0, 50], [374, 432], [1197, 2485]],
            self.timestamp3,
            self.particle_zz,
        )

        result = self.parser.get_records(11)
        self.assertEqual(result[-1], self.particle_aa)
        self.assert_state([[2295, 2485, 12, 1]], [[0, 50], [374, 432], [1197, 1470], [1661, 2485]], self.timestamp4)
        self.assertEqual(self.publish_callback_value[-1], self.particle_aa)

    @unittest.skip("Skip for now")
    def test_set_state(self):
        """
	test changing the state after initializing
	"""
        self.state = {StateKey.UNPROCESSED_DATA: [[0, 1197]], StateKey.IN_PROCESS_DATA: [], StateKey.TIMESTAMP: 0.0}
        new_state = {
            StateKey.UNPROCESSED_DATA: [[0, 50], [374, 432], [1197, 2485]],
            StateKey.IN_PROCESS_DATA: [],
            StateKey.TIMESTAMP: self.timestamp2,
        }

        self.stream_handle = StringIO(CtdmoParserUnitTestCase.TEST_DATA)
        self.parser = CtdmoParser(
            self.config, self.state, self.stream_handle, self.state_callback, self.pub_callback
        )  # last one is the link to the data source
        # there should only be 16 records, make sure we stop there
        result = self.parser.get_records(16)
        result = self.parser.get_records(1)
        self.assertEqual(result, [])

        self.parser.set_state(new_state)
        result = self.parser.get_records(1)
        self.stream_handle.close()
        self.assert_result(
            result,
            [[1470, 1661, 12, 1], [2295, 2485, 12, 0]],
            [[0, 50], [374, 432], [1197, 1661], [2295, 2485]],
            self.timestamp4,
            self.particle_xx,
        )

    @unittest.skip("Skip for now")
    def test_bad_data(self):
开发者ID:sfoley,项目名称:marine-integrations,代码行数:70,代码来源:test_ctdmo.py

示例4: CtdmoParserUnitTestCase

# 需要导入模块: from mi.dataset.parser.ctdmo import CtdmoParser [as 别名]
# 或者: from mi.dataset.parser.ctdmo.CtdmoParser import set_state [as 别名]

#.........这里部分代码省略.........
        """
        new_state = {StateKey.IN_PROCESS_DATA:[],
            StateKey.UNPROCESSED_DATA:[[0, 12], [336, 394], [1429,7500]]}
        self.stream_handle = open(os.path.join(RESOURCE_PATH,
                                               'node59p1_shorter.dat'))
        self.parser = CtdmoParser(self.config, new_state, self.stream_handle, 
                                  self.state_callback, self.pub_callback, self.exception_callback) 
        result = self.parser.get_records(1)
        self.stream_handle.close()
        self.assert_result(result, [[5349,5539,1,0], [6313,6503,1,0], [6958,7148,1,0]],
                           [[0, 12], [336, 394], [5349,5539], [5924,5927], [6313,6503], [6889,7500]],
                           self.particle_c)
        self.assertEqual(self.exception_callback_value, None)

    def test_in_process_start(self):
        """
        test starting a parser with a state in the middle of processing
        """
        new_state = {StateKey.IN_PROCESS_DATA:[[5349,5539,1,0], [6313,6503,1,0], [6958,7148,1,0], [7534,7724,1,0]],
            StateKey.UNPROCESSED_DATA:[[0, 12], [336, 394], [5349,5539], [5924,5927], [6313,6503], [6889,7148], [7534,7985]]}
        self.stream_handle = open(os.path.join(RESOURCE_PATH,
                                               'node59p1_shorter.dat'))
        self.parser = CtdmoParser(self.config, new_state, self.stream_handle, 
                                  self.state_callback, self.pub_callback, self.exception_callback) 

        result = self.parser.get_records(2)
        self.assertEqual(result[0], self.particle_d)
        self.assertEqual(result[-1], self.particle_e)
        self.assert_state([[6958,7148,1,0], [7534,7724,1,0]],
                        [[0, 12], [336, 394], [5924,5927], [6889,7148], [7534,7985]])
        self.assertEqual(self.publish_callback_value[-1], self.particle_e)
        self.assertEqual(self.exception_callback_value, None)

    def test_set_state(self):
        """
        test changing the state after initializing
        """
        self.state = {StateKey.UNPROCESSED_DATA:[[0, 500]], StateKey.IN_PROCESS_DATA:[]}
        new_state = {StateKey.UNPROCESSED_DATA:[[0, 12], [336, 394], [1429,7500]],
            StateKey.IN_PROCESS_DATA:[]}

        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, self.exception_callback) 
        # there should only be 1 records, make sure we stop there
        result = self.parser.get_records(1)
        self.assertEqual(result[0], self.particle_a)
        result = self.parser.get_records(1)
        self.assertEqual(result, [])

        self.parser.set_state(new_state)
        result = self.parser.get_records(1)
        self.stream_handle.close()
        self.assert_result(result, [[5349,5539,1,0], [6313,6503,1,0], [6958,7148,1,0]],
                           [[0, 12], [336, 394], [5349,5539], [5924,5927], [6313,6503], [6889,7500]],
                           self.particle_c)
        self.assertEqual(self.exception_callback_value, None)

    def test_update(self):
        """
        Test a file which has had a section of data replaced by 0s, as if a block of data has not been received yet,
        then using the returned state make a new parser with the test data that has the 0s filled in
        """
        # this file has a block of CT data replaced by 0s
        self.stream_handle = open(os.path.join(RESOURCE_PATH,
开发者ID:StevenMyerson,项目名称:marine-integrations,代码行数:70,代码来源:test_ctdmo.py


注:本文中的mi.dataset.parser.ctdmo.CtdmoParser.set_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。