當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。