def file_data(self, device_file): print("Device file:" + device_file) device_id = device_file.split("_")[1].split(".")[0] prev_packet_num, packet_num, SFum = -1, -1, 0 packet_list = [] cur_packet = Packet() SFcolum = True with open(device_file) as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for line in csv_reader: if not line[17] in (None, ""): try: SFum += float(line[17]) + 3 except: continue if SFum == 0: SFcolum = False print("SFcoulm exist: " + str(SFcolum)) with open(device_file) as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for indx, row in enumerate(csv_reader): if row[19] in (None, "") or indx == 0: continue packet_num = int(row[19]) # Check if new packet if packet_num != prev_packet_num: prev_packet = cur_packet prev_packet_num = packet_num #if packet is complete, append to list if prev_packet.is_packet_complete(SFcolum) == True: print("Packet Complete") packet_list.append(prev_packet) cur_packet = Packet() cur_packet.number = packet_num try: if not (row[3] in (None, "")): cur_packet.battery_voltage = (float(row[3])) cur_packet.local_time = (float(row[0])) if not (row[7] in (None, "")): cur_packet.lte_time = (float(row[7])) if not (row[2] in (None, "")): cur_packet.ai = (float(row[2])) if not (row[8] in (None, "")): cur_packet.event_source = (float(row[8])) if not (row[17] in (None, "")): cur_packet.sf = (float(row[17])) except: print("error reading row") continue for packet in packet_list: print(packet) self.bat_volt.append(packet.battery_voltage) self.t_stmp.append(packet.local_time) self.t_stmp_day.append(packet.local_time / (3600 * 24)) self.lte_connect_time.append(packet.lte_time) self.ai.append(packet.ai) self.eventsrc.append(packet.event_source) self.sf.append(packet.sf)