Skip to content

extract_series method when value for a key is not an array #4

@dpreid

Description

@dpreid

The spinner remote lab sends values batched into an array e.g. {"d":[6935.37,6935.37,6935.37,6935.37],"v":[0.00,0.00,0.00,0.00],"t":[636742613,636742618,636742623,636742628],"y":[0.00,0.00,0.00,0.00],"c":[0.00,0.00,0.00,0.00],"e":[0.00,0.00,0.00,0.00],"p_sig":0,"i_sig":0,"d_sig":0,"m":"s"}; whilst the pendulum remote lab sends messages that contain single values e.g. {"enc":356,"time":3807661886}.

The extract_series() method assumes that the value for an extracted key is a list as it iterates through that list to get the individual values. This causes an error when run with the pendulum experiment, since no iterable list is returned in the line vv = self.extract(obj, key, separator=separator)

Current method:

def extract_series(self, arr, key, separator="/"):
        values = []
        for obj in arr:
            vv = self.extract(obj, key, separator=separator)
            for v in vv:
                values.append(v)
            
        return values

Possible solution:

def extract_series(self, arr, key, separator="/"):
        values = []
        for obj in arr:
            vv = self.extract(obj, key, separator=separator)
            if(isinstance(vv, list)):
                for v in vv:
                    values.append(v)
            else:
                values.append(vv)
        return values

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions