pycomtrade icon indicating copy to clipboard operation
pycomtrade copied to clipboard

WRONG READ RESULT with multiple sample rate!

Open SKCZHANG opened this issue 5 years ago • 1 comments

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:

                ......

    ......

SKCZHANG avatar Jun 04 '20 09:06 SKCZHANG

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

miguelmoreto avatar Jun 04 '20 18:06 miguelmoreto