Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rwykey = name[8:10]
if not name[10].isidigit():
rwykey = rwykey+name[10]
# also if it is only RW
else:
rwykey = name[7:9]
if not name[9].isidigit():
rwykey = rwykey+name[9]
wphdg = bs.navdb.rwythresholds[name[:4]][rwykey][2]
# keep constant runway heading
stack.stack("HDG " + str(bs.traf.id[self.iac]) + " " + str(wphdg))
# start decelerating
stack.stack("DELAY " + "10 " + "SPD " + str(bs.traf.id[self.iac]) + " " + "10")
# delete aircraft
stack.stack("DELAY " + "42 " + "DEL " + str(bs.traf.id[self.iac]))
return self.wplat[self.iactwp],self.wplon[self.iactwp], \
self.wpalt[self.iactwp],self.wpspd[self.iactwp], \
self.wpxtoalt[self.iactwp],self.wptoalt[self.iactwp], \
self.wpxtorta[self.iactwp], self.wptorta[self.iactwp], \
lnavon,self.wpflyby[self.iactwp], nextqdr
lnavon = self.iactwp +1 < self.nwp
if lnavon:
self.iactwp += 1
nextqdr = self.getnextqdr()
def update(self):
# First time: IC window in pygame version
if self.firstx:
stack.stack("IC")
self.firstx = False
# Get events
for event in pg.event.get():
if event.type==pg.QUIT:
bs.sim.stop()
elif event.type==pg.KEYDOWN:
# Alphanumeric key
if event.key>31 and event.key<127:
bs.scr.editwin.insert(str(event.str).upper())
elif event.key==13: # ENTER
cmdline = bs.scr.editwin.getline()
bs.scr.editwin.enter()
% (self.year, self.month, self.day, self.hour)
# first clear exisiting wind field
stack.stack('DEL wind')
# add new wind field
data = self.extract_wind(grb, self.lat0, self.lon0, self.lat1, self.lon1)
df = pd.DataFrame(data.T, columns=['lat','lon','alt','vx','vy'])
df['dir'] = np.degrees(np.arctan2(df.vx, df.vy))
df['spd'] = np.sqrt(df.vx**2 + df.vy**2)
for (lat, lon), d in df.groupby(['lat', 'lon']):
cmd = "WIND %d,%d," % (lat, lon)
for idx, r in d.iterrows():
cmd += "%d,%d,%d," % (r.alt, r.dir, r.spd)
stack.stack(cmd)
return True, "Wind field update in area [%d, %d], [%d, %d]. " \
% (self.lat0, self.lat1, self.lon0, self.lon1) \
+ "time: %04d-%02d-%02d %02d:00" \
% (self.year, self.month, self.day, self.hour)
def remove_outdated_ac(self):
"""House keeping, remove old entries (offline > 100s)"""
for addr, ac in list(self.acpool.items()):
if 'ts' in ac:
# threshold, remove ac after 90 seconds of no-seen
if (int(time.time()) - ac['ts']) > 100:
del self.acpool[addr]
# remove from sim traffic
if 'callsign' in ac:
stack.stack('DEL %s' % ac['callsign'])
return
def setspd(self,cmdargs):
if len(cmdargs)==1:
spd = txt2spd(cmdargs[0])
self.startspdmin = spd
self.startapdmax = spd
elif len(cmdargs)>1:
spd0,spd1 = txt2spd(cmdargs[0]),txt2spd(cmdargs[1])
self.startspdmin = min(spd0,spd1)
self.startspdmax = max(spd0,spd1)
else:
stack.stack("ECHO "+self.name+" SPD "+str(self.startaltmin)+" "+str(self.startaltmax))
#stack.stack(acid + " ADDWPT ",wplat," ",wplon)
#stack.stack(acid+"LNAV ON")
if idest>=0:
if self.dest[idest][:4] != "SEGM":
stack.stack(acid + " DEST " + self.dest[idest])
else:
stack.stack(acid + " DEST " + str(self.destlat[idest])
+ " " + str(self.destlon[idest]))
if self.name[:4] != "SEGM":
stack.stack(acid + " ORIG " + self.name)
else:
stack.stack(acid + " ORIG " + str(self.lat) + " " + str(self.lon))
stack.stack(acid + " SPD 250")
stack.stack(acid + " ALT FL100")
stack.stack(acid + " HDG " + str(self.rwyhdg[i]))
stack.stack(acid+" LNAV OFF")
# Not runway, then define instantly at position with random heading or in case of segment inward heading
if gennow:
if not self.incircle:
lat,lon = kwikpos(ctrlat,ctrlon,self.segdir,radius)
hdg = self.segdir-180
elif self.type=="seg":
lat,lon,brg = getseg(self.name)
hdg = (brg+180)%360
elif self.type=="rwy":
lat,lon = self.lat,self.lon
hdg = self.hdg # Runway heading
else:
def toggle(self, flag=None):
if flag:
self.connected = True
stack.stack('OP')
return True, 'Connecting to OpenSky'
else:
self.connected = False
return True, 'Stopping the requests'
for event in pg.event.get():
if event.type==pg.QUIT:
sim.stop()
elif event.type==pg.KEYDOWN:
# Alphanumeric key
if event.key>31 and event.key<127:
scr.editwin.insert(str(event.unicode).upper())
elif event.key==13: # ENTER
cmdline = scr.editwin.getline()
scr.editwin.enter()
if len(cmdline)>0:
self.lastcmd = cmdline
stack.stack(cmdline)
elif event.key==8: # BACKSPACE
scr.editwin.backspace()
elif event.key==27: # ESCAPE
sim.stop()
elif event.key ==pg.K_F3: # F3: Insert last command
scr.editwin.insert(self.lastcmd.strip().upper()+" ")
# Display keys
elif event.key == 269: # Num lock minus
stack.stack("ZOOM OUT")
elif event.key == 270: # Num lock pluus
stack.stack("ZOOM IN")