iicsys/pypmu

Timestamp issues

RadevicI opened this issue · 1 comments

Hi to all,

In order to test the performance of the algorithm running in my PMU prototype, I decided to use your pyPMU model to enable connection between the sensor and local PDC in the lab. In case when the reporting rate is set to be 50 frames/s, the data are being sent each 20 ms (50 Hz systems). Therefore, fraction of second is getting the values equal to 0, 20000, 40000, .... 900000,...0 etc. It has been noticed that each time when timestamp of 0 fraction of second is sent, PDC received the frasec of the system time (time.time()) instead of 0.

The problem is solved by modifying the frame.py in def set_time:

Instead of:

    t = time()  # Get current timestamp

   if soc:
         self.set_soc(soc)
    else:
        self.set_soc(int(t))  # Get current timestamp##

    if frasec:
        if isinstance(frasec, collections.Sequence):
            self.set_frasec(*frasec)
        else:
            self.set_frasec(frasec)  # Just set fraction of second and use default values for other arguments.
    else:
         Calculate fraction of second (after decimal point) using only first 7 digits to avoid
         overflow (24 bit number).
        self.set_frasec(int((((repr((t % 1))).split("."))[1])[0:6]))

This code is written:

    if soc :
        self.set_soc(soc)
        if isinstance(frasec, collections.Sequence):
                self.set_frasec(*frasec)
        else:
                self.set_frasec(frasec)
    else:
        t = time()  # Get current timestamp
        self.set_soc(int(t))  # Get current timestamp
        self.set_frasec(int((((repr((t % 1))).split("."))[1])[0:6]))

BR,

Isidora

Hello @RadevicI,

Thanks for reporting this issue.

The thing is that if frasec: resolves as False if frasec is zero.

We will fix this issue by checking if frasec is not None: (and if soc is not None:).
Methods set_soc() and set_frasec() will validate values.

So it will look like this:

        t = time()  # Get current timestamp

        if soc is not None:
            self.set_soc(soc)
        else:
            self.set_soc(int(t))  # Get current timestamp

        if frasec is not None:
            if isinstance(frasec, collections.Sequence):
                self.set_frasec(*frasec)
            else:
                self.set_frasec(frasec)  # Just set fraction of second and use default values for other arguments.
        else:
            # Calculate fraction of second (after decimal point) using only first 7 digits to avoid
            # overflow (24 bit number).
            self.set_frasec(int((((repr((t % 1))).split("."))[1])[0:6]))