miguelmoreto / pycomtrade

pyComtrade is a python module that provides you a transparent way for reading and writing oscillographic files in Comtrade format
http://pypi.python.org/pypi/pyComtrade
GNU General Public License v3.0
31 stars 30 forks source link

WRONG READ RESULT with multiple sample rate! #18

Open SKCZHANG opened 4 years ago

SKCZHANG commented 4 years ago

Where a wrong result come to my cases while multiple sample rate applied. Here the codes can run after some debugs.

Briefly, a logical mistake results

wrong outputs under multiple sample rate. So some changes in functions below.

def dct_samples(self, data) --BEFORE

For each sample rate

        for i in range(self.cfg_data['nrates']):
                output['samp'].append(data[0])     # Sample rates
                output['endsamp'].append(data[1])  # Number of samples

--AFTER output['samp'].append(data[0]) # Sample rates output['endsamp'].append(data[1]) # Number of samples

def read_bin_digital(self) && def read_bin_analog(self) --BEFORE nS = self.cfg_data['endsamp']
--AFTER nS = sum(self.cfg_data['endsamp'])

And the core is to get the addition where "# Reading One or Multiple Sample Rates ".

def read(self, cfg_path, dat_path): ......

    # Try to open the config file
    with open(cfg_path, 'r') as cfg_file:

        ......

            # Extracting and testing arguments
            if arg in ['A', 'D']:

                ......

            # Reading One or Multiple Sample Rates 
            elif arg in ['samples']:

                # Number of Sample Rates
                nsamrate = self.cfg_data['nrates']

                # Reading each sample rate
                for i in range(nsamrate):
                    # Read line
                    line = cfg_file.readline()
                    if line.rstrip() == '':
                        break

                    # Process line
                    out_dct = self.proc_line(line, arg)
                    if i in range(1):
                        self.cfg_data.update(out_dct)

                    else:
                        for k in list(out_dct.keys()):
                            self.cfg_data[k].append(out_dct[k][0])

            else:

                ......

    ......
miguelmoreto commented 4 years ago

Hello @SKCZHANG thanks for pointing out this issue. I think that I've never tested this situation. Is it possible for you to make a pull request with your code changes and also add the Comtrade record as an example? I don't have any Comtrade here with more than one sampling rate to test this. Best regards, Miguel