Dec-12-2018, 09:11 AM
Hello!
I am stuck with idea of creating unique object list where I have this log:
Here I want to make unique objects list based on 3rd element in each row, That element represents id of a message. So when I read line by line first row will be first unique object in my list, and second row because it has the same ID I want to just append its first element as timestamp and its 00 00 00 05 00 00 00 00 as its value and nothing more, now the third row has ID that is not contained yet in unique object list. So it needs to be added as unique object item.
This is how my class looks like for one item:
This is my function that is iterating way too many times.
I am stuck with idea of creating unique object list where I have this log:
Quote: 0.001051 1 1 Rx d 8 00 00 00 05 00 00 00 00 Length = 242000 BitCount = 125 ID = 1
0.001301 1 1 Rx d 8 00 00 00 05 00 00 00 00 Length = 242000 BitCount = 125 ID = 1
0.001549 1 6 Rx d 8 03 00 00 00 00 00 00 00 Length = 240000 BitCount = 124 ID = 6
0.001800 1 9 Rx d 8 04 00 00 00 00 00 00 00 Length = 242000 BitCount = 125 ID = 9
0.002050 1 9 Rx d 8 04 00 00 00 00 00 00 00 Length = 242000 BitCount = 125 ID = 9
0.002300 1 9 Rx d 8 04 00 00 00 00 00 00 00 Length = 242000 BitCount = 125 ID = 9
0.002990 1 1 Rx d 8 00 00 00 05 00 00 00 00 Length = 242000 BitCount = 125 ID = 1
0.003241 1 9 Rx d 8 04 00 00 00 00 00 00 00 Length = 242000 BitCount = 125 ID = 9
0.012996 1 6 Rx d 8 03 00 00 00 00 00 00 00 Length = 240000 BitCount = 124 ID = 6
Here I want to make unique objects list based on 3rd element in each row, That element represents id of a message. So when I read line by line first row will be first unique object in my list, and second row because it has the same ID I want to just append its first element as timestamp and its 00 00 00 05 00 00 00 00 as its value and nothing more, now the third row has ID that is not contained yet in unique object list. So it needs to be added as unique object item.
This is how my class looks like for one item:
class UniqueObjectClass: def __init__(self, data_frame): self.channel = data_frame[1] self.pduName = data_frame[2] self.direction = data_frame[3] self.payloadList = list() self.timestampList = list()I have problem because I made some function that is not working at all, and cant figurre out any better approach for this.
This is my function that is iterating way too many times.
with open(ASCFilePath1) as ASCOpen: for line in ASCOpen: line = line.strip() message_split = line.split(' ') message_split = list(filter(lambda a: a != '', message_split)) #if lenght is 23 of message then fo the work if len(message_split) == DATA_FRAME_LENGTH: if len(uniqueObjectList) == 0: uniqueObject = UniqueObjectClass(message_split) uniqueObject.payloadList.append(payload_creator(message_split)) uniqueObject.timestampList.append(message_split[0]) uniqueObjectList.append(uniqueObject) elif len(uniqueObjectList) > 0: for x in uniqueObjectList: print(uniqueObjectList) print("For") pprint(vars(x)) if message_split[2] == x.pduName: print("Before append") pprint(vars(x)) x.payloadList.append(payload_creator(message_split)) x.timestampList.append(message_split[0]) pprint(message_split[0]) print("After append") pprint(vars(x)) else: uniqueObject = UniqueObjectClass(message_split) uniqueObject.payloadList.append(payload_creator(message_split)) uniqueObject.timestampList.append(message_split[0]) uniqueObjectList.append(uniqueObject) print("New object added")Than you for your help