def TimeFrame(self, TargetDatetime): Return = [] TargetSecond = Time.DatetimeToUnixTime(TargetDatetime) for Waypoint in self.Waypoints: # makes sure that none of the waypoints are too close # converts the timestamp to a PST timestamp PSTSecond = Waypoint["Timestamp"] - (7 * 3600) if TargetSecond - PSTSecond <= 3600 and TargetSecond - PSTSecond >= 0: Return.append(Waypoint) return Return # no longer call self.GroupWaypoints()
def __Parse(self, BaseFilepath, Files): WindObjects = [] for DataFile in Files: # read all lines into an array Lines = [] with open(os.path.join(BaseFilepath, DataFile), 'r') as WindspeedFile: Lines = WindspeedFile.readlines() # different modes for the state machine Mode = "meta" Index = 0 FlightObject = {} for i in range(0, len(Lines)): Line = Lines[i].replace("\n", "") # always add 1 to the index Index += 1 # changes in the state machine occur here if "CPYXXXX" in Line: Mode = "meta" Index = 0 FlightObject = {} if Mode == "meta" and "- " in Line: Mode = "specs" Index = 0 if Mode == "specs" and Index == 1: Mode = "wind" Index = 0 if Line == "": Mode = "wait" Index = 0 # change different variables based on the state if Mode == "meta" and Index == 3: LineArray = Line.split(" ") FlightObject["Aircraft"] = LineArray[2] FlightObject["FlightNumber"] = LineArray[1][2:].replace( "/AN", "") if Mode == "specs": if "WT" in Line: FlightObject["Day"] = int(Line[9:11]) FlightObject["Hour"] = int(Line[11:13]) elif "FE" in Line: DateString = Line.split("FE")[1] FlightObject["Day"] = int(DateString[0:2]) FlightObject["Hour"] = int(DateString[5:7]) else: Mode = "wait" # set the mode to "wait" so that nothing happens until the next clump of data if Mode == "wind": FormattedLine = Line.replace("/", "") LettersInLine = re.search('[a-zA-Z]', FormattedLine) # set all of the vars to none HHMMSS, Latitude, Longitude, Altitude, StaticAirTemperature, WindDirection, WindSpeedKnots, Rolf, DataSource = [ None for i in range(0, 9) ] if len(FormattedLine) == 33: HHMMSS = FormattedLine[0:6] Latitude = FormattedLine[7:9] + "." + FormattedLine[ 9:11] # make the longitude negative here because we are removing the W Longitude = "-" + FormattedLine[ 12:15] + "." + FormattedLine[15:17] Altitude = FormattedLine[17:22] StaticAirTemperature = FormattedLine[ 22:25] + "." + FormattedLine[25] WindDirection = FormattedLine[26:29] WindSpeedKnots = FormattedLine[29:32] Rolf = FormattedLine[32] DataSource = "boeing" elif len(FormattedLine) == 38 and LettersInLine == None: HHMMSS = FormattedLine[0:6] Latitude = FormattedLine[6:9] + "." + FormattedLine[ 9:13] Longitude = FormattedLine[13:17] + "." + FormattedLine[ 17:21] Altitude = FormattedLine[21:27] StaticAirTemperature = FormattedLine[ 27:30] + "." + FormattedLine[30] WindDirection = FormattedLine[31:34] WindSpeedKnots = FormattedLine[34:37] Rolf = FormattedLine[37] DataSource = "airbus" else: pass #print "didn't know what to do with this line: " + FormattedLine if HHMMSS != None: # do time conversions Days = FlightObject["Day"] Hours = HHMMSS[0:2] Minutes = HHMMSS[2:4] Seconds = HHMMSS[4:6] DateTimeString = str( Days ) + "/04/16 " + Hours + ":" + Minutes + ":" + Seconds date_object = datetime.strptime( DateTimeString, '%d/%m/%y %H:%M:%S') try: WindObjects.append({ "AircraftId": FlightObject["Aircraft"], "Raw": Line, "Timestamp": float(str( Time.DatetimeToUnixTime(date_object))), "FlightNumber": FlightObject["FlightNumber"], "Position": [float(Latitude), float(Longitude)], "Altitude": int(Altitude), "Temperature": float(StaticAirTemperature), "WindDirection": int(WindDirection), "WindSpeed": int(WindSpeedKnots) }) except Exception, e: print e pass