예제 #1
0
	def test_basictest2(self):
		"""Similar to basictest, but creates new saveparam object before writing second value"""
		temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")
		path = os.path.join(temp_dir, "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/00001234560000000000.sz4")

		sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)
		sp.process_msg(self._msg(123456, 4))
		self._check_size(path, 4)
		self._check_file(path, "<i", (4, ))

		sp.process_msg(self._msg(123457, 4))
		self._check_size(path, 9)
		self._check_file(path, "<iBBBBB", (4, 0xf0, 0x3b, 0x9a, 0xca, 0x00))

		del sp
		sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)

		sp.process_msg(self._msg(123458, 5))
		self._check_size(path, 22)
		self._check_file(path, "<iBBBBBiBBBBBi",
					(4, 0xf0, 0x3b, 0x9a, 0xca, 0x00,
					-2**31, 0xf0, 0x3b, 0x9a, 0xca, 0x00,
					5, ))

		shutil.rmtree(temp_dir)
예제 #2
0
파일: ipk.py 프로젝트: wds315/szarp
	def __init__(self, ipk_path):
		ipk = lxml.etree.parse(ipk_path)

		self.params = [
			param.from_node(p) for p in ipk.xpath("//s:device//s:param", namespaces={'s': IPK_NAMESPACE })
		]
		self.device_params_count = len(self.params)

		self.params.extend(
			param.from_node(p) for p in ipk.xpath("//s:defined/s:param|s:drawdefinable/s:param", namespaces={'s': IPK_NAMESPACE })
		)

		param_map = {}
		for p in self.params:
			param_map[p.param_name] = p	

		for p in self.params:
			if not p.combined:
				continue

			lsw_param = param_map[p.lsw_param_name]
			msw_param = param_map[p.msw_param_name]

			p.lsw_param = lsw_param
			p.msw_param = msw_param

			lsw_param.lsw_combined_referencing_param = p
			msw_param.msw_combined_referencing_param = p
예제 #3
0
파일: ipk.py 프로젝트: Strongc/szarp
	def __init__(self, ipk_path):
		ipk = lxml.etree.parse(ipk_path)

		self.params = [
			param.from_node(p) for p in ipk.xpath("//s:device//s:param", namespaces={'s': IPK_NAMESPACE })
		]
		self.device_params_count = len(self.params)

		self.params.extend(
			param.from_node(p) for p in ipk.xpath("//s:defined/s:param|s:drawdefinable/s:param", namespaces={'s': IPK_NAMESPACE })
		)

		param_map = {}
		for p in self.params:
			param_map[p.param_name] = p	
예제 #4
0
    def test_processing_batch(self):
        temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")
        path = os.path.join(temp_dir, "A/B/float/0000123457.sz4")
        spf = saveparam.SaveParam(param.from_node(self.float_node), temp_dir)

        msgs = []
        for t, v in [(123456, spf.param.nan), (123457, 4.5),
                     (123458, spf.param.nan), (123459, spf.param.nan),
                     (123460, 5.0), (123461, 5.0)]:
            msg = paramsvalues_pb2.ParamValue()
            msg.param_no = 1
            msg.time = t
            msg.is_nan = False
            msg.double_value = v
            msgs.append(msg)

        s_time = spf.process_msg_batch(msgs)
        self.assertEqual(s_time, 123461)

        self._check_size(path, 15)
        self._check_file(path, "<fBBBBBBfB", (
            4.5,
            1,
            0x00,
            0x00,
            0xc0,
            0x7f,
            2,
            5.0,
            1,
        ))

        shutil.rmtree(temp_dir)
예제 #5
0
    def test_crosscast_types(self):
        from random import randint
        int_value = randint(1, 2000)
        float_value = randint(1, 2000) / 10.0  # prec 1
        for i, n in enumerate(self.nodes):
            p = param.from_node(n)

            self.assertEqual(p.data_type, self.types[i])
            self.assertEqual(p.value_format_string, self.formats[i])
            self.assertEqual(p.value_lenght, self.val_lens[i])
            self.assertEqual(p.time_prec, 4)
            self.assertEqual(p.written_to_base, True)
            self.assertTrue(
                p.value_from_binary(p.value_to_binary(int_value)) -
                self.val_cast[i](int_value) <= int_value * self.epsilons[i])
            self.assertTrue(
                p.value_from_binary(p.value_to_binary(float_value)) -
                self.val_cast[i](float_value) <= int_value * self.epsilons[i])

            msg = paramsvalues_pb2.ParamValue()
            msg.param_no = 100
            msg.is_nan = False
            msg.time = 123456
            setattr(msg, self.msg_attrs[i], self.values[i])

            self.assertEqual(p.value_from_msg(msg), self.values[i])
예제 #6
0
파일: ipk.py 프로젝트: xiaomailong/szarp
    def __init__(self, ipk_path):
        ipk = lxml.etree.parse(ipk_path)

        self.params = [
            param.from_node(p)
            for p in ipk.xpath("//s:device//s:param",
                               namespaces={'s': IPK_NAMESPACE})
        ]
        self.device_params_count = len(self.params)

        self.params.extend(
            param.from_node(p)
            for p in ipk.xpath("//s:defined/s:param|s:drawdefinable/s:param",
                               namespaces={'s': IPK_NAMESPACE}))

        param_map = {}
        for p in self.params:
            param_map[p.param_name] = p
예제 #7
0
	def setUp(self):
		node1 = lxml.etree.fromstring("""
      <param name="Kocioł 3:Sterownik:Aktualne wysterowanie falownika podmuchu" short_name="imp_p" draw_name="Wyst. fal. podm." unit="%" prec="1" base_ind="auto">
        <raport title="Kocioł 3" order="14"/>
        <draw title="Kocioł 3 Komora spalania" color="red" min="0" max="100" prior="85" order="1"/>
        <draw title="Kocioł 3 Praca falowników" color="red" min="0" max="100" prior="86" order="1"/>
      </param>
""")
		self.param1 = param.from_node(node1)

		node2 = lxml.etree.fromstring("""
      <param name="Kocioł 3:Sterownik:Aktualne wysterowanie falownika podmuchu" short_name="imp_p" draw_name="Wyst. fal. podm." unit="%" prec="1" base_ind="auto" time_type="nanosecond">
        <raport title="Kocioł 3" order="14"/>
        <draw title="Kocioł 3 Komora spalania" color="red" min="0" max="100" prior="85" order="1"/>
        <draw title="Kocioł 3 Praca falowników" color="red" min="0" max="100" prior="86" order="1"/>
      </param>
""")
		self.param2 = param.from_node(node2)
예제 #8
0
파일: test_param.py 프로젝트: wds315/szarp
	def test_parsing_combined(self):
		n = lxml.etree.fromstring("""
    <param xmlns="http://www.praterm.com.pl/SZARP/ipk" name="Siec:Kamstrup:przeplyw z licznika" short_name="Kp" draw_name="Przeplyw z licznika" unit="m3/h" prec="2">
      <define type="DRAWDEFINABLE" formula="(*:*:przeplyw z licznika msw) (*:*:przeplyw z licznika lsw) :"/>
      <draw title="Kamstrup cieppomierz CO" min="0" max="300" special="hoursum" order="6"/>
    </param>""")
		p = param.from_node(n)

		self.assertTrue(p.combined)
		self.assertEqual("Siec:Kamstrup:przeplyw z licznika lsw", p.lsw_param_name)
예제 #9
0
    def test_basictest2(self):
        """Similar to basictest, but creates new saveparam object before writing second value"""
        temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")
        path = os.path.join(
            temp_dir,
            "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/00001234560000000000.sz4"
        )

        sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)
        sp.process_msg(self._msg(123456, 4))
        self._check_size(path, 4)
        self._check_file(path, "<i", (4, ))

        sp.process_msg(self._msg(123457, 4))
        self._check_size(path, 9)
        self._check_file(path, "<iBBBBB", (4, 0xf0, 0x3b, 0x9a, 0xca, 0x00))

        # check if will properly fill nans
        del sp
        sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)

        sp.process_msg(self._msg(123458, 5))
        self._check_size(path, 22)
        self._check_file(path, "<iBBBBBiBBBBBi", (
            4,
            0xf0,
            0x3b,
            0x9a,
            0xca,
            0x00,
            -2**31,
            0xf0,
            0x3b,
            0x9a,
            0xca,
            0x00,
            5,
        ))

        shutil.rmtree(temp_dir)
예제 #10
0
	def test_nan_handling(self):
		temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")
		def _path(time):
			return os.path.join(temp_dir, "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/0000"+str(time)+"0000000000.sz4")
		sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)

		# check if will properly handle nan msg with nan value
		nan_v = sp.param.nan
		msg = self._msg(123456, nan_v)
		msg.is_nan = True
		sp.process_msg(msg)
		self._check_doesnt_exist(_path(123456))

		# check if will properly handle nan msg with incorrect value
		msg = self._msg(123457, 104)
		msg.is_nan = True
		sp.process_msg(msg)
		self._check_doesnt_exist(_path(123457))

		# check if will properly handle non-nan msg with nan value
		msg = self._msg(123458, nan_v)
		sp.process_msg(msg)
		self._check_doesnt_exist(_path(123458))

		# check if will properly handle regular value after nans
		path = _path(123459)
		sp.process_msg(self._msg(123459, 4))
		self._check_size(path, 4)
		self._check_file(path, "<i", (4, ))

		# check if will properly handle regular value after nan
		msg = self._msg(123460, 0)
		msg.is_nan = True
		sp.process_msg(msg)

		self._check_size(path, 13)
		self._check_file(path, "<iBBBBBi",
					(4, 0xf0, 0x3b, 0x9a, 0xca, 0x00,
					-2**31, ))

		sp.process_msg(self._msg(123461, 8))

		self._check_size(path, 22)
		self._check_file(path, "<iBBBBBiBBBBBi",
					(4, 0xf0, 0x3b, 0x9a, 0xca, 0x00,
					-2**31, 0xf0, 0x3b, 0x9a, 0xca, 0x00,
					8, ))

		shutil.rmtree(temp_dir)
예제 #11
0
	def test_basictest3(self):
		temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")

		item_size = 4 + 5
		items_per_file = config.DATA_FILE_SIZE / item_size

		sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)
		for i in range(items_per_file + 1):
			sp.process_msg(self._msg(i, i))

		path = os.path.join(temp_dir, "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/00000000000000000000.sz4")
		self._check_size(path, items_per_file * item_size)

		path2 = os.path.join(temp_dir, "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/%010d0000000000.sz4" % (items_per_file))
		self._check_size(path2, 4)
예제 #12
0
	def test_parsing_def(self):
		p = param.from_node(self.node_def)

		self.assertEqual(p.data_type, "short")
		self.assertEqual(p.value_format_string, "<h")
		self.assertEqual(p.value_lenght, 2)
		self.assertEqual(p.time_prec, 4)
		self.assertEqual(p.written_to_base, True)
		self.assertEqual(p.value_from_binary(p.value_to_binary(10)), 10)

		msg = paramsvalues_pb2.ParamValue()
		msg.param_no = 100;
		msg.time = 123456;
		msg.int_value = 10;

		self.assertEqual(p.value_from_msg(msg), 10)
예제 #13
0
파일: test_param.py 프로젝트: Strongc/szarp
	def test_parsing_def(self):
		p = param.from_node(self.node_def)
		
		self.assertEqual(p.data_type, "short")
		self.assertEqual(p.value_format_string, "<h")
		self.assertEqual(p.value_lenght, 2)
		self.assertEqual(p.time_prec, 4)
		self.assertEqual(p.written_to_base, True)
		self.assertEqual(p.value_from_binary(p.value_to_binary(10)), 10)

		msg = paramsvalues_pb2.ParamValue()
		msg.param_no = 100;	
		msg.time = 123456;
		msg.int_value = 10;		
		
		self.assertEqual(p.value_from_msg(msg), 10)
예제 #14
0
파일: test_param.py 프로젝트: Strongc/szarp
	def test_parsing2(self):
		for i, n in enumerate(self.nodes):
			p = param.from_node(n)

			self.assertEqual(p.data_type, self.types[i])
			self.assertEqual(p.value_format_string, self.formats[i])
			self.assertEqual(p.value_lenght, self.val_lens[i])
			self.assertEqual(p.time_prec, 4)
			self.assertEqual(p.written_to_base, True)
			self.assertEqual(p.value_from_binary(p.value_to_binary(self.values[i])), self.values[i])

			msg = paramsvalues_pb2.ParamValue()
			msg.param_no = 100;
			msg.time = 123456;
			setattr(msg, self.msg_attrs[i], self.values[i])
		
			self.assertEqual(p.value_from_msg(msg), self.values[i])
예제 #15
0
	def test_parsing2(self):
		for i, n in enumerate(self.nodes):
			p = param.from_node(n)

			self.assertEqual(p.data_type, self.types[i])
			self.assertEqual(p.value_format_string, self.formats[i])
			self.assertEqual(p.value_lenght, self.val_lens[i])
			self.assertEqual(p.time_prec, 4)
			self.assertEqual(p.written_to_base, True)
			self.assertEqual(p.value_from_binary(p.value_to_binary(self.values[i])), self.values[i])

			msg = paramsvalues_pb2.ParamValue()
			msg.param_no = 100;
			msg.time = 123456;
			setattr(msg, self.msg_attrs[i], self.values[i])

			self.assertEqual(p.value_from_msg(msg), self.values[i])
예제 #16
0
	def test_processing_float_nans(self):
		temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")
		path = os.path.join(temp_dir, "A/B/float/0000123457.sz4")
		spf = saveparam.SaveParam(param.from_node(self.float_node), temp_dir)

		for t,v in [(123456, spf.param.nan), (123457, 4.5), (123458, spf.param.nan), (123459, spf.param.nan), (123460, 5.0), (123461, 5.0)]:
			msg = paramsvalues_pb2.ParamValue()
			msg.param_no = 1
			msg.time = t
			msg.is_nan = False
			msg.double_value = v
			spf.process_msg(msg)

		self._check_size(path, 15)
		self._check_file(path, "<fBBBBBBfB", (4.5, 1, 0x00, 0x00, 0xc0, 0x7f, 2, 5.0, 1))

		shutil.rmtree(temp_dir)
예제 #17
0
	def test_casting_nans(self):
		def _msg(is_nan):
			msg = paramsvalues_pb2.ParamValue()
			msg.param_no = 100;
			msg.time = 123456;
			msg.is_nan = is_nan
			return msg

		from random import randint
		for i, n in enumerate(self.nodes):
			p = param.from_node(n)
			self.assertTrue(p.isnan(p.nan))

			# nan msg w/o value
			msg = _msg(True)
			self.assertTrue(p.isnan(p.value_from_msg(msg)))

			# nan w/ value
			msg.double_value = 10.4
			msg.int_value = 104
			self.assertTrue(p.isnan(p.value_from_msg(msg)))

			# non-nan w/ value
			msg = _msg(False)
			msg.int_value = 104
			self.assertFalse(p.isnan(p.value_from_msg(msg)))

			msg = _msg(False)
			msg.double_value = 10.4
			self.assertFalse(p.isnan(p.value_from_msg(msg)))

			# non-nan w/o value (should be nan)
			msg = _msg(False)
			self.assertTrue(p.isnan(p.value_from_msg(msg)))

			# non-nan w/ nan value (should be nan)
			msg = _msg(False)
			setattr(msg, self.msg_attrs[i], p.nan)
			self.assertTrue(p.isnan(p.value_from_msg(msg)))

			msg = _msg(False)
			msg.double_value = float('nan')
			self.assertTrue(p.isnan(p.value_from_msg(msg)))
예제 #18
0
    def test_casting_nans(self):
        def _msg(is_nan):
            msg = paramsvalues_pb2.ParamValue()
            msg.param_no = 100
            msg.time = 123456
            msg.is_nan = is_nan
            return msg

        from random import randint
        for i, n in enumerate(self.nodes):
            p = param.from_node(n)
            self.assertTrue(p.isnan(p.nan))

            # nan msg w/o value
            msg = _msg(True)
            self.assertTrue(p.isnan(p.value_from_msg(msg)))

            # nan w/ value
            msg.double_value = 10.4
            msg.int_value = 104
            self.assertTrue(p.isnan(p.value_from_msg(msg)))

            # non-nan w/ value
            msg = _msg(False)
            msg.int_value = 104
            self.assertFalse(p.isnan(p.value_from_msg(msg)))

            msg = _msg(False)
            msg.double_value = 10.4
            self.assertFalse(p.isnan(p.value_from_msg(msg)))

            # non-nan w/o value (should be nan)
            msg = _msg(False)
            self.assertTrue(p.isnan(p.value_from_msg(msg)))

            # non-nan w/ nan value (should be nan)
            msg = _msg(False)
            setattr(msg, self.msg_attrs[i], p.nan)
            self.assertTrue(p.isnan(p.value_from_msg(msg)))

            msg = _msg(False)
            msg.double_value = float('nan')
            self.assertTrue(p.isnan(p.value_from_msg(msg)))
예제 #19
0
	def test_basictest(self):
		temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")
		path = os.path.join(temp_dir, "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/00001234560000000000.sz4")

		sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)
		sp.process_msg(self._msg(123456, 4))
		self._check_size(path, 4)
		self._check_file(path, "<i", (4, ))

		sp.process_msg(self._msg(123457, 4))
		self._check_size(path, 9)
		self._check_file(path, "<iBBBBB", (4, 0xf0, 0x3b, 0x9a, 0xca, 0x00))

		sp.process_msg(self._msg(123458, 5))
		self._check_size(path, 4 + 5 + 4)
		self._check_file(path, "<iBBBBBi", (4, 0xf0, 0x77, 0x35, 0x94, 0x00, 5))

		del sp

		shutil.rmtree(temp_dir)
예제 #20
0
	def test_crosscast_types(self):
		from random import randint
		int_value = randint(1, 2000)
		float_value = randint(1, 2000) / 10.0 # prec 1
		for i, n in enumerate(self.nodes):
			p = param.from_node(n)

			self.assertEqual(p.data_type, self.types[i])
			self.assertEqual(p.value_format_string, self.formats[i])
			self.assertEqual(p.value_lenght, self.val_lens[i])
			self.assertEqual(p.time_prec, 4)
			self.assertEqual(p.written_to_base, True)
			self.assertTrue(p.value_from_binary(p.value_to_binary(int_value)) - self.val_cast[i](int_value) <= int_value*self.epsilons[i])
			self.assertTrue(p.value_from_binary(p.value_to_binary(float_value)) - self.val_cast[i](float_value) <= int_value*self.epsilons[i])

			msg = paramsvalues_pb2.ParamValue()
			msg.param_no = 100;
			msg.is_nan = False;
			msg.time = 123456;
			setattr(msg, self.msg_attrs[i], self.values[i])

			self.assertEqual(p.value_from_msg(msg), self.values[i])
예제 #21
0
    def test_basictest3(self):
        temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")

        item_size = 4 + 5
        items_per_file = config.DATA_FILE_SIZE / item_size

        sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)
        for i in range(items_per_file):
            sp.process_msg(self._msg(i, i))

        path = os.path.join(
            temp_dir,
            "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/00000000000000000000.sz4"
        )
        self._check_size(path, (items_per_file - 1) * item_size)

        path2 = os.path.join(
            temp_dir,
            "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/%010d0000000000.sz4"
            % (items_per_file - 1))
        self._check_size(path2, 4)

        shutil.rmtree(temp_dir)
예제 #22
0
    def test_basictest(self):
        temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")
        path = os.path.join(
            temp_dir,
            "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/00001234560000000000.sz4"
        )

        sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)
        sp.process_msg(self._msg(123456, 4))
        self._check_size(path, 4)
        self._check_file(path, "<i", (4, ))

        sp.process_msg(self._msg(123457, 4))
        self._check_size(path, 9)
        self._check_file(path, "<iBBBBB", (4, 0xf0, 0x3b, 0x9a, 0xca, 0x00))

        sp.process_msg(self._msg(123458, 5))
        self._check_size(path, 4 + 5 + 4)
        self._check_file(path, "<iBBBBBi",
                         (4, 0xf0, 0x77, 0x35, 0x94, 0x00, 5))

        del sp

        shutil.rmtree(temp_dir)
예제 #23
0
    def test_nan_handling(self):
        temp_dir = tempfile.mkdtemp(suffix="meaner4_unit_test")

        def _path(time):
            return os.path.join(
                temp_dir,
                "Kociol_3/Sterownik/Aktualne_wysterowanie_falownika_podmuchu/0000"
                + str(time) + "0000000000.sz4")

        sp = saveparam.SaveParam(param.from_node(self.node), temp_dir)

        # check if will properly handle nan msg with nan value
        nan_v = sp.param.nan
        msg = self._msg(123456, nan_v)
        msg.is_nan = True
        sp.process_msg(msg)
        self._check_doesnt_exist(_path(123456))

        # check if will properly handle nan msg with incorrect value
        msg = self._msg(123457, 104)
        msg.is_nan = True
        sp.process_msg(msg)
        self._check_doesnt_exist(_path(123457))

        # check if will properly handle non-nan msg with nan value
        msg = self._msg(123458, nan_v)
        sp.process_msg(msg)
        self._check_doesnt_exist(_path(123458))

        # check if will properly handle regular value after nans
        path = _path(123459)
        sp.process_msg(self._msg(123459, 4))
        self._check_size(path, 4)
        self._check_file(path, "<i", (4, ))

        # check if will properly handle regular value after nan
        msg = self._msg(123460, 0)
        msg.is_nan = True
        sp.process_msg(msg)

        self._check_size(path, 13)
        self._check_file(path, "<iBBBBBi", (
            4,
            0xf0,
            0x3b,
            0x9a,
            0xca,
            0x00,
            -2**31,
        ))

        sp.process_msg(self._msg(123461, 8))

        self._check_size(path, 22)
        self._check_file(path, "<iBBBBBiBBBBBi", (
            4,
            0xf0,
            0x3b,
            0x9a,
            0xca,
            0x00,
            -2**31,
            0xf0,
            0x3b,
            0x9a,
            0xca,
            0x00,
            8,
        ))

        shutil.rmtree(temp_dir)