def getNameMMSI(logfile,outfile): for line in logfile: fields = line.split(',')[:6] if '1'!=fields[2]: # Must be the start of a sequence continue if len(fields[5])<39: continue bv = binary.ais6tobitvec(fields[5][:39]) # Hacked for speed mmsi = ais_msg_5.decodeUserID(bv) name = aisstring.unpad(ais_msg_5.decodename(bv)) outfile.write(str(mmsi)+' '+str(name)+'\n')
for line in msgsByShip[mmsi]: fields = line.split(",") if fields[5] == lastMsg: continue # if lastMsgDict!=None: lastMsg = fields[5] r = m5.decode(binary.ais6tobitvec(fields[5])) timestamp = fields[-1] col = 0 # MMSI and IMO numbers are too much for excel, so make them strings ws_report.write(ws_report_row, col, str(mmsi)) col += 1 ws_report.write(ws_report_row, col, str(r["IMOnumber"])) col += 1 ws_report.write(ws_report_row, col, aisstring.unpad(r["callsign"])) col += 1 ws_report.write(ws_report_row, col, aisstring.unpad(r["name"])) col += 1 ws_report.write(ws_report_row, col, r["shipandcargo"]) col += 1 ws_report.write(ws_report_row, col, r["dimA"]) col += 1 ws_report.write(ws_report_row, col, r["dimB"]) col += 1 ws_report.write(ws_report_row, col, r["dimC"]) col += 1 ws_report.write(ws_report_row, col, r["dimD"]) col += 1 ws_report.write(ws_report_row, col, r["ETAminute"]) col += 1
# lastMsgDict=None print 'mmsi',mmsi,' count=',len(msgsByShip[mmsi]) for line in msgsByShip[mmsi]: fields=line.split(',') if fields[5] == lastMsg: continue # if lastMsgDict!=None: lastMsg=fields[5] r = m5.decode(binary.ais6tobitvec(fields[5])) timestamp = fields[-1] col=0 # MMSI and IMO numbers are too much for excel, so make them strings ws_report.write(ws_report_row,col,str(mmsi)); col += 1 ws_report.write(ws_report_row,col,str(r['IMOnumber'])); col += 1 ws_report.write(ws_report_row,col,aisstring.unpad(r['callsign'])); col += 1 ws_report.write(ws_report_row,col,aisstring.unpad(r['name'])); col += 1 ws_report.write(ws_report_row,col,r['shipandcargo']); col += 1 ws_report.write(ws_report_row,col,r['dimA']); col += 1 ws_report.write(ws_report_row,col,r['dimB']); col += 1 ws_report.write(ws_report_row,col,r['dimC']); col += 1 ws_report.write(ws_report_row,col,r['dimD']); col += 1 ws_report.write(ws_report_row,col,r['ETAminute']); col += 1 ws_report.write(ws_report_row,col,r['ETAhour']); col += 1 ws_report.write(ws_report_row,col,float(r['draught'])); col += 1 ws_report.write(ws_report_row,col,aisstring.unpad(r['destination'])); col += 1 ws_report.write(ws_report_row,col,timestamp); col += 1 # FIX: keep track of the last time reported and add that as a column along with number of the same messages. ws_report_row += 1