Example #1
0
	def __init__(self, path, uri, heartbeat):
		MeanerBase.__init__(self, path)

		self.hub_uri = uri

		self.context = zmq.Context(1)
		self.socket = self.context.socket(zmq.SUB)

		self.last_heartbeat = None

		self.heartbeat_interval = heartbeat
		self.last_meaner4_heartbeat = None

		self.heartbeat_param = saveparam.SaveParam(create_hearbeat_param(), self.szbase_path)
		self.meaner4_heartbeat_param = saveparam.SaveParam(create_meaner4_heartbeat_param(), self.szbase_path)
Example #2
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)
Example #3
0
    def __init__(self, config_dir, offset, count):
        self.offset = offset
        self.count = count

        sz4_dir = os.path.join(config_dir, "sz4")
        self.szbase_dir = os.path.join(config_dir, "szbase")

        self.ipk = ipk.IPK(config_dir + "/config/params.xml")

        self.s_params = {}

        for p in self.ipk.params:
            sp = saveparam.SaveParam(p, sz4_dir, FileFactory(), False)
            self.s_params[p.param_name] = sp

        self.s_params[heartbeat_param_name] = saveparam.SaveParam(
            create_hearbeat_param(), sz4_dir, FileFactory())
Example #4
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)
Example #5
0
    def __init__(self, config_dir, szc_dir, offset, current, queue):
        self.offset = offset
        self.current = current

        self.szbase_dir = os.path.join(config_dir, "szbase")

        self.ipk = ipk.IPK(config_dir + "/config/params.xml")
        self.szc_dir = szc_dir

        self.s_params = {}

        del parampath.ParamPath.find_latest_path
        parampath.ParamPath.find_latest_path = lambda self: None

        delta_cache = {}

        def get_time_delta_cached(self, time_from, time_to):
            diff = time_to - time_from
            if diff < 0:
                raise TimeError(time_from, time_to)

            if diff in delta_cache:
                return delta_cache[diff]
            else:
                delta = timedelta.encode(diff)
                delta_cache[diff] = delta
                return delta

        del lastentry.LastEntry.get_time_delta
        lastentry.LastEntry.get_time_delta = get_time_delta_cached

        for p in self.ipk.params:
            sp = saveparam.SaveParam(p, self.szbase_dir, FileFactory(), False)
            self.s_params[p.param_name] = sp

        self.s_params[heartbeat_param_name] = saveparam.SaveParam(
            create_hearbeat_param(), self.szbase_dir, FileFactory())

        self.queue = queue
Example #6
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)
Example #7
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)
Example #8
0
    def configure(self, ipk_path):
        self.ipk = IPK(ipk_path)

        for p in self.ipk.params:
            self.save_params.append(saveparam.SaveParam(p, self.szbase_path))
Example #9
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)